未验证 提交 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 {
void Make() override {
OpComment comment;
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));
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));
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
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):
def logical_and(x, y, out=None, name=None):
"""
: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
logical_and Operator
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
``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
.. math::
Out = X \land Y
out = x \&\& y
Args:
x(${x_type}): ${x_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.
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`
x(${x_type}): ${x_comment}.
y(${y_type}): ${y_comment}.
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 users to set this property. For more information, please refer to :ref:`api_guide_Name`.
Returns:
${out_type}: ${out_comment}
......@@ -12030,25 +12028,16 @@ def logical_and(x, y, out=None, name=None):
Examples:
.. code-block:: python
import paddle.fluid as fluid
import paddle
import numpy as np
# Graph organizing
x = fluid.layers.data(name='x', shape=[2], dtype='bool')
y = fluid.layers.data(name='y', shape=[2], dtype='bool')
res = fluid.layers.logical_and(x=x, y=y)
# The comment lists another available method.
# res = fluid.layers.fill_constant(shape=[2], dtype='bool', value=0)
# fluid.layers.logical_and(x=x, y=y, out=res)
# 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]]
paddle.enable_imperative()
x_data = np.array([True, True, False, False], dtype=np.bool)
y_data = np.array([True, False, True, False], dtype=np.bool)
x = paddle.imperative.to_variable(x_data)
y = paddle.imperative.to_variable(y_data)
res = paddle.logical_and(x, y)
print(res.numpy()) # [True False False False]
"""
return _logical_op(
......@@ -12059,23 +12048,21 @@ def logical_and(x, y, out=None, name=None):
def logical_or(x, y, out=None, name=None):
"""
: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
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.
Each element of Out is calculated by
``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
.. math::
Out = X \lor Y
out = x || y
Args:
x(${x_type}): ${x_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.
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`
x(${x_type}): ${x_comment}.
y(${y_type}): ${y_comment}.
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 users to set this property. For more information, please refer to :ref:`api_guide_Name`.
Returns:
${out_type}: ${out_comment}
......@@ -12083,25 +12070,16 @@ def logical_or(x, y, out=None, name=None):
Examples:
.. code-block:: python
import paddle.fluid as fluid
import paddle
import numpy as np
# Graph organizing
x = fluid.layers.data(name='x', shape=[2], dtype='bool')
y = fluid.layers.data(name='y', shape=[2], dtype='bool')
res = fluid.layers.logical_or(x=x, y=y)
# The comment lists another available method.
# res = fluid.layers.fill_constant(shape=[2], dtype='bool', value=0)
# fluid.layers.logical_or(x=x, y=y, out=res)
# 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]]
paddle.enable_imperative()
x_data = np.array([True, True, False, False], dtype=np.bool)
y_data = np.array([True, False, True, False], dtype=np.bool)
x = paddle.imperative.to_variable(x_data)
y = paddle.imperative.to_variable(y_data)
res = paddle.logical_or(x, y)
print(res.numpy()) # [True True True False]
"""
return _logical_op(
......@@ -12112,23 +12090,21 @@ def logical_or(x, y, out=None, name=None):
def logical_xor(x, y, out=None, name=None):
"""
: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
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.
Each element of Out is calculated by
``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
.. math::
Out = (X \lor Y) \land \lnot (X \land Y)
out = (x || y) \&\& !(x \&\& y)
Args:
x(${x_type}): ${x_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.
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`
x(${x_type}): ${x_comment}.
y(${y_type}): ${y_comment}.
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 users to set this property. For more information, please refer to :ref:`api_guide_Name`.
Returns:
${out_type}: ${out_comment}
......@@ -12136,25 +12112,16 @@ def logical_xor(x, y, out=None, name=None):
Examples:
.. code-block:: python
import paddle.fluid as fluid
import paddle
import numpy as np
# Graph organizing
x = fluid.layers.data(name='x', shape=[2], dtype='bool')
y = fluid.layers.data(name='y', shape=[2], dtype='bool')
res = fluid.layers.logical_xor(x=x, y=y)
# The comment lists another available method.
# res = fluid.layers.fill_constant(shape=[2], dtype='bool', value=0)
# fluid.layers.logical_xor(x=x, y=y, out=res)
# 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]]
paddle.enable_imperative()
x_data = np.array([True, True, False, False], dtype=np.bool)
y_data = np.array([True, False, True, False], dtype=np.bool)
x = paddle.imperative.to_variable(x_data)
y = paddle.imperative.to_variable(y_data)
res = paddle.logical_xor(x, y)
print(res.numpy()) # [False True True False]
"""
return _logical_op(
......@@ -12165,46 +12132,34 @@ def logical_xor(x, y, out=None, name=None):
def logical_not(x, out=None, name=None):
"""
: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
logical_not Operator
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
``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
.. math::
Out = \lnot X
out = !x
Args:
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.
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`
x(${x_type}): ${x_comment}.
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 users to set this property. For more information, please refer to :ref:`api_guide_Name`.
Returns:
${out_type}: ${out_comment}
Examples:
.. code-block:: python
import paddle.fluid as fluid
import paddle
import numpy as np
# Graph organizing
x = fluid.layers.data(name='x', shape=[2], dtype='bool')
res = fluid.layers.logical_not(x)
# The comment lists another avaliable method.
# res = fluid.layers.fill_constant(shape=[2], dtype='bool', value=0)
# 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]]
paddle.enable_imperative()
x_data = np.array([True, False, True, False], dtype=np.bool)
x = paddle.imperative.to_variable(x_data)
res = paddle.logical_not(x)
print(res.numpy()) # [False True False True]
"""
return _logical_op(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册