Skip to content

Should meshgrid return a list or a tuple of coordinate arrays? #938

Closed

Description

@ev-br

The spec stipulates that meshgrid returns a list of arrays, https://data-apis.org/array-api/draft/API_specification/generated/array_api.meshgrid.html

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.

Activity

  1. kgryte commented on May 15, 2025

    @kgryte
    Contributor
  2. ev-br commented on May 15, 2025

    @ev-br
    MemberAuthor

    So it might be worth revisiting this in the spec then.

  3. ev-br commented on Jun 23, 2025

    @ev-br
    MemberAuthor

    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.

    $ git grep -n "List\[arr" src/array_api_stubs/_draft/
    src/array_api_stubs/_draft/creation_functions.py:454:def meshgrid(*arrays: array, indexing: Literal["xy", "ij"] = "xy") -> List[array]:
    src/array_api_stubs/_draft/creation_functions.py:467:    out: List[array]
    src/array_api_stubs/_draft/manipulation_functions.py:22:def broadcast_arrays(*arrays: array) -> List[array]:
    src/array_api_stubs/_draft/manipulation_functions.py:33:    out: List[array]
    src/array_api_stubs/_draft/manipulation_functions.py:60:    arrays: Union[Tuple[array, ...], List[array]], /, *, axis: Optional[int] = 0
    src/array_api_stubs/_draft/manipulation_functions.py:67:    arrays: Union[Tuple[array, ...], List[array]]
    src/array_api_stubs/_draft/manipulation_functions.py:302:def stack(arrays: Union[Tuple[array, ...], List[array]], /, *, axis: int = 0) -> array:
    src/array_api_stubs/_draft/manipulation_functions.py:308:    arrays: Union[Tuple[array, ...], List[array]]
    
  4. ev-br commented on Sep 18, 2025

    @ev-br
    MemberAuthor

    @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)

  5. kgryte commented on Nov 13, 2025

    @kgryte
    Contributor

    Currently, in the specification, the list is as follows:

    • meshgrid
    • broadcast_arrays
    • info.devices

    In the following APIs, we return tuples:

    • unique_all
    • unique_counts
    • unique_inverse
    • nonzero
    • unstack
    • linalg.svg
    • linalg.slogdet
    • linalg.qr
    • linalg.eigh
    • array.shape
    • array.dlpack_device
  6. kgryte commented on Nov 13, 2025

    @kgryte
    Contributor

    I've opened #981.

  7. added this to the v2025 milestone on Jan 5, 2026
  8. added a commit that references this issue on Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions