Skip to content

DOC: explicitly state that count_nonzero with axis=() is unspecified. #937

Open
@ev-br

Description

@ev-br

The current docs [1] only state that If a tuple of integers, the number of non-zero values must be computed over multiple axes.

[1] https://data-apis.org/array-api/draft/API_specification/generated/array_api.count_nonzero.html

While one could argue that an empty tuple is not a tuple of integers, it could still be worth it to explicitly state that the behavior with axis=() is unspecificed and thus implementation-defined.

IRL, it is implementation-defined:

In [5]: a = np.arange(3*4*5).reshape(3, 4, 5)

In [6]: np.count_nonzero(a, axis=()).shape
Out[6]: (3, 4, 5)

In [7]: torch.count_nonzero(torch.as_tensor(a), dim=())
Out[7]: tensor(59)

In fact, it'd be best to add the same phrasing to all reduction-like functions which accept tuples for axis.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions