Skip to content

Commit

Permalink
[testing] Use tuples for numpy indexing (#14476)
Browse files Browse the repository at this point in the history
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.])
  • Loading branch information
Krzysztof Parzyszek authored Apr 4, 2023
1 parent 99a5734 commit 4d7e890
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions python/tvm/topi/testing/poolnd_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_slice(
kernel: Tuple[int],
strides: Tuple[int],
dilation: Tuple[int],
) -> List[slice]:
) -> Tuple[slice]:
"""
Programmatically create a slice object of the right dimensions for pad_np.
Expand All @@ -100,7 +100,7 @@ def get_slice(
# Add back batch and channel dimensions
slices = [slice(None), slice(None)] + slices

return slices
return tuple(slices)


def pad_tensor(
Expand Down Expand Up @@ -189,7 +189,7 @@ def poolnd_python(
dilation=dilation,
)

output_slice = [slice(None), slice(None)] + list(coordinate)
output_slice = (slice(None), slice(None)) + tuple(coordinate)
reduction_axis = tuple(range(2, len(np_data.shape)))
if pool_type == "avg":
count_non_padded = (
Expand Down

0 comments on commit 4d7e890

Please sign in to comment.