Numba: don't materialize index broadcast - #2353
Open
ricardoV94 wants to merge 1 commit into
Open
Conversation
ricardoV94
force-pushed
the
numba_adv_index_do_not_materialize_idx_bcast
branch
from
August 14, 2026 09:07
f20e893 to
9ca5e4b
Compare
A multi-dimensional advanced group was walked as `enumerate(zip(idx0.ravel(), idx1.ravel(), ...))`. The indices reaching that loop are `np.broadcast_to` views, and `ravel` of a stride-0 view cannot alias: it materialises a contiguous copy of the full broadcast size, per index, per call. The update array paid the same cost, having to be raveled to be reshaped. Nest over the broadcast shape explicitly and read the views by index, which is a stride-0 load -- no copy and no reshape.
ricardoV94
force-pushed
the
numba_adv_index_do_not_materialize_idx_bcast
branch
from
August 14, 2026 09:32
9ca5e4b to
7f1ca91
Compare
Member
Author
|
The string codegen for AdvancedSubtensor and AdvancedIncSubtensor is pretty grotesque by now. I suggest we follow up with a rewrite ala vectorize_codegen. Unreadable strings aren't better than unreadable numba intrinsic codegen. The only advantage of this one is you can always dprint the string codegen at the end of the day I guess... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow up to #2345 that I missed
Before:
After: