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 defining NDArray-like types for NumPy-ish frameworks? #30

Open
EricCousineau-TRI opened this issue Aug 10, 2020 · 7 comments
Open
Labels
feature A new feature

Comments

@EricCousineau-TRI
Copy link

I'd like to define something like Tensor for use with pytorch (relates #27).

Some random notes:

  • This would loosely enable any frameworks that offer array-like objects (e.g. torch, tensorflow, open3d (code)), generally something that offers .shape and .dtype that behave similar to NumPy's
  • Ideally, some of this work could also permit ndarray subclasses (docs), and handle the whole covariance shindig mentioned in PEP 484 (docs)
@EricCousineau-TRI
Copy link
Author

I, uh, couldn't figure out how to make PyTorch easily play well with _NDArray and all the generics, so I went ahead and wrote a poor-man's duplicate. I've hashed out a simple version of this here:
https://github.com/EricCousineau-TRI/repro/blob/4a5c71162bf2e3c0afc4d08c5d757aa0841000c4/python/nptyping_ish/test/typing_test.py

@EricCousineau-TRI
Copy link
Author

FWIW I've updated the prototype to allow working with dataclasses and as a (semi-annoying) stand-in for default_collate:
https://github.com/EricCousineau-TRI/repro/blob/7a08250e55899dd47fb77ac6524331cd24d86e59/python/nptyping_ish/typing_/test/typing_test.py#L293-L427

@ramonhagenaars ramonhagenaars added the feature A new feature label Sep 5, 2020
@ramonhagenaars
Copy link
Owner

Good idea to support similar frameworks. I was thinking of adding support for pandas, tensorflow and pytorch would be nice additions too.

The other frameworks are to become optional for nptyping, meaning that you have to explicitly specify them when installing:

pip install nptyping[pandas]
pip install nptyping[tensorflow]
...
pip install nptyping[complete]

I think I'll start designing an addition for Pandas first. Then I could use help with other frameworks (I don't know open3d for example).

@EricCousineau-TRI
Copy link
Author

Sounds great!

And yeah, for open3d, I think it'd basically be a restricted subset of NumPy functionality, so nothing fancy. (Just may have device-like semantics like PyTorch / TensorFlow, but no computation graph thingers for reverse autodiff going on.)

@zplizzi
Copy link

zplizzi commented Jun 23, 2022

Would love to see this for torch :)

@dxm447
Copy link

dxm447 commented Aug 11, 2022

Would love to see it for cupy too

@dxm447
Copy link

dxm447 commented Sep 28, 2022

cupy.typing has been available since this year, and is a like for like replacement of np.typing

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

No branches or pull requests

4 participants