Skip to content

BUG: np.all does not strictly obey the array-api standard. #31990

Description

@andyfaff

Describe the issue:

According to the array-api standard for all:

out (array) – if a logical AND reduction was performed over the entire array, the returned array must be a zero-dimensional array containing the test result. Otherwise, the returned array must be a non-zero-dimensional array containing the test results. The returned array must have a data type of bool.

Thus, I expect the return from np.all to definitely be an array. This is not the case .

Reproduce the code example:

>>> import numpy as np
>>> x = np.array([1.0, 2.0])
>>> res = np.all(np.equal(x, x)) # res is np.True_ here, it should be something like np.array(True, dtype=bool)
>>> assert isinstance(res, np.ndarray)

Error message:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[197], line 4
      2 x = np.array([1.0, 2.0])
      3 res = np.all(np.equal(x, x))
----> 4 assert isinstance(res, np.ndarray)

AssertionError: 
Selection deleted

Python and NumPy Versions:

main

Runtime Environment:

No response

How does this issue affect you or how did you find it:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions