Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add newaxis constant for use in array indexing #414

Merged
merged 2 commits into from
Apr 18, 2022
Merged

Add newaxis constant for use in array indexing #414

merged 2 commits into from
Apr 18, 2022

Conversation

kgryte
Copy link
Contributor

@kgryte kgryte commented Apr 7, 2022

This PR

  • adds the constant newaxis to the specification, as an alias for None. This change was discussed and supported in the March 24, 2022 consortium meeting.
  • addresses readability concerns when performing array indexing (e.g., A[:, newaxis] vs A[:, None], where the former more explicitly conveys that the selection tuple results in an array with an additional dimension).

Notes

newaxis as an alias for None enjoys broad support among array libraries. Only PyTorch and Dask lack explicit support.

  • NumPy: np.newaxis
  • PyTorch: no equivalent, but supports None
  • MXNet: mx.np.newaxis
  • TensorFlow: tf.newaxis
  • CuPy: cupy.newaxis
  • Dask: no equivalent, but supports np.newaxis (i.e., None)

@kgryte kgryte added API extension Adds new functions or objects to the API. topic: Indexing Array indexing. labels Apr 7, 2022
@asmeurer
Copy link
Member

asmeurer commented Apr 8, 2022

This looks good, and is absolutely trivial for libraries to implement. Obviously this needs to be merged alongside #408. Is the plan to defer this until after the spec release?

@kgryte
Copy link
Contributor Author

kgryte commented Apr 18, 2022

@asmeurer As discussed during meetings, we'll merge this for inclusion in the current specification version given that indexing with None is already universally supported across array libraries.

Most libraries already have a newaxis constant, except Dask and Torch. Torch still needs to add all currently specified constants. Dask has plans to add all constants (dask/dask#8931).

Accordingly, now that #408 is merged, we can merge this PR, as well, for inclusion in the current specification version.

@kgryte kgryte merged commit 77b66c1 into main Apr 18, 2022
@kgryte kgryte deleted the add-newaxis branch April 18, 2022 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API extension Adds new functions or objects to the API. topic: Indexing Array indexing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants