Skip to content

Commit

Permalink
add static check
Browse files Browse the repository at this point in the history
  • Loading branch information
Liyulingyue committed Jan 20, 2023
1 parent 5c30503 commit 09926af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions paddle/phi/infermeta/unary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion python/paddle/fluid/tests/unittests/test_matrix_power_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,11 @@ def test_errors(self):
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
# The size of input should not be 0 (static graph)
input = fluid.data(name="input_4", shape=[1, 1, 0, 0], dtype="float32")
self.assertRaises(ValueError, paddle.linalg.matrix_power, input, 2)

# The size of input should not be 0 (dynamic graph)
with paddle.fluid.dygraph.guard():
input = paddle.to_tensor(
paddle.uniform([1, 1, 0, 0]).astype('float32')
Expand Down

0 comments on commit 09926af

Please sign in to comment.