Skip to content

Commit 0a2ab33

Browse files
committed
Update slice bounds from data-apis/array-api#138
1 parent e607201 commit 0a2ab33

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

array_api_tests/hypothesis_helpers.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,13 @@ def integer_indices(draw, sizes):
126126
def slices(draw, sizes):
127127
size = draw(sizes)
128128
# The spec does not specify out of bounds behavior.
129-
start = draw(one_of(integers(-size, max(0, size-1)), none()))
130-
stop = draw(one_of(integers(-size, size)), none())
131129
max_step_size = draw(integers(1, max(1, size)))
132130
step = draw(one_of(integers(-max_step_size, -1), integers(1, max_step_size), none()))
131+
start = draw(one_of(integers(-size, max(0, size-1)), none()))
132+
if step is None or step > 0:
133+
stop = draw(one_of(integers(-size, size)), none())
134+
else:
135+
stop = draw(one_of(integers(-size - 1, size - 1)), none())
133136
s = slice(start, stop, step)
134137
l = list(range(size))
135138
sliced_list = l[s]

array_api_tests/test_indexing.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ def test_slicing(size, s):
3939
if s.start is not None:
4040
assert -size <= s.start <= max(0, size - 1), "Sanity check failed. This indicates a bug in the test suite"
4141
if s.stop is not None:
42-
assert -size <= s.stop <= size, "Sanity check failed. This indicates a bug in the test suite"
43-
42+
if s.step is None or s.step > 0:
43+
assert -size <= s.stop <= size, "Sanity check failed. This indicates a bug in the test suite"
44+
else:
45+
assert -size - 1 <= s.stop <= size - 1, "Sanity check failed. This indicates a bug in the test suite"
4446
a = arange(size)
4547
l = list(range(size))
4648
sliced_list = l[s]

0 commit comments

Comments
 (0)