From 60c9f97c5586bb9bc9acc0dd993f8c9588a91c05 Mon Sep 17 00:00:00 2001 From: liym27 <33742067+liym27@users.noreply.github.com> Date: Thu, 10 Jun 2021 13:44:40 +0800 Subject: [PATCH] Get exact value of dim in advance for slice op (#33300) --- python/paddle/fluid/tests/unittests/test_slice_op.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/python/paddle/fluid/tests/unittests/test_slice_op.py b/python/paddle/fluid/tests/unittests/test_slice_op.py index bd784b65c10..b83478a5b8b 100644 --- a/python/paddle/fluid/tests/unittests/test_slice_op.py +++ b/python/paddle/fluid/tests/unittests/test_slice_op.py @@ -22,6 +22,8 @@ import paddle.fluid as fluid import paddle.fluid.layers as layers import paddle +paddle.enable_static() + # Situation 1: starts(list, no tensor), ends(list, no tensor) # 1.1 without attr(decrease) @@ -683,6 +685,16 @@ class TestImperativeVarBaseGetItem(unittest.TestCase): self.assertRaises(Exception, test_float_in_index) +class TestInferShape(unittest.TestCase): + def test(self): + x = paddle.ones(shape=[3, 4, 5]) + x.desc.set_shape([3, -1, 5]) + self.assertEqual(x.shape, (3, -1, 5)) + + out0 = paddle.slice(x, axes=[1], starts=[0], ends=[3]) + self.assertEqual(out0.shape, (3, 3, 5)) + + @unittest.skipIf(not core.is_compiled_with_cuda(), "core is not compiled with CUDA") class TestImperativeCUDAPinnedInput(unittest.TestCase): -- GitLab