Skip to content
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

Support Any for shape #5

Closed
AdilZouitine opened this issue Apr 7, 2021 · 4 comments
Closed

Support Any for shape #5

AdilZouitine opened this issue Apr 7, 2021 · 4 comments

Comments

@AdilZouitine
Copy link
Contributor

AdilZouitine commented Apr 7, 2021

Hi, I would like to thank you for this cool library.
I was desperate not to find a shape typing for pytorch and I had planned to code it myself if it didn't exist.

I think your api is great, however I find that specifying the dimension of any shape to -1 is not very intuitive (I saw that you have many other ways to declare it). One idea is to declare a dimension with any shape using typing.Any.
As the library nbtyping does :

from typing import Any
import numpy as np 
from nptyping import NDArray
NDArray[(3, 3, Any), np.float32]

In this case we have typed our array with no constraints on the last dimension.
If we apply this modification to your library:

from typing import Any
from torchtyping import TensorType
import torch

TensorType[3, 3, Any, torch.float32]
# Instead of 
TensorType[3, 3, -1, torch.float32]

What do you think of this? If you're interested I can try to make a pull request!

I thank you again for developing this wonderful library.

@patrick-kidger
Copy link
Owner

Yep, that sounds good to me. I'd be very happy to accept a PR on this.

@patrick-kidger
Copy link
Owner

patrick-kidger commented Apr 7, 2021

In passing: The syntax currently used is TensorType[3, 3, -1, torch.float32] not TensorType[(3, 3, -1), torch.float32] (taken from your example). If you particularly want the second syntax then I'd be happy to have that in as well.

The different arguments in the [] are distinguished by type rather than position. This was a deliberate choice to

  • (a) make it easy to do just TensorType[float] rather than something like TensorType[(...,), float].
  • (b) make it possible to use slice syntax like TensorType["channels": 4] to be able to put both name and size to a dimension.

@AdilZouitine
Copy link
Contributor Author

In passing: The syntax currently used is TensorType[3, 3, -1, torch.float32] not TensorType[(3, 3, -1), torch.float32] (taken from your example).

The different arguments in the [] are distinguished by type rather than position. This was a deliberate choice to

  • (a) make it easy to do just TensorType[float] rather than something like TensorType[(...,), float].
  • (b) make it possible to use slice syntax like TensorType["channels": 4] to be able to put both name and size to a dimension.

I understand your choice!
(I will therefore modify my example) 😄

@patrick-kidger
Copy link
Owner

Closed by #6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants