未验证 提交 a48ef360 编写于 作者: 张春乔 提交者: GitHub

fix the NullPointerError of median (#50017)

上级 da11aa40
......@@ -86,6 +86,7 @@ class TestMedian(unittest.TestCase):
x = paddle.arange(12).reshape([3, 4])
self.assertRaises(ValueError, paddle.median, x, 1.0)
self.assertRaises(ValueError, paddle.median, x, 2)
self.assertRaises(ValueError, paddle.median, paddle.to_tensor([]))
if __name__ == '__main__':
......
......@@ -406,6 +406,9 @@ def median(x, axis=None, keepdim=False, name=None):
if not isinstance(x, Variable):
raise TypeError("In median, the input x should be a Tensor.")
if x.size == 0:
raise ValueError("In median, the size of input x should not be 0.")
if len(x.shape) == 0:
return x.clone()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册