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

Use pytest's parameterize for TestSubtensor.test_ellipsis

上级 fd4c5d91
...@@ -537,10 +537,9 @@ class TestSubtensor(utt.OptimizationTestMixin): ...@@ -537,10 +537,9 @@ class TestSubtensor(utt.OptimizationTestMixin):
ret = f() ret = f()
assert ret.shape == (1, 1, 4) assert ret.shape == (1, 1, 4)
def test_ellipsis(self): @pytest.mark.parametrize(
numpy_n = np.arange(24, dtype=self.dtype).reshape((2, 3, 4)) "length, op_type_opt, slice_",
n = self.shared(numpy_n) [
test_cases = [
(0, Subtensor, np.index_exp[...]), (0, Subtensor, np.index_exp[...]),
(1, Subtensor, np.index_exp[..., 1]), (1, Subtensor, np.index_exp[..., 1]),
(1, Subtensor, np.index_exp[1, ...]), (1, Subtensor, np.index_exp[1, ...]),
...@@ -554,14 +553,16 @@ class TestSubtensor(utt.OptimizationTestMixin): ...@@ -554,14 +553,16 @@ class TestSubtensor(utt.OptimizationTestMixin):
AdvancedSubtensor, AdvancedSubtensor,
np.index_exp[..., np.newaxis, [1, 2]], np.index_exp[..., np.newaxis, [1, 2]],
), ),
] ],
)
for length, op_type_opt, slice_ in test_cases: def test_ellipsis(self, length, op_type_opt, slice_):
numpy_tval = numpy_n[slice_] numpy_n = np.arange(24, dtype=self.dtype).reshape((2, 3, 4))
t = n[slice_] n = self.shared(numpy_n)
tval = self.eval_output_and_check(t, op_type=op_type_opt, length=length) numpy_tval = numpy_n[slice_]
assert tval.shape == numpy_tval.shape t = n[slice_]
assert_array_equal(tval, numpy_tval) tval = self.eval_output_and_check(t, op_type=op_type_opt, length=length)
assert tval.shape == numpy_tval.shape
assert_array_equal(tval, numpy_tval)
def test_boolean(self): def test_boolean(self):
def numpy_inc_subtensor(x, idx, a): def numpy_inc_subtensor(x, idx, a):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论