15
15
# limitations under the License.
16
16
17
17
import numbers
18
+ from operator import index
18
19
from cpython.buffer cimport PyObject_CheckBuffer
19
20
20
21
@@ -64,7 +65,7 @@ cdef bint _is_integral(object x) except *:
64
65
return False
65
66
if callable (getattr (x, " __index__" , None )):
66
67
try :
67
- x.__index__( )
68
+ index(x )
68
69
except (TypeError , ValueError ):
69
70
return False
70
71
return True
@@ -136,7 +137,7 @@ def _basic_slice_meta(ind, shape : tuple, strides : tuple, offset : int):
136
137
else :
137
138
return ((0 ,) + shape, (0 ,) + strides, offset, _no_advanced_ind, _no_advanced_pos)
138
139
elif _is_integral(ind):
139
- ind = ind.__index__( )
140
+ ind = index(ind )
140
141
new_shape = shape[1 :]
141
142
new_strides = strides[1 :]
142
143
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):
272
273
elif _is_integral(ind_i):
273
274
if array_streak:
274
275
if not isinstance (ind_i, usm_ndarray):
275
- ind_i = ind_i.__index__( )
276
+ ind_i = index(ind_i )
276
277
# integer will be converted to an array, still raise if OOB
277
278
if not (0 <= ind_i < shape[k] or - shape[k] <= ind_i < 0 ):
278
279
raise IndexError (
@@ -284,7 +285,7 @@ def _basic_slice_meta(ind, shape : tuple, strides : tuple, offset : int):
284
285
new_strides.extend(strides[k:k_new])
285
286
k = k_new
286
287
else :
287
- ind_i = ind_i.__index__( )
288
+ ind_i = index(ind_i )
288
289
if 0 <= ind_i < shape[k]:
289
290
k_new = k + 1
290
291
if not is_empty:
0 commit comments