未验证 提交 d43e4047 编写于 作者: L Leo Chen 提交者: GitHub

refine err msg, test=develop (#24550)

上级 615a8bfc
......@@ -114,6 +114,13 @@ class SumOp : public framework::OperatorWithKernel {
framework::LibraryType library{framework::LibraryType::kPlain};
framework::DataLayout layout{framework::DataLayout::kAnyLayout};
PADDLE_ENFORCE_GT(x_vars.size(), 0, platform::errors::InvalidArgument(
"Input[X] should not be empty"));
PADDLE_ENFORCE_NOT_NULL(
x_vars[0], platform::errors::NotFound(
"Input var[%s] should not be nullptr", x_vars_name[0]));
if (x_vars[0]->IsType<framework::LoDTensor>()) {
int dtype = -1;
for (size_t idx = 0; idx < x_vars.size(); ++idx) {
......
......@@ -298,6 +298,20 @@ class TestRaiseSumsError(unittest.TestCase):
self.assertRaises(TypeError, test_out_dtype)
class TestSumOpError(unittest.TestCase):
def test_errors(self):
def test_empty_list_input():
with fluid.dygraph.guard():
fluid.core.ops.sum([])
def test_list_of_none_input():
with fluid.dygraph.guard():
fluid.core.ops.sum([None])
self.assertRaises(Exception, test_empty_list_input)
self.assertRaises(Exception, test_list_of_none_input)
create_test_sum_fp16_class(TestSelectedRowsSumOp)
create_test_sum_fp16_class(TestLoDTensorAndSelectedRowsOp)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册