Skip to content

Commit a02b5e5

Browse files
committed
raise for OOB indices even if they will be converted to arrays
since the index is on the host, we can raise like we normally would, which follows NumPy behavior
1 parent 17ca447 commit a02b5e5

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

dpctl/tensor/_slicing.pxi

+5
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ def _basic_slice_meta(ind, shape : tuple, strides : tuple, offset : int):
268268
elif _is_integral(ind_i):
269269
ind_i = ind_i.__index__()
270270
if array_streak:
271+
# integer will be converted to an array, still raise if OOB
272+
if not (0 <= ind_i < shape[k] or -shape[k] <= ind_i < 0):
273+
raise IndexError(
274+
("Index {0} is out of range for "
275+
"axes {1} with size {2}").format(ind_i, k, shape[k]))
271276
new_advanced_ind.append(ind_i)
272277
k_new = k + 1
273278
new_shape.extend(shape[k:k_new])

0 commit comments

Comments
 (0)