Skip to content

Commit

Permalink
[Zero-Dim] temporarily revert create_scalar due to input 0D is not fu…
Browse files Browse the repository at this point in the history
…lly supported (#48058)
  • Loading branch information
zhwesky2010 committed Nov 17, 2022
1 parent ccbd03d commit 4f57da5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion python/paddle/fluid/layers/math_op_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def create_tensor(block, value, dtype, shape):
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)
Expand Down
6 changes: 5 additions & 1 deletion python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def test_dygraph_binary(self):

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()
Expand All @@ -377,15 +377,19 @@ def test_static_unary(self):
# 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()
Expand Down

0 comments on commit 4f57da5

Please sign in to comment.