未验证 提交 71c71e68 编写于 作者: S Shibo Tao 提交者: GitHub

fix logical_* ops' doc (#25479)

* fix doc of logical_* op.

* fix doc of op pow.

* fix comment syntax error9D

* fix operator reciprocal demo.

* fix logical_* ops' doc. test=develop,test=document_fix

* bug fix. test=develop,test=document_fix

* bug fix. test=develop,test=document_fix

* bug fix. test=develop,test=document_fix

* bug fix. test=develop,test=document_fix
上级 a4d3335b
...@@ -24,12 +24,12 @@ class BinaryLogicalOpProtoMaker : public framework::OpProtoAndCheckerMaker { ...@@ -24,12 +24,12 @@ class BinaryLogicalOpProtoMaker : public framework::OpProtoAndCheckerMaker {
void Make() override { void Make() override {
OpComment comment; OpComment comment;
AddInput("X", string::Sprintf("Left hand operand of %s operator. Must be " AddInput("X", string::Sprintf("Left hand operand of %s operator. Must be "
"a LoDTensor or Tensor of type bool.", "a Variable of type bool.",
comment.type)); comment.type));
AddInput("Y", string::Sprintf("Right hand operand of %s operator. Must be " AddInput("Y", string::Sprintf("Right hand operand of %s operator. Must be "
"a LoDTensor or Tensor of type bool.", "a Variable of type bool.",
comment.type)); comment.type));
AddOutput("Out", string::Sprintf("n-dim bool LoDTensor or Tensor")); AddOutput("Out", string::Sprintf("n-dim bool Variable"));
AddComment(string::Sprintf(R"DOC(%s Operator AddComment(string::Sprintf(R"DOC(%s Operator
It operates element-wise on X and Y, and returns the Out. X, Y and Out are N-dim boolean LoDTensor or Tensor. It operates element-wise on X and Y, and returns the Out. X, Y and Out are N-dim boolean LoDTensor or Tensor.
......
...@@ -12006,23 +12006,21 @@ def _logical_op(op_name, x, y, out=None, name=None, binary_op=True): ...@@ -12006,23 +12006,21 @@ def _logical_op(op_name, x, y, out=None, name=None, binary_op=True):
def logical_and(x, y, out=None, name=None): def logical_and(x, y, out=None, name=None):
""" """
:alias_main: paddle.logical_and :alias_main: paddle.logical_and
:alias: paddle.logical_and,paddle.tensor.logical_and,paddle.tensor.logic.logical_and :alias: paddle.logical_and, paddle.tensor.logical_and, paddle.tensor.logic.logical_and
:old_api: paddle.fluid.layers.logical_and :old_api: paddle.fluid.layers.logical_and
logical_and Operator ``logical_and`` operator computes element-wise logical AND on ``x`` and ``y``, and returns ``out``. ``x``, ``y`` and ``out`` are N-dim boolean ``Variable``.
Each element of ``out`` is calculated by
It operates element-wise on X and Y, and returns the Out. X, Y and Out are N-dim boolean LoDTensor or Tensor.
Each element of Out is calculated by
.. math:: .. math::
Out = X \land Y out = x \&\& y
Args: Args:
x(${x_type}): ${x_comment} x(${x_type}): ${x_comment}.
y(${y_type}): ${y_comment} y(${y_type}): ${y_comment}.
out(LoDTensor or Tensor): The LoDTensor or Tensor that specifies the output of the operator, which can be any Variable that has been created in the program. The default value is None, and a new Variable will be created to save the output. out(Variable): The ``Variable`` that specifies the output of the operator, which can be any ``Variable`` that has been created in the program. The default value is None, and a new ``Variable`` will be created to save the output.
name(str|None): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name` name(str|None): The default value is None. Normally there is no need for users to set this property. For more information, please refer to :ref:`api_guide_Name`.
Returns: Returns:
${out_type}: ${out_comment} ${out_type}: ${out_comment}
...@@ -12030,25 +12028,16 @@ def logical_and(x, y, out=None, name=None): ...@@ -12030,25 +12028,16 @@ def logical_and(x, y, out=None, name=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle
import numpy as np import numpy as np
# Graph organizing paddle.enable_imperative()
x = fluid.layers.data(name='x', shape=[2], dtype='bool') x_data = np.array([True, True, False, False], dtype=np.bool)
y = fluid.layers.data(name='y', shape=[2], dtype='bool') y_data = np.array([True, False, True, False], dtype=np.bool)
res = fluid.layers.logical_and(x=x, y=y) x = paddle.imperative.to_variable(x_data)
# The comment lists another available method. y = paddle.imperative.to_variable(y_data)
# res = fluid.layers.fill_constant(shape=[2], dtype='bool', value=0) res = paddle.logical_and(x, y)
# fluid.layers.logical_and(x=x, y=y, out=res) print(res.numpy()) # [True False False False]
# Create an executor using CPU as an example
exe = fluid.Executor(fluid.CPUPlace())
# Execute
x_i = np.array([[1, 0], [0, 1]]).astype(np.bool)
y_i = np.array([[1, 1], [0, 0]]).astype(np.bool)
res_val, = exe.run(fluid.default_main_program(), feed={'x':x_i, 'y':y_i}, fetch_list=[res])
print(res_val) # [[True, False], [False, False]]
""" """
return _logical_op( return _logical_op(
...@@ -12059,23 +12048,21 @@ def logical_and(x, y, out=None, name=None): ...@@ -12059,23 +12048,21 @@ def logical_and(x, y, out=None, name=None):
def logical_or(x, y, out=None, name=None): def logical_or(x, y, out=None, name=None):
""" """
:alias_main: paddle.logical_or :alias_main: paddle.logical_or
:alias: paddle.logical_or,paddle.tensor.logical_or,paddle.tensor.logic.logical_or :alias: paddle.logical_or, paddle.tensor.logical_or, paddle.tensor.logic.logical_or
:old_api: paddle.fluid.layers.logical_or :old_api: paddle.fluid.layers.logical_or
logical_or Operator
It operates element-wise on X and Y, and returns the Out. X, Y and Out are N-dim boolean LoDTensor or Tensor. ``logical_or`` operator computes element-wise logical OR on ``x`` and ``y``, and returns ``out``. ``x``, ``y`` and ``out`` are N-dim boolean ``Variable``.
Each element of Out is calculated by Each element of ``out`` is calculated by
.. math:: .. math::
Out = X \lor Y out = x || y
Args: Args:
x(${x_type}): ${x_comment} x(${x_type}): ${x_comment}.
y(${y_type}): ${y_comment} y(${y_type}): ${y_comment}.
out(LoDTensor or Tensor): The LoDTensor or Tensor that specifies the output of the operator, which can be any Variable that has been created in the program. The default value is None, and a new Variable will be created to save the output. out(Variable): The ``Variable`` that specifies the output of the operator, which can be any ``Variable`` that has been created in the program. The default value is None, and a new ``Variable`` will be created to save the output.
name(str|None): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name` name(str|None): The default value is None. Normally there is no need for users to set this property. For more information, please refer to :ref:`api_guide_Name`.
Returns: Returns:
${out_type}: ${out_comment} ${out_type}: ${out_comment}
...@@ -12083,25 +12070,16 @@ def logical_or(x, y, out=None, name=None): ...@@ -12083,25 +12070,16 @@ def logical_or(x, y, out=None, name=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle
import numpy as np import numpy as np
# Graph organizing paddle.enable_imperative()
x = fluid.layers.data(name='x', shape=[2], dtype='bool') x_data = np.array([True, True, False, False], dtype=np.bool)
y = fluid.layers.data(name='y', shape=[2], dtype='bool') y_data = np.array([True, False, True, False], dtype=np.bool)
res = fluid.layers.logical_or(x=x, y=y) x = paddle.imperative.to_variable(x_data)
# The comment lists another available method. y = paddle.imperative.to_variable(y_data)
# res = fluid.layers.fill_constant(shape=[2], dtype='bool', value=0) res = paddle.logical_or(x, y)
# fluid.layers.logical_or(x=x, y=y, out=res) print(res.numpy()) # [True True True False]
# Create an executor using CPU as an example
exe = fluid.Executor(fluid.CPUPlace())
# Execute
x_i = np.array([[1, 0], [0, 1]]).astype(np.bool)
y_i = np.array([[1, 1], [0, 0]]).astype(np.bool)
res_val, = exe.run(fluid.default_main_program(), feed={'x':x_i, 'y':y_i}, fetch_list=[res])
print(res_val) # [[True, True], [False, True]]
""" """
return _logical_op( return _logical_op(
...@@ -12112,23 +12090,21 @@ def logical_or(x, y, out=None, name=None): ...@@ -12112,23 +12090,21 @@ def logical_or(x, y, out=None, name=None):
def logical_xor(x, y, out=None, name=None): def logical_xor(x, y, out=None, name=None):
""" """
:alias_main: paddle.logical_xor :alias_main: paddle.logical_xor
:alias: paddle.logical_xor,paddle.tensor.logical_xor,paddle.tensor.logic.logical_xor :alias: paddle.logical_xor, paddle.tensor.logical_xor, paddle.tensor.logic.logical_xor
:old_api: paddle.fluid.layers.logical_xor :old_api: paddle.fluid.layers.logical_xor
logical_xor Operator
It operates element-wise on X and Y, and returns the Out. X, Y and Out are N-dim boolean LoDTensor or Tensor. ``logical_xor`` operator computes element-wise logical XOR on ``x`` and ``y``, and returns ``out``. ``x``, ``y`` and ``out`` are N-dim boolean ``Variable``.
Each element of Out is calculated by Each element of ``out`` is calculated by
.. math:: .. math::
Out = (X \lor Y) \land \lnot (X \land Y) out = (x || y) \&\& !(x \&\& y)
Args: Args:
x(${x_type}): ${x_comment} x(${x_type}): ${x_comment}.
y(${y_type}): ${y_comment} y(${y_type}): ${y_comment}.
out(LoDTensor or Tensor): The LoDTensor or Tensor that specifies the output of the operator, which can be any Variable that has been created in the program. The default value is None, and a new Variable will be created to save the output. out(Variable): The ``Variable`` that specifies the output of the operator, which can be any ``Variable`` that has been created in the program. The default value is None, and a new ``Variable`` will be created to save the output.
name(str|None): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name` name(str|None): The default value is None. Normally there is no need for users to set this property. For more information, please refer to :ref:`api_guide_Name`.
Returns: Returns:
${out_type}: ${out_comment} ${out_type}: ${out_comment}
...@@ -12136,25 +12112,16 @@ def logical_xor(x, y, out=None, name=None): ...@@ -12136,25 +12112,16 @@ def logical_xor(x, y, out=None, name=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle
import numpy as np import numpy as np
# Graph organizing paddle.enable_imperative()
x = fluid.layers.data(name='x', shape=[2], dtype='bool') x_data = np.array([True, True, False, False], dtype=np.bool)
y = fluid.layers.data(name='y', shape=[2], dtype='bool') y_data = np.array([True, False, True, False], dtype=np.bool)
res = fluid.layers.logical_xor(x=x, y=y) x = paddle.imperative.to_variable(x_data)
# The comment lists another available method. y = paddle.imperative.to_variable(y_data)
# res = fluid.layers.fill_constant(shape=[2], dtype='bool', value=0) res = paddle.logical_xor(x, y)
# fluid.layers.logical_xor(x=x, y=y, out=res) print(res.numpy()) # [False True True False]
# Create an executor using CPU as an example
exe = fluid.Executor(fluid.CPUPlace())
# Execute
x_i = np.array([[1, 0], [0, 1]]).astype(np.bool)
y_i = np.array([[1, 1], [0, 0]]).astype(np.bool)
res_val, = exe.run(fluid.default_main_program(), feed={'x':x_i, 'y':y_i}, fetch_list=[res])
print(res_val) # [[False, True], [False, True]]
""" """
return _logical_op( return _logical_op(
...@@ -12165,46 +12132,34 @@ def logical_xor(x, y, out=None, name=None): ...@@ -12165,46 +12132,34 @@ def logical_xor(x, y, out=None, name=None):
def logical_not(x, out=None, name=None): def logical_not(x, out=None, name=None):
""" """
:alias_main: paddle.logical_not :alias_main: paddle.logical_not
:alias: paddle.logical_not,paddle.tensor.logical_not,paddle.tensor.logic.logical_not :alias: paddle.logical_not, paddle.tensor.logical_not, paddle.tensor.logic.logical_not
:old_api: paddle.fluid.layers.logical_not :old_api: paddle.fluid.layers.logical_not
logical_not Operator ``logical_not`` operator computes element-wise logical NOT on ``x``, and returns ``out``. ``x`` and ``out`` are N-dim boolean ``Variable``.
Each element of ``out`` is calculated by
It operates element-wise on X, and returns the Out. X and Out are N-dim boolean LoDTensor or Tensor.
Each element of Out is calculated by
.. math:: .. math::
Out = \lnot X out = !x
Args: Args:
x(${x_type}): ${x_comment} x(${x_type}): ${x_comment}.
out(LoDTensor/Tensor): The LoDTensor/Tensor that specifies the output of the operator, which can be any Variable that has been created in the program. The default value is None, and a new Variable will be created to save the output. out(Variable): The ``Variable`` that specifies the output of the operator, which can be any ``Variable`` that has been created in the program. The default value is None, and a new ``Variable` will be created to save the output.
name(str|None): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name` name(str|None): The default value is None. Normally there is no need for users to set this property. For more information, please refer to :ref:`api_guide_Name`.
Returns: Returns:
${out_type}: ${out_comment} ${out_type}: ${out_comment}
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np import numpy as np
# Graph organizing paddle.enable_imperative()
x = fluid.layers.data(name='x', shape=[2], dtype='bool') x_data = np.array([True, False, True, False], dtype=np.bool)
res = fluid.layers.logical_not(x) x = paddle.imperative.to_variable(x_data)
# The comment lists another avaliable method. res = paddle.logical_not(x)
# res = fluid.layers.fill_constant(shape=[2], dtype='bool', value=0) print(res.numpy()) # [False True False True]
# fluid.layers.logical_not(x, out=res)
# Create an executor using CPU as an example
exe = fluid.Executor(fluid.CPUPlace())
# Execute
x_i = np.array([[1, 0]]).astype(np.bool)
res_val, = exe.run(fluid.default_main_program(), feed={'x':x_i}, fetch_list=[res])
print(res_val) # [[False, True]]
""" """
return _logical_op( return _logical_op(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册