diff --git a/python/paddle/fluid/layers/tensor.py b/python/paddle/fluid/layers/tensor.py index 806149b5b2520403f8a3dd7f5d8611f9e8e9d408..2928cd69ba3e4bfc8d3232b172aeaf1e4c0463ea 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 fce7331f509c5b85c1d4cc61d5fca731b111f8a6..4d43747676dfe31c1600cb3adae3bd14fd927b69 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")