Skip to content

Commit 3dd533b

Browse files
committed
Disallow 0-dimensional arrays in numpy.array_api.nonzero
This is required by the standard, even though np.nonzero does not yet disallow it. Original NumPy Commit: 28a15d5c99076c88b2906e8d3e95011ab8ef1c3c
1 parent 16c4dd8 commit 3dd533b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

array_api_strict/_searching_functions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def nonzero(x: Array, /) -> Tuple[Array, ...]:
3636
3737
See its docstring for more information.
3838
"""
39+
# Note: nonzero is disallowed on 0-dimensional arrays
40+
if x.ndim == 0:
41+
raise ValueError("nonzero is not allowed on 0-dimensional arrays")
3942
return tuple(Array._new(i) for i in np.nonzero(x._array))
4043

4144

0 commit comments

Comments
 (0)