未验证 提交 382cf5d7 编写于 作者: L lijianshe02 提交者: GitHub

add input type and input data type check for Print_op test=develop (#21250)

* add input type and input data type check for Print_op test=develop
上级 6fc3e8ec
......@@ -27,7 +27,7 @@ import numpy
import warnings
import six
from functools import reduce, partial
from ..data_feeder import convert_dtype
from ..data_feeder import convert_dtype, check_type_and_dtype
__all__ = [
'While', 'Switch', 'increment', 'array_write', 'create_array', 'less_than',
......@@ -253,6 +253,10 @@ def Print(input,
data: 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
'''
check_type_and_dtype(input, 'input', Variable,
['float32', 'float64', 'int32_t', 'int64_t', 'bool'],
'fluid.layers.Print')
helper = LayerHelper('print' + "_" + input.name, **locals())
output = helper.create_variable_for_type_inference(input.dtype)
helper.append_op(
......
......@@ -24,6 +24,8 @@ from paddle.fluid.framework import switch_main_program
from paddle.fluid.framework import Program
import numpy as np
from simple_nets import simple_fc_net, init_data
from paddle.fluid import compiler, Program, program_guard
from op_test import OpTest
class TestPrintOpCPU(unittest.TestCase):
......@@ -80,6 +82,18 @@ class TestPrintOpCPU(unittest.TestCase):
return_numpy=False)
class TestPrintOpError(OpTest):
def test_errors(self):
with program_guard(Program(), Program()):
# The input type of Print_op must be Variable.
x1 = fluid.create_lod_tensor(
np.array([[-1]]), [[1]], fluid.CPUPlace())
self.assertRaises(TypeError, fluid.layers.Print, x1)
# The input dtype of Print_op must be float32, float64, int32_t, int64_t or bool.
x2 = fluid.layers.data(name='x2', shape=[4], dtype="float16")
self.assertRaises(TypeError, fluid.layers.Print, x2)
@unittest.skipIf(not core.is_compiled_with_cuda(),
"core is not compiled with CUDA")
class TestPrintOpGPU(TestPrintOpCPU):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册