-
Notifications
You must be signed in to change notification settings - Fork 44
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 support for expanding dimensions using None
#408
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think adding None
makes sense. My main question is whether it's okay to combine it with other indexing semantics. E.g,:
>>> import torch
>>> t = torch.arange(5)
>>> t[None, :3, None]
tensor([[[0],
[1],
[2]]])
>>> t2 = torch.arange(6).reshape((3, 2))
>>> t2[:2, None, ...]
tensor([[[0, 1]],
[[2, 3]]])
That probably needs testing and specifying.
There shouldn't be any issues with this I would imagine. The text from the NumPy docs seems fine, although it could perhaps be more precise:
This should probably not apply to boolean indices where we should keep the "only index" rule. |
I've added an explicit note that the use of |
Re: combining with other indexing semantics. As @asmeurer mentions, this should not be an issue, given that the use of |
This looks good. Were we going to add |
As this PR has been open for 3 weeks, has received approvals here, and no objections were raised during consortium meetings, will go ahead and merge. Any changes can be addressed in follow-up pull requests. |
This PR
None
for indexing to add an axis #360 by adding support for expanding dimensions viaNone
. The functional equivalent of the proposed changes is repeated invocation ofexpand_dims
. UsingNone
in a selection tuple is more convenient when needing to insert multiple size1
dimensions.None
in selection tuples enjoys broad support across array libraries.