-
Notifications
You must be signed in to change notification settings - Fork 52
Specify shape behavior #289
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
Conversation
My worry about this is that Weren't there proposals to allow shape to be an array? Wouldn't this solve the problem for libraries that already allow representing arrays as undefined objects? This would seem more type safe since you can always index into an array, even if the resulting object is some uncomputed entity. That would also seem to allow more flexibility in terms of some part of the shape being known vs. it is either all known or completely unknown, i.e., you might know I know there have been some example codes people have written using array API compliant APIs. How many of those are making use of the |
For visibility, @shoyer @agarwal-ashish @jakirkham @alextp. |
Re type safety, doesn't allowing None just mean that the type of array.shape becomes Optional[Shape] instead of just Shape? That does inform that the call site needs to check. |
TensorFlow currently alows arrays with unknown numbers of dimensions, but in my opinion the use-cases (beyond backwards compatibility) are pretty marginal. On the other hand, arrays with unknown shape are much more common (e.g., at least in TensorFlow, JAX and Dask). So I would lean towards typing I don't love the idea of allowing Instead, we could consider a separate function like |
@shoyer Agreed. We've discussed adding a I'm certainly open to modifying the current proposal to always return a tuple (i.e., disallowing supporting unknown rank). |
This sounds about right to me - strikes a good balance between the needs of libraries using delayed evaluation and usability.
|
IIRC we never really had any data on the "unknown rank" use cases. I thought our main remaining decision here was whether to represent the unknown dimension inside |
Shape guidance has now been updated to remove support for unknown ranks, in alignment with @shoyer's proposal and as discussed on today's call. |
As this has been discussed and agreed upon during consortium meetings and both here and in #97, will merge. Any further changes can be addressed in follow-up PRs. |
This PR
x.shape
to return a tuple withNone
elements to indicate that a dimension is unknown.x.shape
should return a tuple. A custom shape object is allowed so long as it behaves like a tuple.__len__
from the specification. NumPy, TF, and others return the size of the first dimension whenlen()
(which calls__len__
) is invoked on an array. In Python,__len__
should return integer>=0
. Given the above changes accommodating unknown shapes/dimensions, returning an integer cannot be guaranteed as the first dimension could be unknown and thusNone
. Accordingly, this PR elects to remove__len__
from the specification.