Change '*' to '...' and ... for named tensor API functions.#26350
Closed
zou3519 wants to merge 3 commits intogh/zou3519/173/basefrom
Closed
Change '*' to '...' and ... for named tensor API functions.#26350zou3519 wants to merge 3 commits intogh/zou3519/173/basefrom
... for named tensor API functions.#26350zou3519 wants to merge 3 commits intogh/zou3519/173/basefrom
Conversation
Python 3 lets us use `...` to perform indexing. Semantically, `...`
means "the rest of the unspecified dimensions". For example, while
indexing, one can do (for 5D `tensor`) `tensor[0, 0, ..., 0]` and
the `...` is expanded into `tensor[0, 0, :, :, 0]`.
Previously, we were using '*' to represent a similar behavior in names.
For example, `tensor.refine_names` supports things like the following:
```
x = torch.randn(2, 3, 4, 5, 6)
x_out = x.refine_names('*', 'H', 'W') # refine only the last two
dimensions
```
This PR changes it so that named tensor API functions recognize `'...'`
(in Python 2 and Python 3) and `...` (in Python 3 exclusively) instead
of `'*'`.
Test Plan:
- [namedtensor ci]
nairbv
reviewed
Sep 17, 2019
| self.assertEqual(named_tensor.renamed('*').names, named_tensor.names) | ||
| self.assertEqual(named_tensor.renamed('*', 'width').names, | ||
| self.assertEqual(named_tensor.renamed('...').names, named_tensor.names) | ||
| self.assertEqual(named_tensor.renamed('...', 'width').names, |
Collaborator
There was a problem hiding this comment.
in python3 these all work without the quotes?
Contributor
Author
There was a problem hiding this comment.
Yes! There's an explicit python-3 test for this behavior somewhere in this file
…ns."
Python 3 lets us use `...` to perform indexing. Semantically, `...`
means "the rest of the unspecified dimensions". For example, while
indexing, one can do (for 5D `tensor`) `tensor[0, 0, ..., 0]` and
the `...` is expanded into `tensor[0, 0, :, :, 0]`.
Previously, we were using '*' to represent a similar behavior in names.
For example, `tensor.refine_names` supports things like the following:
```
x = torch.randn(2, 3, 4, 5, 6)
x_out = x.refine_names('*', 'H', 'W') # refine only the last two
dimensions
```
This PR changes it so that named tensor API functions recognize `'...'`
(in Python 2 and Python 3) and `...` (in Python 3 exclusively) instead
of `'*'`.
Test Plan:
- [namedtensor ci]
Differential Revision: [D17424666](https://our.internmc.facebook.com/intern/diff/D17424666)
…ns."
Python 3 lets us use `...` to perform indexing. Semantically, `...`
means "the rest of the unspecified dimensions". For example, while
indexing, one can do (for 5D `tensor`) `tensor[0, 0, ..., 0]` and
the `...` is expanded into `tensor[0, 0, :, :, 0]`.
Previously, we were using '*' to represent a similar behavior in names.
For example, `tensor.refine_names` supports things like the following:
```
x = torch.randn(2, 3, 4, 5, 6)
x_out = x.refine_names('*', 'H', 'W') # refine only the last two
dimensions
```
This PR changes it so that named tensor API functions recognize `'...'`
(in Python 2 and Python 3) and `...` (in Python 3 exclusively) instead
of `'*'`.
Test Plan:
- [namedtensor ci]
Differential Revision: [D17424666](https://our.internmc.facebook.com/intern/diff/D17424666)
zou3519
added a commit
that referenced
this pull request
Sep 18, 2019
Python 3 lets us use `...` to perform indexing. Semantically, `...`
means "the rest of the unspecified dimensions". For example, while
indexing, one can do (for 5D `tensor`) `tensor[0, 0, ..., 0]` and
the `...` is expanded into `tensor[0, 0, :, :, 0]`.
Previously, we were using '*' to represent a similar behavior in names.
For example, `tensor.refine_names` supports things like the following:
```
x = torch.randn(2, 3, 4, 5, 6)
x_out = x.refine_names('*', 'H', 'W') # refine only the last two
dimensions
```
This PR changes it so that named tensor API functions recognize `'...'`
(in Python 2 and Python 3) and `...` (in Python 3 exclusively) instead
of `'*'`.
Test Plan:
- [namedtensor ci]
ghstack-source-id: 89819ee
Pull Request resolved: #26350
Contributor
laurentdupin
pushed a commit
to laurentdupin/pytorch
that referenced
this pull request
Apr 24, 2026
…h#26350) Summary: Pull Request resolved: pytorch#26350 Python 3 lets us use `...` to perform indexing. Semantically, `...` means "the rest of the unspecified dimensions". For example, while indexing, one can do (for 5D `tensor`) `tensor[0, 0, ..., 0]` and the `...` is expanded into `tensor[0, 0, :, :, 0]`. Previously, we were using '*' to represent a similar behavior in names. For example, `tensor.refine_names` supports things like the following: ``` x = torch.randn(2, 3, 4, 5, 6) x_out = x.refine_names('*', 'H', 'W') # refine only the last two dimensions ``` This PR changes it so that named tensor API functions recognize `'...'` (in Python 2 and Python 3) and `...` (in Python 3 exclusively) instead of `'*'`. Test Plan: - [namedtensor ci] Differential Revision: D17424666 Pulled By: zou3519 fbshipit-source-id: 003182879fd38ced3fea051217572a457cdaf7cf
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.
Stack from ghstack:
...for named tensor API functions. #26350 Change '*' to '...' and...for named tensor API functions.Python 3 lets us use
...to perform indexing. Semantically,...means "the rest of the unspecified dimensions". For example, while
indexing, one can do (for 5D
tensor)tensor[0, 0, ..., 0]andthe
...is expanded intotensor[0, 0, :, :, 0].Previously, we were using '*' to represent a similar behavior in names.
For example,
tensor.refine_namessupports things like the following:This PR changes it so that named tensor API functions recognize
'...'(in Python 2 and Python 3) and
...(in Python 3 exclusively) insteadof
'*'.Test Plan:
Differential Revision: D17424666