1515# limitations under the License.
1616
1717import numbers
18+ from operator import index
1819from 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