未验证 提交 620ce8b8 编写于 作者: G gouzil 提交者: GitHub

[Divide by 0 Error] add normalize check (#49977)

* [Divide by 0 Error] add normalize check

* [Divide by 0 Error] normalize check migrate to c++
上级 08e72592
......@@ -97,6 +97,18 @@ class TestNNFunctionalNormalize(unittest.TestCase):
with fluid.program_guard(fluid.Program()):
self.run_static(use_gpu=True)
def test_errors(self):
with fluid.dygraph.guard():
# The size of input in Normalize should not be 0.
def test_0_size():
array = np.array([], dtype=np.float32)
x = paddle.to_tensor(
np.reshape(array, [1, 1, 0]), dtype='float32'
)
paddle.nn.functional.normalize(x)
self.assertRaises(ValueError, test_0_size)
if __name__ == "__main__":
unittest.main()
......@@ -77,6 +77,7 @@ def normalize(x, p=2, axis=1, epsilon=1e-12, name=None):
# [[0. , 0.24253564, 0.37139067],
# [1. , 0.97014254, 0.92847669]])
"""
if in_dygraph_mode():
eps = fluid.dygraph.base.to_variable([epsilon], dtype=x.dtype)
out = _C_ops.p_norm(x, float(p), axis, epsilon, True, False)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册