diff --git a/python/paddle/fluid/layers/control_flow.py b/python/paddle/fluid/layers/control_flow.py index 5221ddaa825fc2af66829f94b3931d72d039b7d0..dba0021ef00fdbbc1e3a20cba3c5fb436ffe6390 100755 --- a/python/paddle/fluid/layers/control_flow.py +++ b/python/paddle/fluid/layers/control_flow.py @@ -1408,8 +1408,9 @@ def less_than(x, y, force_cpu=None, cond=None): x(${x_type}): ${x_comment}. y(${y_type}): ${y_comment}. force_cpu(${force_cpu_type}): ${force_cpu_comment}. - cond(Variable|None): Optional output variable to store the result of *less_than* - + cond(Variable, optional): Optional output which can be any created Variable + that meets the requirements to store the result of *less_than*. + if cond is None, a new Varibale will be created to store the result. Returns: ${out_comment}. @@ -1471,12 +1472,11 @@ def less_equal(x, y, cond=None): Args: x(Variable): First input to compare which is N-D tensor. The input data type should be float32, float64, int32, int64. y(Variable): Second input to compare which is N-D tensor. The input data type should be float32, float64, int32, int64. - cond(Variable, optional): If is :attr:`None`, the op will create a variable as output tensor, the input shape and data type of \ - this tensor is the same as input :attr:`x`. If is not :attr:`None`, the op will set the variable as output tensor, the input shape \ - and data type of this tensor should be the same as input :attr:`x`. Default value is :attr:`None`. + cond(Variable, optional): Optional output which can be any created Variable that meets the requirements to store the result of *less_equal*. + if cond is None, a new Varibale will be created to store the result. Returns: - Variable, the output data type is bool.: The tensor variable storing the output, the output shape is the same as input :attr:`x`. + Variable, the output data type is bool: The tensor variable storing the output, the output shape is same as input :attr:`x`. Examples: .. code-block:: python @@ -1494,8 +1494,7 @@ def less_equal(x, y, cond=None): check_variable_and_dtype(y, "y", ["float32", "float64", "int32", "int64"], "less_equal") if cond is not None: - check_variable_and_dtype(cond, "cond", [convert_dtype(x.dtype)], - "less_equal") + check_type(cond, "cond", Variable, "less_equal") helper = LayerHelper("less_equal", **locals()) if cond is None: @@ -1521,12 +1520,11 @@ def greater_than(x, y, cond=None): Args: x(Variable): First input to compare which is N-D tensor. The input data type should be float32, float64, int32, int64. y(Variable): Second input to compare which is N-D tensor. The input data type should be float32, float64, int32, int64. - cond(Variable, optional): If is :attr:`None`, the op will create a variable as output tensor, the shape and data type of this \ - tensor is the same as input :attr:`x` . If is not :attr:`None`, the op will set the variable as output tensor, the shape and data type \ - of this tensor should be the same as input :attr:`x` . Default value is :attr:`None`. + cond(Variable, optional): Optional output which can be any created Variable that meets the requirements to store the result of *greater_than*. + if cond is None, a new Varibale will be created to store the result. Returns: - Variable, the output data type is bool.: The tensor variable storing the output, the output shape is the same as input :attr:`x` . + Variable, the output data type is bool: The tensor variable storing the output, the output shape is same as input :attr:`x` . Examples: .. code-block:: python @@ -1543,8 +1541,7 @@ def greater_than(x, y, cond=None): check_variable_and_dtype(y, "y", ["float32", "float64", "int32", "int64"], "greater_than") if cond is not None: - check_variable_and_dtype(cond, "cond", [convert_dtype(x.dtype)], - "greater_than") + check_type(cond, "cond", Variable, "greater_than") helper = LayerHelper("greater_than", **locals()) if cond is None: @@ -1570,12 +1567,11 @@ def greater_equal(x, y, cond=None): Args: x(Variable): First input to compare which is N-D tensor. The input data type should be float32, float64, int32, int64. y(Variable): Second input to compare which is N-D tensor. The input data type should be float32, float64, int32, int64. - cond(Variable, optional): If is :attr:`None` , the op will create a variable as output tensor, the shape and data type of this \ - tensor is the same as input :attr:`x`. If is not :attr:`None` , the op will set the variable as output tensor, the shape and data \ - type of this tensor is the same as input :attr:`x`. Default value is :attr:`None`. + cond(Variable, optional): Optional output which can be any created Variable that meets the requirements to store the result of *greater_equal*. + if cond is None, a new Varibale will be created to store the result. Returns: - Variable, the output data type is bool.: The tensor variable storing the output, the output shape is the same as input :attr:`x`. + Variable, the output data type is bool: The tensor variable storing the output, the output shape is same as input :attr:`x`. Examples: .. code-block:: python @@ -1594,8 +1590,7 @@ def greater_equal(x, y, cond=None): check_variable_and_dtype(y, "y", ["float32", "float64", "int32", "int64"], "greater_equal") if cond is not None: - check_variable_and_dtype(cond, "cond", [convert_dtype(x.dtype)], - "greater_equal") + check_type(cond, "cond", Variable, "greater_equal") helper = LayerHelper("greater_equal", **locals()) if cond is None: @@ -1645,8 +1640,7 @@ def equal(x, y, cond=None): check_variable_and_dtype(y, "y", ["float32", "float64", "int32", "int64"], "equal") if cond is not None: - check_variable_and_dtype(cond, "cond", [convert_dtype(x.dtype)], - "equal") + check_type(cond, "cond", Variable, "equal") helper = LayerHelper("equal", **locals()) if cond is None: @@ -1666,12 +1660,11 @@ def not_equal(x, y, cond=None): Args: x(Variable): First input to compare which is N-D tensor. The input data type should be float32, float64, int32, int64. y(Variable): Second input to compare which is N-D tensor. The input data type should be float32, float64, int32, int64. - cond(Variable, optional): If is :attr:`None`, the op will create a variable as output tensor, the shape and data type of this \ - tensor is the same as input :attr:`x`. If is not :attr:`None`, the op will set the variable as output tensor, the shape and data \ - type of this tensor should be the same as input :attr:`x`. Default value is :attr:`None`. + cond(Variable, optional): Optional output which can be any created Variable that meets the requirements to store the result of *not_equal*. + if cond is None, a new Varibale will be created to store the result. Returns: - Variable, the output data type is bool.: The tensor variable storing the output, the output shape is the same as input :attr:`x`. + Variable, the output data type is bool: The tensor variable storing the output, the output shape is same as input :attr:`x`. Examples: .. code-block:: python @@ -1687,8 +1680,7 @@ def not_equal(x, y, cond=None): check_variable_and_dtype(y, "y", ["float32", "float64", "int32", "int64"], "not_equal") if cond is not None: - check_variable_and_dtype(cond, "cond", [convert_dtype(x.dtype)], - "not_equal") + check_type(cond, "cond", Variable, "not_equal") helper = LayerHelper("not_equal", **locals()) if cond is None: diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index f4b7ec90cd5db6bac63f53ef4d503bd9e7f5b98f..6f6166dbdfa1e5675ce645b101cb36ce18994d21 100644 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -11432,7 +11432,7 @@ def _logical_op(op_name, x, y, out=None, name=None, binary_op=True): if y is not None: check_variable_and_dtype(y, "y", ["bool"], op_name) if out is not None: - check_variable_and_dtype(out, "out", [convert_dtype(x.dtype)], op_name) + check_type(out, "out", Variable, op_name) helper = LayerHelper(op_name, **locals()) diff --git a/python/paddle/fluid/tests/unittests/test_compare_op.py b/python/paddle/fluid/tests/unittests/test_compare_op.py index eed1aad405ac12222c0ce6d59530dc52ac31383c..9d4a9082b543c1bef67f2a203c27b63bf89c1ef5 100644 --- a/python/paddle/fluid/tests/unittests/test_compare_op.py +++ b/python/paddle/fluid/tests/unittests/test_compare_op.py @@ -41,7 +41,6 @@ def create_test_class(op_type, typename, callback): x = fluid.layers.data(name='x', shape=[2], dtype='int32') y = fluid.layers.data(name='y', shape=[2], dtype='int32') a = fluid.layers.data(name='a', shape=[2], dtype='int16') - b = fluid.layers.data(name='b', shape=[2], dtype='int64') if self.op_type == "less_than": self.assertRaises( TypeError, @@ -51,8 +50,6 @@ def create_test_class(op_type, typename, callback): force_cpu=1) op = eval("fluid.layers.%s" % self.op_type) self.assertRaises(TypeError, op, x=x, y=y, cond=1) - if self.op_type != "less_than": - self.assertRaises(TypeError, op, x=x, y=y, cond=b) self.assertRaises(TypeError, op, x=x, y=a) self.assertRaises(TypeError, op, x=a, y=y) diff --git a/python/paddle/fluid/tests/unittests/test_logical_op.py b/python/paddle/fluid/tests/unittests/test_logical_op.py index 87156ca98c4b2d7ca9fe764cbcbf13a7595c600e..8f0049a8d30d0e1fed1d27cf6e13c036e33678d0 100644 --- a/python/paddle/fluid/tests/unittests/test_logical_op.py +++ b/python/paddle/fluid/tests/unittests/test_logical_op.py @@ -50,10 +50,8 @@ def create_test_class(op_type, callback, binary_op=True): self.assertRaises(TypeError, op, x=x, y=y, out=1) self.assertRaises(TypeError, op, x=x, y=a) self.assertRaises(TypeError, op, x=a, y=y) - self.assertRaises(TypeError, op, x=x, y=y, out=a) else: self.assertRaises(TypeError, op, x=x, out=1) - self.assertRaises(TypeError, op, x=x, out=a) self.assertRaises(TypeError, op, x=a) Cls.__name__ = op_type