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

Array vs PyTree anotation #58

Closed
gerdm opened this issue Jan 27, 2023 · 2 comments
Closed

Array vs PyTree anotation #58

gerdm opened this issue Jan 27, 2023 · 2 comments

Comments

@gerdm
Copy link

gerdm commented Jan 27, 2023

Hi!

I'm curious why the API for array annotations is Float[Array, "dims"] and not Array[float, "dims"]? The latter would make it consistent with PyTree[float].

@patrick-kidger
Copy link
Owner

So from a static type-checking point of view, we'd like both Array and Array[...] to mean jnp.ndarray.

We could accomplish the former by just setting Array = jnp.ndarray, but then the latter would break ([...] isn't valid: you can't write jnp.ndarray[...].

The fix is to do what we do here. As far as the static type checker is concerned, Float = typing.Annotated, and thus Float[Array, ...] = Array = jnp.ndarray, and things work out.

TL;DR: limitations of static type checking.

@gerdm
Copy link
Author

gerdm commented Jan 27, 2023

Thanks for the explanation @patrick-kidger! That makes sense.

@gerdm gerdm closed this as completed Jan 27, 2023
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