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

Fix the div 0 error of matrix_power (#49942)

* add zero size check in matrix_power_kernel_impl.h

* add zero size check in matrix_power_kernel_impl.h

* add zero size check in unittest

* bug_fix

* bug_fix

* bug_fix

* bug_fix

* bug_fix

* bug fix

* bug_fix

* bug_fix

* add static check

* delete the dy codes
上级 66682be0
......@@ -1889,6 +1889,11 @@ void MatrixPowerInferMeta(const MetaTensor& x, int n, MetaTensor* out) {
"The Input(X) should have at least 2 dimensions. But "
"received a %d dimension tensor.",
n_dim));
for (int i = 0; i < n_dim; ++i)
PADDLE_ENFORCE_NE(
dims[i],
0,
phi::errors::InvalidArgument("The size of Input(X) should not be 0."));
PADDLE_ENFORCE_EQ(dims[n_dim - 2],
dims[n_dim - 1],
phi::errors::InvalidArgument(
......
......@@ -312,6 +312,10 @@ class TestMatrixPowerAPIError(unittest.TestCase):
input = fluid.data(name="input_3", shape=[4, 5], dtype="float32")
self.assertRaises(ValueError, paddle.linalg.matrix_power, input, 2)
# The size of input should not be 0
input = fluid.data(name="input_4", shape=[1, 1, 0, 0], dtype="float32")
self.assertRaises(ValueError, paddle.linalg.matrix_power, input, 2)
class TestMatrixPowerSingularAPI(unittest.TestCase):
def setUp(self):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册