Skip to content

reshape, broadcast_to, and permute_dims do not accept a single integer #608

Closed

Description

@asmeurer

reshape, broadcast_to, and permute_dims (I think these are all but I could have missed one), all accept a Tuple[int, ...]. The shape parameter for reshape and broadcast_to for shape, and axis for permute_dims

Every other function that accepts this kind of parameter accepts Union[int, Tuple[int, ...]].

It was pointed out in data-apis/array-api-compat#28 that NumPy currently accepts ints for all of these (and indeed, numpy.array_api accidentally does), but PyTorch does not.

Activity

  1. kgryte commented on Mar 8, 2023

    @kgryte
    Contributor

    IIRC, the use of an integer is not the dominant use case and is more of shorthand in NumPy. In #42, we explicitly favored Torch (and somewhat TF) in restricting to a tuple for reshape.

    For permute_dims, providing an integer does not make sense as a shorthand, except for the trivial case of a 1d array.

    In general, I'd argue that a shape kwarg should be a tuple. If NumPy wants to support an integer shorthand, that's its prerogative, but I don't think this should be codified in the spec.

  2. rgommers commented on Mar 8, 2023

    @rgommers
    Member

    Every other function that accepts this kind of parameter accepts Union[int, Tuple[int, ...]].

    The only instances of shape parameters are for creation functions (ones & co) and manipulation functions (the ones you mentioned. The former accept ints, because ones(3) is a super common shorthand. The latter all require a tuple. So I'm inclined to agree with @kgryte here and say that the current state is fine, and preferred over allowing reshape(3).

  3. rgommers commented on Mar 8, 2023

    @rgommers
    Member

    Since this was reviewed in gh-42, there are good reasons for this, and data-apis/array-api-compat#28 is already closed, let's close this one too.

    Thanks @asmeurer and @kgryte

  4. added
    status: Rejected
    on Mar 8, 2023
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

    status: Rejected

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions