提交 000a1c87 authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Brandon T. Willard

Remove use of deprecated NumPy list indexing

上级 0f4f64fe
...@@ -291,10 +291,10 @@ def _topk_py_impl(op, x, k, axis, idx_dtype): ...@@ -291,10 +291,10 @@ def _topk_py_impl(op, x, k, axis, idx_dtype):
idx[axis] = slice(-k, None) if k > 0 else slice(-k) idx[axis] = slice(-k, None) if k > 0 else slice(-k)
if not op.return_indices: if not op.return_indices:
zv = np.partition(x, -k, axis=axis)[idx] zv = np.partition(x, -k, axis=axis)[tuple(idx)]
return zv return zv
elif op.return_values: elif op.return_values:
zi = np.argpartition(x, -k, axis=axis)[idx] zi = np.argpartition(x, -k, axis=axis)[tuple(idx)]
idx2 = tuple( idx2 = tuple(
np.arange(s).reshape((s,) + (1,) * (ndim - i - 1)) if i != axis else zi np.arange(s).reshape((s,) + (1,) * (ndim - i - 1)) if i != axis else zi
for i, s in enumerate(x.shape) for i, s in enumerate(x.shape)
...@@ -302,7 +302,7 @@ def _topk_py_impl(op, x, k, axis, idx_dtype): ...@@ -302,7 +302,7 @@ def _topk_py_impl(op, x, k, axis, idx_dtype):
zv = x[idx2] zv = x[idx2]
return zv, zi.astype(idx_dtype) return zv, zi.astype(idx_dtype)
else: else:
zi = np.argpartition(x, -k, axis=axis)[idx] zi = np.argpartition(x, -k, axis=axis)[tuple(idx)]
return zi.astype(idx_dtype) return zi.astype(idx_dtype)
......
...@@ -216,7 +216,7 @@ class TestDownsampleFactorMax(utt.InferShapeTester): ...@@ -216,7 +216,7 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
r_stride = builtins.max(r_stride, pad[i]) r_stride = builtins.max(r_stride, pad[i])
r_end = builtins.min(r_end, input.shape[-nd + i] + pad[i]) r_end = builtins.min(r_end, input.shape[-nd + i] + pad[i])
region.append(slice(r_stride, r_end)) region.append(slice(r_stride, r_end))
patch = padded_input[l][region] patch = padded_input[l][tuple(region)]
output_val[l][r] = func(patch) output_val[l][r] = func(patch)
return output_val return output_val
...@@ -325,7 +325,7 @@ class TestDownsampleFactorMax(utt.InferShapeTester): ...@@ -325,7 +325,7 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
r_stride = r[i] * stride[i] r_stride = r[i] * stride[i]
r_end = builtins.min(r_stride + ws[i], input.shape[-nd + i]) r_end = builtins.min(r_stride + ws[i], input.shape[-nd + i])
region.append(slice(r_stride, r_end)) region.append(slice(r_stride, r_end))
patch = input[l][region] patch = input[l][tuple(region)]
output_val[l][r] = func(patch) output_val[l][r] = func(patch)
return output_val return output_val
......
...@@ -527,12 +527,6 @@ class TestSubtensor(utt.OptimizationTestMixin): ...@@ -527,12 +527,6 @@ class TestSubtensor(utt.OptimizationTestMixin):
with pytest.raises(Exception): with pytest.raises(Exception):
n[: (2**63)] n[: (2**63)]
def test_list_slice(self):
x = at.arange(100).reshape((5, 5, 4))
res = x[[slice(1, -1)] * x.ndim].eval()
x = np.arange(100).reshape((5, 5, 4))
np.allclose(res, x[[slice(1, -1)] * x.ndim])
def test_slice_symbol(self): def test_slice_symbol(self):
x = self.shared(np.random.random((5, 4)).astype(self.dtype)) x = self.shared(np.random.random((5, 4)).astype(self.dtype))
y = self.shared(np.random.random((1, 2, 3)).astype(self.dtype)) y = self.shared(np.random.random((1, 2, 3)).astype(self.dtype))
...@@ -623,15 +617,15 @@ class TestSubtensor(utt.OptimizationTestMixin): ...@@ -623,15 +617,15 @@ class TestSubtensor(utt.OptimizationTestMixin):
test_array_np[np.newaxis, 1:, mask], test_array[np.newaxis, 1:, mask].eval() test_array_np[np.newaxis, 1:, mask], test_array[np.newaxis, 1:, mask].eval()
) )
assert_array_equal( assert_array_equal(
numpy_inc_subtensor(test_array_np, [0, mask], 1), numpy_inc_subtensor(test_array_np, (0, mask), 1),
inc_subtensor(test_array[(0,) + mask.nonzero()], 1).eval(), inc_subtensor(test_array[(0,) + mask.nonzero()], 1).eval(),
) )
assert_array_equal( assert_array_equal(
numpy_inc_subtensor(test_array_np, [0, mask], 1), numpy_inc_subtensor(test_array_np, (0, mask), 1),
inc_subtensor(test_array[0, mask], 1).eval(), inc_subtensor(test_array[0, mask], 1).eval(),
) )
assert_array_equal( assert_array_equal(
numpy_inc_subtensor(test_array_np, [slice(None), mask], 1), numpy_inc_subtensor(test_array_np, (slice(None), mask), 1),
inc_subtensor(test_array[:, mask], 1).eval(), inc_subtensor(test_array[:, mask], 1).eval(),
) )
...@@ -657,15 +651,15 @@ class TestSubtensor(utt.OptimizationTestMixin): ...@@ -657,15 +651,15 @@ class TestSubtensor(utt.OptimizationTestMixin):
numpy_n4[test_array_np > 2, ..., 0, 1], n4[test_array > 2, ..., 0, 1].eval() numpy_n4[test_array_np > 2, ..., 0, 1], n4[test_array > 2, ..., 0, 1].eval()
) )
assert_array_equal( assert_array_equal(
numpy_inc_subtensor(numpy_n4, [test_array_np > 2, Ellipsis], 1), numpy_inc_subtensor(numpy_n4, (test_array_np > 2, Ellipsis), 1),
inc_subtensor(n4[test_array > 2, ...], 1).eval(), inc_subtensor(n4[test_array > 2, ...], 1).eval(),
) )
assert_array_equal( assert_array_equal(
numpy_inc_subtensor(numpy_n4, [test_array_np > 2, Ellipsis, 1], 1), numpy_inc_subtensor(numpy_n4, (test_array_np > 2, Ellipsis, 1), 1),
inc_subtensor(n4[test_array > 2, ..., 1], 1).eval(), inc_subtensor(n4[test_array > 2, ..., 1], 1).eval(),
) )
assert_array_equal( assert_array_equal(
numpy_inc_subtensor(numpy_n4, [test_array_np > 2, Ellipsis, 0, 1], 1), numpy_inc_subtensor(numpy_n4, (test_array_np > 2, Ellipsis, 0, 1), 1),
inc_subtensor(n4[test_array > 2, ..., 0, 1], 1).eval(), inc_subtensor(n4[test_array > 2, ..., 0, 1], 1).eval(),
) )
...@@ -730,8 +724,6 @@ class TestSubtensor(utt.OptimizationTestMixin): ...@@ -730,8 +724,6 @@ class TestSubtensor(utt.OptimizationTestMixin):
test_array.__getitem__((False,)) test_array.__getitem__((False,))
with pytest.raises(TypeError): with pytest.raises(TypeError):
test_array.__getitem__((True, False)) test_array.__getitem__((True, False))
with pytest.raises(TypeError):
test_array.__getitem__([True, False])
with pytest.raises(TypeError): with pytest.raises(TypeError):
test_array.__getitem__(([0, 1], [0, False])) test_array.__getitem__(([0, 1], [0, False]))
with pytest.raises(TypeError): with pytest.raises(TypeError):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论