Enable full NumPy indexing compliance for jax.Ref - #5542
Open
copybara-service[bot] wants to merge 1 commit into
Open
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
Decouples `None` (`jnp.newaxis`) from the default empty index argument in reference primitives (`ref_get`, `ref_set`, `ref_swap`, `ref_addupdate`) by transitioning defaults to `()`. Delegates reference index parsing to `jax._src.numpy.indexing`, allowing references to inherit canonical ellipsis (`...`) expansion and boolean array indexing. To maintain compatibility with low-level kernel lowerings (such as Pallas and Triton), physical buffer indexers (`NDIndexer`) are decoupled from size-1 axis insertions. This is structured via a new bridge function, `get_transforms_from_indices`, which translates user indexing expressions into explicit state transformations during primitive evaluation and view construction (`ref.at[idx]`): - Routes raw indexing arguments through `numpy.indexing.NDIndexer.from_raw_indices` to inherit standard indexing validation, ellipsis expansion, and boolean array conversion. - Separates zero-consumption newaxis dimensions (`IndexType.NONE`) from physical memory buffer slicing. - Returns a structured transformation sequence consisting of a physical `NDIndexer` and an optional follow-up `ReshapeTransform` that inserts size-1 axes in accordance with NumPy integer and slice contiguity conventions. PiperOrigin-RevId: 957374261
copybara-service
Bot
force-pushed
the
test_957374261
branch
from
August 3, 2026 21:58
4b545b2 to
3b1b2c7
Compare
This branch has not been deployed
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.
Enable full NumPy indexing compliance for jax.Ref
Decouples
None(jnp.newaxis) from the default empty index argument in reference primitives (ref_get,ref_set,ref_swap,ref_addupdate) by transitioning defaults to(). Delegates reference index parsing tojax._src.numpy.indexing, allowing references to inherit canonical ellipsis (...) expansion and boolean array indexing.To maintain compatibility with low-level kernel lowerings (such as Pallas and Triton), physical buffer indexers (
NDIndexer) are decoupled from size-1 axis insertions. This is structured via a new bridge function,get_transforms_from_indices, which translates user indexing expressions into explicit state transformations during primitive evaluation and view construction (ref.at[idx]):numpy.indexing.NDIndexer.from_raw_indicesto inherit standard indexing validation, ellipsis expansion, and boolean array conversion.IndexType.NONE) from physical memory buffer slicing.NDIndexerand an optional follow-upReshapeTransformthat inserts size-1 axes in accordance with NumPy integer and slice contiguity conventions.