Skip to content

Commit 06acccb

Browse files
committed
MAINT: remove a dead code branch from test_nonzero
The branch is checking for x.ndim == 0, while the hypothesis decorator only generates arrays of at least ndim=1: `given(hh.arrays(dtype=hh.all_dtypes, shape=hh.shapes(min_dims=1, min_side=1)))` This is consistent with the spec: https://data-apis.org/array-api/draft/API_specification/generated/array_api.nonzero.html > x (array) – input array. **Must** have one or more dimensions. > If x is zero-dimensional, the function **must** raise an exception.
1 parent 233f140 commit 06acccb

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

array_api_tests/test_searching_functions.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,15 @@ def test_nonzero(x):
180180
for idx in sh.ndindex(x.shape):
181181
if x[idx] != 0:
182182
indices.append(idx)
183-
if x.ndim == 0:
184-
assert out_size == len(
185-
indices
186-
), f"prod(out[0].shape)={out_size}, but should be {len(indices)}"
187-
else:
188-
for i in range(out_size):
189-
idx = tuple(int(x[i]) for x in out)
190-
f_idx = f"Extrapolated index (x[{i}] for x in out)={idx}"
191-
f_element = f"x[{idx}]={x[idx]}"
192-
assert idx in indices, f"{f_idx} results in {f_element}, a zero element"
193-
assert (
194-
idx == indices[i]
195-
), f"{f_idx} is in the wrong position, should be {indices.index(idx)}"
183+
184+
for i in range(out_size):
185+
idx = tuple(int(x[i]) for x in out)
186+
f_idx = f"Extrapolated index (x[{i}] for x in out)={idx}"
187+
f_element = f"x[{idx}]={x[idx]}"
188+
assert idx in indices, f"{f_idx} results in {f_element}, a zero element"
189+
assert (
190+
idx == indices[i]
191+
), f"{f_idx} is in the wrong position, should be {indices.index(idx)}"
196192
except Exception as exc:
197193
ph.add_note(exc, repro_snippet)
198194
raise

0 commit comments

Comments
 (0)