diff --git a/python/paddle/fluid/layers/math_op_patch.py b/python/paddle/fluid/layers/math_op_patch.py index fb3979434347f407c5bc9a2e5f0fb2e00cdd95e9..f9ba649867161754a81e0a32b97b8b73efab605a 100644 --- a/python/paddle/fluid/layers/math_op_patch.py +++ b/python/paddle/fluid/layers/math_op_patch.py @@ -99,7 +99,8 @@ def monkey_patch_variable(): return var def create_scalar(block, value, dtype): - return create_tensor(block, value, dtype, shape=[]) + # TODO(zhouwei): will change to [] which is 0-D Tensor + return create_tensor(block, value, dtype, shape=[1]) def create_tensor_with_batchsize(ref_var, value, dtype): assert isinstance(ref_var, Variable) diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index c85f5aec42e9f63e86e852f59a70a47b2bdb9f97..174172b026f21fd49cc84f9740b6ea78e3cde4d9 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -350,7 +350,7 @@ class TestBinaryAPI(unittest.TestCase): paddle.enable_static() - def test_static_unary(self): + def test_static_binary(self): paddle.enable_static() for api in binary_api_list + binary_api_list_without_grad: main_prog = fluid.Program() @@ -377,15 +377,19 @@ class TestBinaryAPI(unittest.TestCase): # Test runtime shape self.assertEqual(out_np.shape, ()) + # TODO(zhouwei): will open when create_scalar is [] # 2) x is 0D , y is scalar + ''' x = paddle.rand([]) y = 0.5 x.stop_gradient = False + print(api) if isinstance(api, dict): out = getattr(paddle.static.Variable, api['cls_method'])( x, y ) self.assertEqual(out.shape, ()) + ''' for api in binary_int_api_list_without_grad: main_prog = fluid.Program()