Skip to content

Commit

Permalink
[Divide by 0 Error] add svd check (#49968)
Browse files Browse the repository at this point in the history
* [Divide by 0 Error] add svd check

* [Divide by 0 Error] svd check migrate to c++, move svd test_0_size
  • Loading branch information
gouzil authored Feb 3, 2023
1 parent 620ce8b commit f2ec69b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python/paddle/fluid/tests/unittests/test_svd_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,16 @@ def test_static(self):
)
np.testing.assert_allclose(fetches[0], gt_s, rtol=1e-05)

def test_errors(self):
with paddle.fluid.dygraph.guard():
# The size of input in svd should not be 0.
def test_0_size():
array = np.array([], dtype=np.float32)
x = paddle.to_tensor(np.reshape(array, [0, 0]), dtype='float32')
paddle.linalg.svd(x, full_matrices=False)

self.assertRaises(ValueError, test_0_size)


if __name__ == "__main__":
paddle.enable_static()
Expand Down
1 change: 1 addition & 0 deletions python/paddle/tensor/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,7 @@ def svd(x, full_matrices=False, name=None):
# U * UH == I
# V * VH == I
"""

if in_dygraph_mode():
return _C_ops.svd(x, full_matrices)
else:
Expand Down

0 comments on commit f2ec69b

Please sign in to comment.