Skip to content

Conversation

zou3519
Copy link
Contributor

@zou3519 zou3519 commented Sep 17, 2019

Stack from ghstack:

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

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,
Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Collaborator

@nairbv nairbv left a 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)
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
@facebook-github-bot
Copy link
Contributor

@zou3519 merged this pull request in bae7528.

@facebook-github-bot facebook-github-bot deleted the gh/zou3519/173/head branch October 28, 2019 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants