Skip to content

Commit 4d7e890

Browse files
author
Krzysztof Parzyszek
authored
[testing] Use tuples for numpy indexing (#14476)
Some versions of numpy disallow the following: >>> import numpy as np >>> a = np.zeros(10) >>> b = [slice(None)] >>> a[b] Traceback (most recent call last): File "<stdin>", line 1, in <module> IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices When b is a tuple, it works fine: >>> a[tuple(b)] array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
1 parent 99a5734 commit 4d7e890

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

python/tvm/topi/testing/poolnd_python.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def get_slice(
7979
kernel: Tuple[int],
8080
strides: Tuple[int],
8181
dilation: Tuple[int],
82-
) -> List[slice]:
82+
) -> Tuple[slice]:
8383
"""
8484
Programmatically create a slice object of the right dimensions for pad_np.
8585
@@ -100,7 +100,7 @@ def get_slice(
100100
# Add back batch and channel dimensions
101101
slices = [slice(None), slice(None)] + slices
102102

103-
return slices
103+
return tuple(slices)
104104

105105

106106
def pad_tensor(
@@ -189,7 +189,7 @@ def poolnd_python(
189189
dilation=dilation,
190190
)
191191

192-
output_slice = [slice(None), slice(None)] + list(coordinate)
192+
output_slice = (slice(None), slice(None)) + tuple(coordinate)
193193
reduction_axis = tuple(range(2, len(np_data.shape)))
194194
if pool_type == "avg":
195195
count_non_padded = (

0 commit comments

Comments
 (0)