Skip to content

Change '*' to '...' and ... for named tensor API functions.#26350

Closed
zou3519 wants to merge 3 commits intogh/zou3519/173/basefrom
gh/zou3519/173/head
Closed

Change '*' to '...' and ... for named tensor API functions.#26350
zou3519 wants to merge 3 commits intogh/zou3519/173/basefrom
gh/zou3519/173/head

Conversation

@zou3519
Copy link
Copy Markdown
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]
Comment thread test/test_namedtensor.py
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
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
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