Closed EricCousineau-TRI closed 2 years ago
I've tried to iron out a contract here: https://github.com/EricCousineau-TRI/repro/blob/4a5c71162bf2e3c0afc4d08c5d757aa0841000c4/python/nptyping_ish/test/typing_test.py
Dunno if it's useful here.
Interesting, you found a hidden 'feature' that I wasn't aware of.
>>> from typing import NDArray
>>> arr_generic = NDArray
>>> arr_generic
NDArray[(typing.Any, ...), typing.Any]
>>> arr_with_dims = arr_generic[(2, 2)]
>>> arr_with_dims
NDArray[(2, 2), typing.Any]
>>> arr_with_dims_and_type = arr_with_dims[int]
>>> arr_with_dims_and_type
NDArray[(2, 2), Int[32]]
And it seems you can replace the dimension as well as the type:
>>> arr_with_dims_and_type[float]
NDArray[(2, 2), Float[64]]
>>> arr_with_dims_and_type[3]
NDArray[(3,), Int[32]]
I'm not yet sure if it is useful and if it should be officially supported or removed.
Yeah... In my example, I restricted it, but I still provide access to the .unbound()
version on the instantiation, which you can then use to get back to whatever you want.
I haven't encountered any friction with it (using it for some basic behavior cloning stuff with perception, control in robotics - OpenAI Gym-ish), although I haven't been doing anything too intense with typing annotations, other than as basic metadata for dataclass
.
When looking through the
typing
setup, it seems like this is possible (on c813f6d):Dunno if that's a bug or feature?