Skip to content

Commit 87db03a

Browse files
committed
Use operator.index in _slicing.pxi
1 parent 682b598 commit 87db03a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

dpctl/tensor/_slicing.pxi

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# limitations under the License.
1616

1717
import numbers
18+
from operator import index
1819
from cpython.buffer cimport PyObject_CheckBuffer
1920

2021

@@ -64,7 +65,7 @@ cdef bint _is_integral(object x) except *:
6465
return False
6566
if callable(getattr(x, "__index__", None)):
6667
try:
67-
x.__index__()
68+
index(x)
6869
except (TypeError, ValueError):
6970
return False
7071
return True
@@ -136,7 +137,7 @@ def _basic_slice_meta(ind, shape : tuple, strides : tuple, offset : int):
136137
else:
137138
return ((0,) + shape, (0,) + strides, offset, _no_advanced_ind, _no_advanced_pos)
138139
elif _is_integral(ind):
139-
ind = ind.__index__()
140+
ind = index(ind)
140141
new_shape = shape[1:]
141142
new_strides = strides[1:]
142143
is_empty = any(sh_i == 0 for sh_i in new_shape)
@@ -272,7 +273,7 @@ def _basic_slice_meta(ind, shape : tuple, strides : tuple, offset : int):
272273
elif _is_integral(ind_i):
273274
if array_streak:
274275
if not isinstance(ind_i, usm_ndarray):
275-
ind_i = ind_i.__index__()
276+
ind_i = index(ind_i)
276277
# integer will be converted to an array, still raise if OOB
277278
if not (0 <= ind_i < shape[k] or -shape[k] <= ind_i < 0):
278279
raise IndexError(
@@ -284,7 +285,7 @@ def _basic_slice_meta(ind, shape : tuple, strides : tuple, offset : int):
284285
new_strides.extend(strides[k:k_new])
285286
k = k_new
286287
else:
287-
ind_i = ind_i.__index__()
288+
ind_i = index(ind_i)
288289
if 0 <= ind_i < shape[k]:
289290
k_new = k + 1
290291
if not is_empty:

0 commit comments

Comments
 (0)