@@ -44,6 +44,9 @@ cdef object _basic_slice_meta(object ind, tuple shape,
44
44
Raises IndexError for invalid index `ind`, and NotImplementedError
45
45
if `ind` is an array.
46
46
"""
47
+ is_integral = lambda x : (
48
+ isinstance (x, numbers.Integral) or callable (getattr (x, " __index__" , None ))
49
+ )
47
50
if ind is Ellipsis :
48
51
return (shape, strides, offset)
49
52
elif ind is None :
@@ -58,7 +61,8 @@ cdef object _basic_slice_meta(object ind, tuple shape,
58
61
new_strides,
59
62
offset + sl_start * strides[0 ]
60
63
)
61
- elif isinstance (ind, numbers.Integral):
64
+ elif is_integral(ind):
65
+ ind = ind.__index__()
62
66
if 0 <= ind < shape[0 ]:
63
67
return (shape[1 :], strides[1 :], offset + ind * strides[0 ])
64
68
elif - shape[0 ] <= ind < 0 :
@@ -82,7 +86,7 @@ cdef object _basic_slice_meta(object ind, tuple shape,
82
86
ellipses_count = ellipses_count + 1
83
87
elif isinstance (i, slice ):
84
88
axes_referenced = axes_referenced + 1
85
- elif isinstance (i, numbers.Integral ):
89
+ elif is_integral(i ):
86
90
explicit_index = explicit_index + 1
87
91
axes_referenced = axes_referenced + 1
88
92
elif isinstance (i, list ):
@@ -124,7 +128,8 @@ cdef object _basic_slice_meta(object ind, tuple shape,
124
128
new_strides.append(str_i)
125
129
new_offset = new_offset + sl_start * strides[k]
126
130
k = k_new
127
- elif isinstance (ind_i, numbers.Integral):
131
+ elif is_integral(ind_i):
132
+ ind_i = ind_i.__index__()
128
133
if 0 <= ind_i < shape[k]:
129
134
k_new = k + 1
130
135
new_offset = new_offset + ind_i * strides[k]
0 commit comments