Skip to content

Commit e607201

Browse files
committed
Fix the multiaxis_indices strategy to only generate valid indices
Previously it was not correctly corresponding indices to dimensions for indices after an ellipsis.
1 parent ed30222 commit e607201

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Diff for: array_api_tests/hypothesis_helpers.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,24 @@ def multiaxis_indices(draw, shapes):
150150
# Generate tuples no longer than the shape, with indices corresponding to
151151
# each dimension.
152152
shape = draw(shapes)
153-
guard = draw(tuples(just(object()), max_size=len(shape)))
153+
n_entries = draw(integers(0, len(shape)))
154154
# from hypothesis import note
155-
# note(f"multiaxis_indices guard: {guard}")
155+
# note(f"multiaxis_indices n_entries: {n_entries}")
156156

157-
for size, _ in zip(shape, guard):
158-
res.append(draw(one_of(
157+
k = 0
158+
for i in range(n_entries):
159+
size = shape[k]
160+
idx = draw(one_of(
159161
integer_indices(just(size)),
160162
slices(just(size)),
161-
just(...))))
163+
just(...)))
164+
if idx == ... and k >= 0:
165+
# If there is an ellipsis, index from the end of the shape
166+
k = k - n_entries
167+
k += 1
168+
res.append(idx)
162169
# Sometimes add more entries than necessary to test this.
163-
if len(guard) == len(shape) and ... not in res:
170+
if n_entries == len(shape) and ... not in res:
164171
# note("Adding extra")
165172
extra = draw(lists(one_of(integer_indices(sizes), slices(sizes)), min_size=0, max_size=3))
166173
res += extra

0 commit comments

Comments
 (0)