-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Change '*' to '...' and ...
for named tensor API functions.
#26350
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
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]
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, |
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.
in python3 these all work without the quotes?
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.
Yes! There's an explicit python-3 test for this behavior somewhere in this file
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.
Cool!
…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)
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
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_names
supports 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