Add support for expanding dimensions using None#408
Conversation
There was a problem hiding this comment.
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
Nonefor 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. UsingNonein a selection tuple is more convenient when needing to insert multiple size1dimensions.Nonein selection tuples enjoys broad support across array libraries.