From c7ae6c62cd2ed74812a4420669814a388e7c9e5d Mon Sep 17 00:00:00 2001 From: Guo Sheng Date: Sat, 12 Oct 2019 22:00:55 +0800 Subject: [PATCH] Fix the assign data check (#20564) * Fix the assign data check. test=develop * Fix test_assign_op.py. test=develop --- python/paddle/fluid/layers/tensor.py | 6 +++--- python/paddle/fluid/tests/unittests/test_assign_op.py | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/python/paddle/fluid/layers/tensor.py b/python/paddle/fluid/layers/tensor.py index 806149b5b2..2928cd69ba 100644 --- a/python/paddle/fluid/layers/tensor.py +++ b/python/paddle/fluid/layers/tensor.py @@ -455,12 +455,12 @@ def assign(input, output=None): helper = LayerHelper('assign', **locals()) if isinstance(input, Variable): if convert_dtype(input.dtype) not in [ - 'float32', 'float64', 'int32', 'int64' + 'float32', 'float64', 'int32', 'int64', 'bool' ]: raise TypeError( "When the type of 'input' in assign is Variable, the data " - "type of 'input' must be float32, float64, int32 or int64, " - "but received %s." % convert_dtype(input.dtype)) + "type of 'input' must be float32, float64, int32, int64 or " + "bool, but received %s." % convert_dtype(input.dtype)) if output is None: output = helper.create_variable_for_type_inference( dtype=input.dtype) diff --git a/python/paddle/fluid/tests/unittests/test_assign_op.py b/python/paddle/fluid/tests/unittests/test_assign_op.py index fce7331f50..4d43747676 100644 --- a/python/paddle/fluid/tests/unittests/test_assign_op.py +++ b/python/paddle/fluid/tests/unittests/test_assign_op.py @@ -44,9 +44,7 @@ class TestAssignOpError(op_test.OpTest): x1 = fluid.create_lod_tensor( np.array([[-1]]), [[1]], fluid.CPUPlace()) self.assertRaises(TypeError, fluid.layers.assign, x1) - # When the type of input is Variable, the dtype of input must be float32, float64, int32, int64. - x2 = fluid.layers.data(name='x2', shape=[4], dtype="bool") - self.assertRaises(TypeError, fluid.layers.assign, x2) + # When the type of input is Variable, the dtype of input must be float32, float64, int32, int64, bool. x3 = fluid.layers.data(name='x3', shape=[4], dtype="float16") self.assertRaises(TypeError, fluid.layers.assign, x3) x4 = fluid.layers.data(name='x4', shape=[4], dtype="uint8") -- GitLab