You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Should meshgrid return a list or a tuple of coordinate arrays? #938
NumPy and Pytorch, however, return tuples. Jax and CuPy return lists. Makes me wonder if specifying a list is a conscious decision: I seem to recall that tuples are generally more JIT-friendly.
Assuming that List[array] is the correct annotation for functions which return lists of arrays, the only functions which return a list of arrays are meshgrid and broadcast_arrays, cf #934.
Two other instances in the search below are stack and concat which accept sequences.
The current spec requirement, List[arrays], comes from NumPy 1.x. Given that NumPy 2.x deliberately changed return type to tuple[arrays], it seems reasonable to change the spec for 2025.12, too.
Alternatively, allow a union of a list and a tuple, with a recommendation along the lines of should return a tuple but may return a list.
@jakevdp while not exactly the master list , the functions which return List[array] in the Array API spec but have been changed in NumPy 2.0 to return tuples are meshgrid and broadcast_arrays, #938 (comment)
Activity
kgryte commentedon May 15, 2025
@ev-br The spec likely reflects pre-NumPy v2.0. See https://numpy.org/doc/1.26/reference/generated/numpy.meshgrid.html and https://github.com/numpy/numpy/blob/v1.26.0/numpy/lib/function_base.py#L5163.
ev-br commentedon May 15, 2025
So it might be worth revisiting this in the spec then.
ev-br commentedon Jun 23, 2025
Assuming that
List[array]is the correct annotation for functions which return lists of arrays, the only functions which return a list of arrays aremeshgridandbroadcast_arrays, cf #934.Two other instances in the search below are
stackandconcatwhich accept sequences.The current spec requirement,
List[arrays], comes from NumPy 1.x. Given that NumPy 2.x deliberately changed return type totuple[arrays], it seems reasonable to change the spec for 2025.12, too.Alternatively, allow a union of a list and a tuple, with a recommendation along the lines of should return a tuple but may return a list.
ev-br commentedon Sep 18, 2025
@jakevdp while not exactly the master list , the functions which return
List[array]in the Array API spec but have been changed in NumPy 2.0 to return tuples aremeshgridandbroadcast_arrays, #938 (comment)kgryte commentedon Nov 13, 2025
Currently, in the specification, the list is as follows:
In the following APIs, we return tuples:
kgryte commentedon Nov 13, 2025
I've opened #981.
feat!: return tuples rather than lists