Subtensor lift: reason about advanced indices jointly when gating#2251
Open
ricardoV94 wants to merge 3 commits into
Open
Subtensor lift: reason about advanced indices jointly when gating#2251ricardoV94 wants to merge 3 commits into
ricardoV94 wants to merge 3 commits into
Conversation
30aa289 to
c27a1c3
Compare
483c1b9 to
f63da68
Compare
fe2c69f to
f7ceb7d
Compare
f7ceb7d to
fe342d6
Compare
ricardoV94
commented
Jun 27, 2026
| and idx.type.ndim > 0 | ||
| and not inp.type.broadcastable[axis] | ||
| ] | ||
| if not _indices_provably_not_larger(adv_indices, fgraph): |
Member
Author
There was a problem hiding this comment.
shouldn't this take the variable for the static shape
ricardoV94
commented
Jun 27, 2026
| continue | ||
| if not _index_provably_not_larger(idx, inp.type.shape[axis], fgraph): | ||
| return None | ||
| adv_indices = [ |
Member
Author
There was a problem hiding this comment.
this should be called adv_indices and input_static_dim
Generalize the duplicate-free reasoning used to gate the advanced-index write rewrites from a per-axis check to a joint one over the whole advanced index group, sharing the logic across subtensor.py and subtensor_lift.py. - _index_provably_unique: per-axis uniqueness, now also proving single-signed aranges and views (Reshape/DimShuffle) that preserve the value multiset. - _indices_jointly_unique: distinct joint coordinate tuples via all-axes uniqueness, a single Nonzero (e.g. tril_indices), or jointly-unique constants where no single axis is unique on its own. - _indices_provably_not_larger: bound a gather by the indexed axes' size using static shapes, per-axis bounds, or joint uniqueness.
fe342d6 to
d60021f
Compare
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.
We had heuristics that work per-axis, but we should reason about the advanced indices together since they interact. E.g., tril_indices, would fail the per-axis checks, as each index (row, col) is larger than the respective axis and contains duplicates. But jointly they index less than the full array and don't have duplicates, so we want to lift it through Elemwise and the like.
Shows up in pymc-devs/pymc#8297