未验证 提交 a2e08657 编写于 作者: Y Yiqun Liu 提交者: GitHub

Add dimension check for inverse to avoid dividing by 0 error when input's...

Add dimension check for inverse to avoid dividing by 0 error when input's shape is [0, 0, 0]. (#34996)
上级 ca7f5208
...@@ -35,6 +35,14 @@ class InverseOp : public framework::OperatorWithKernel { ...@@ -35,6 +35,14 @@ class InverseOp : public framework::OperatorWithKernel {
"The dimension of Input(Input) is expected to be no less than 2. " "The dimension of Input(Input) is expected to be no less than 2. "
"But recieved: Input(Input)'s dimension = %d, shape = [%s].", "But recieved: Input(Input)'s dimension = %d, shape = [%s].",
input_rank, input_dims)); input_rank, input_dims));
for (int64_t i = 0; i < input_rank; ++i) {
PADDLE_ENFORCE_EQ(
(input_dims[i] == -1) || (input_dims[i] > 0), true,
platform::errors::InvalidArgument(
"Each dimension of input tensor is expected to be -1 or a "
"positive number, but recieved %d. Input's shape is [%s].",
input_dims[i], input_dims));
}
if (input_dims[input_rank - 2] > 0 && input_dims[input_rank - 1] > 0) { if (input_dims[input_rank - 2] > 0 && input_dims[input_rank - 1] > 0) {
PADDLE_ENFORCE_EQ(input_dims[input_rank - 2], input_dims[input_rank - 1], PADDLE_ENFORCE_EQ(input_dims[input_rank - 2], input_dims[input_rank - 1],
platform::errors::InvalidArgument( platform::errors::InvalidArgument(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册