Skip to content

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.

3 participants