未验证 提交 53fb0e92 编写于 作者: K kinghuin 提交者: GitHub

fix compare and logical ops cond/out parameter doc bug, test=develop (#23862)

 fix compare and logical ops cond/out parameter doc bug,correct the dtype message 
上级 b89dd86f
...@@ -1408,8 +1408,9 @@ def less_than(x, y, force_cpu=None, cond=None): ...@@ -1408,8 +1408,9 @@ def less_than(x, y, force_cpu=None, cond=None):
x(${x_type}): ${x_comment}. x(${x_type}): ${x_comment}.
y(${y_type}): ${y_comment}. y(${y_type}): ${y_comment}.
force_cpu(${force_cpu_type}): ${force_cpu_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: Returns:
${out_comment}. ${out_comment}.
...@@ -1471,12 +1472,11 @@ def less_equal(x, y, cond=None): ...@@ -1471,12 +1472,11 @@ def less_equal(x, y, cond=None):
Args: Args:
x(Variable): First input to compare which is N-D tensor. The input data type should be float32, float64, int32, int64. 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. 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 \ cond(Variable, optional): Optional output which can be any created Variable that meets the requirements to store the result of *less_equal*.
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 \ if cond is None, a new Varibale will be created to store the result.
and data type of this tensor should be the same as input :attr:`x`. Default value is :attr:`None`.
Returns: 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: Examples:
.. code-block:: python .. code-block:: python
...@@ -1494,8 +1494,7 @@ def less_equal(x, y, cond=None): ...@@ -1494,8 +1494,7 @@ def less_equal(x, y, cond=None):
check_variable_and_dtype(y, "y", ["float32", "float64", "int32", "int64"], check_variable_and_dtype(y, "y", ["float32", "float64", "int32", "int64"],
"less_equal") "less_equal")
if cond is not None: if cond is not None:
check_variable_and_dtype(cond, "cond", [convert_dtype(x.dtype)], check_type(cond, "cond", Variable, "less_equal")
"less_equal")
helper = LayerHelper("less_equal", **locals()) helper = LayerHelper("less_equal", **locals())
if cond is None: if cond is None:
...@@ -1521,12 +1520,11 @@ def greater_than(x, y, cond=None): ...@@ -1521,12 +1520,11 @@ def greater_than(x, y, cond=None):
Args: Args:
x(Variable): First input to compare which is N-D tensor. The input data type should be float32, float64, int32, int64. 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. 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 \ cond(Variable, optional): Optional output which can be any created Variable that meets the requirements to store the result of *greater_than*.
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 \ if cond is None, a new Varibale will be created to store the result.
of this tensor should be the same as input :attr:`x` . Default value is :attr:`None`.
Returns: 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: Examples:
.. code-block:: python .. code-block:: python
...@@ -1543,8 +1541,7 @@ def greater_than(x, y, cond=None): ...@@ -1543,8 +1541,7 @@ def greater_than(x, y, cond=None):
check_variable_and_dtype(y, "y", ["float32", "float64", "int32", "int64"], check_variable_and_dtype(y, "y", ["float32", "float64", "int32", "int64"],
"greater_than") "greater_than")
if cond is not None: if cond is not None:
check_variable_and_dtype(cond, "cond", [convert_dtype(x.dtype)], check_type(cond, "cond", Variable, "greater_than")
"greater_than")
helper = LayerHelper("greater_than", **locals()) helper = LayerHelper("greater_than", **locals())
if cond is None: if cond is None:
...@@ -1570,12 +1567,11 @@ def greater_equal(x, y, cond=None): ...@@ -1570,12 +1567,11 @@ def greater_equal(x, y, cond=None):
Args: Args:
x(Variable): First input to compare which is N-D tensor. The input data type should be float32, float64, int32, int64. 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. 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 \ cond(Variable, optional): Optional output which can be any created Variable that meets the requirements to store the result of *greater_equal*.
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 \ if cond is None, a new Varibale will be created to store the result.
type of this tensor is the same as input :attr:`x`. Default value is :attr:`None`.
Returns: 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: Examples:
.. code-block:: python .. code-block:: python
...@@ -1594,8 +1590,7 @@ def greater_equal(x, y, cond=None): ...@@ -1594,8 +1590,7 @@ def greater_equal(x, y, cond=None):
check_variable_and_dtype(y, "y", ["float32", "float64", "int32", "int64"], check_variable_and_dtype(y, "y", ["float32", "float64", "int32", "int64"],
"greater_equal") "greater_equal")
if cond is not None: if cond is not None:
check_variable_and_dtype(cond, "cond", [convert_dtype(x.dtype)], check_type(cond, "cond", Variable, "greater_equal")
"greater_equal")
helper = LayerHelper("greater_equal", **locals()) helper = LayerHelper("greater_equal", **locals())
if cond is None: if cond is None:
...@@ -1645,8 +1640,7 @@ def equal(x, y, cond=None): ...@@ -1645,8 +1640,7 @@ def equal(x, y, cond=None):
check_variable_and_dtype(y, "y", ["float32", "float64", "int32", "int64"], check_variable_and_dtype(y, "y", ["float32", "float64", "int32", "int64"],
"equal") "equal")
if cond is not None: if cond is not None:
check_variable_and_dtype(cond, "cond", [convert_dtype(x.dtype)], check_type(cond, "cond", Variable, "equal")
"equal")
helper = LayerHelper("equal", **locals()) helper = LayerHelper("equal", **locals())
if cond is None: if cond is None:
...@@ -1666,12 +1660,11 @@ def not_equal(x, y, cond=None): ...@@ -1666,12 +1660,11 @@ def not_equal(x, y, cond=None):
Args: Args:
x(Variable): First input to compare which is N-D tensor. The input data type should be float32, float64, int32, int64. 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. 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 \ cond(Variable, optional): Optional output which can be any created Variable that meets the requirements to store the result of *not_equal*.
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 \ if cond is None, a new Varibale will be created to store the result.
type of this tensor should be the same as input :attr:`x`. Default value is :attr:`None`.
Returns: 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: Examples:
.. code-block:: python .. code-block:: python
...@@ -1687,8 +1680,7 @@ def not_equal(x, y, cond=None): ...@@ -1687,8 +1680,7 @@ def not_equal(x, y, cond=None):
check_variable_and_dtype(y, "y", ["float32", "float64", "int32", "int64"], check_variable_and_dtype(y, "y", ["float32", "float64", "int32", "int64"],
"not_equal") "not_equal")
if cond is not None: if cond is not None:
check_variable_and_dtype(cond, "cond", [convert_dtype(x.dtype)], check_type(cond, "cond", Variable, "not_equal")
"not_equal")
helper = LayerHelper("not_equal", **locals()) helper = LayerHelper("not_equal", **locals())
if cond is None: if cond is None:
......
...@@ -11432,7 +11432,7 @@ def _logical_op(op_name, x, y, out=None, name=None, binary_op=True): ...@@ -11432,7 +11432,7 @@ def _logical_op(op_name, x, y, out=None, name=None, binary_op=True):
if y is not None: if y is not None:
check_variable_and_dtype(y, "y", ["bool"], op_name) check_variable_and_dtype(y, "y", ["bool"], op_name)
if out is not None: 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()) helper = LayerHelper(op_name, **locals())
......
...@@ -41,7 +41,6 @@ def create_test_class(op_type, typename, callback): ...@@ -41,7 +41,6 @@ def create_test_class(op_type, typename, callback):
x = fluid.layers.data(name='x', shape=[2], dtype='int32') x = fluid.layers.data(name='x', shape=[2], dtype='int32')
y = fluid.layers.data(name='y', shape=[2], dtype='int32') y = fluid.layers.data(name='y', shape=[2], dtype='int32')
a = fluid.layers.data(name='a', shape=[2], dtype='int16') 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": if self.op_type == "less_than":
self.assertRaises( self.assertRaises(
TypeError, TypeError,
...@@ -51,8 +50,6 @@ def create_test_class(op_type, typename, callback): ...@@ -51,8 +50,6 @@ def create_test_class(op_type, typename, callback):
force_cpu=1) force_cpu=1)
op = eval("fluid.layers.%s" % self.op_type) op = eval("fluid.layers.%s" % self.op_type)
self.assertRaises(TypeError, op, x=x, y=y, cond=1) 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=x, y=a)
self.assertRaises(TypeError, op, x=a, y=y) self.assertRaises(TypeError, op, x=a, y=y)
......
...@@ -50,10 +50,8 @@ def create_test_class(op_type, callback, binary_op=True): ...@@ -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=y, out=1)
self.assertRaises(TypeError, op, x=x, y=a) self.assertRaises(TypeError, op, x=x, y=a)
self.assertRaises(TypeError, op, x=a, y=y) self.assertRaises(TypeError, op, x=a, y=y)
self.assertRaises(TypeError, op, x=x, y=y, out=a)
else: else:
self.assertRaises(TypeError, op, x=x, out=1) self.assertRaises(TypeError, op, x=x, out=1)
self.assertRaises(TypeError, op, x=x, out=a)
self.assertRaises(TypeError, op, x=a) self.assertRaises(TypeError, op, x=a)
Cls.__name__ = op_type Cls.__name__ = op_type
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册