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

[Divide by 0 Error] add lu check (#49974)

* [Divide by 0 Error] add lu check

* [Divide by 0 Error] lu check migrate to c++
上级 f0811bb7
...@@ -520,6 +520,14 @@ DenseTensor Transpose2DTo6D(const Context& dev_ctx, const DenseTensor& x) { ...@@ -520,6 +520,14 @@ DenseTensor Transpose2DTo6D(const Context& dev_ctx, const DenseTensor& x) {
auto x_dim = x.dims(); auto x_dim = x.dims();
auto x_vec = phi::vectorize<int>(x_dim); auto x_vec = phi::vectorize<int>(x_dim);
int rank = x_vec.size(); int rank = x_vec.size();
for (int i = 0; i < x_dim.size(); i++) {
PADDLE_ENFORCE_LT(0,
x_dim[i],
errors::InvalidArgument(
"The dims of Input(X) should be greater than 0."));
}
std::swap(x_vec[rank - 1], x_vec[rank - 2]); std::swap(x_vec[rank - 1], x_vec[rank - 2]);
std::vector<int> out_shape = x_vec; std::vector<int> out_shape = x_vec;
std::vector<int> axis(rank); std::vector<int> axis(rank);
......
...@@ -303,6 +303,20 @@ class TestLUAPI(unittest.TestCase): ...@@ -303,6 +303,20 @@ class TestLUAPI(unittest.TestCase):
run_lu_static(tensor_shape, dtype) run_lu_static(tensor_shape, dtype)
class TestLUAPIError(unittest.TestCase):
def test_errors(self):
with paddle.fluid.dygraph.guard():
# The size of input in lu should not be 0.
def test_0_size():
array = np.array([], dtype=np.float32)
x = paddle.to_tensor(
np.reshape(array, [0, 0, 0]), dtype='float32'
)
paddle.linalg.lu(x, get_infos=True)
self.assertRaises(ValueError, test_0_size)
if __name__ == "__main__": if __name__ == "__main__":
paddle.enable_static() paddle.enable_static()
unittest.main() unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册