未验证 提交 eac125f9 编写于 作者: B BrilliantYuKaimin 提交者: GitHub

修复 paddle.assign 等 API 的文档 (#42942)

* Update creation.py

* Update search.py

* Update search.py

* Update xavier.py

* Update xavier.py

* Update pooling.py

* Update pooling.py

* Update pooling.py

* Update search.py
上级 d95293f3
...@@ -1273,24 +1273,20 @@ def max_pool3d(x, ...@@ -1273,24 +1273,20 @@ def max_pool3d(x,
def adaptive_avg_pool1d(x, output_size, name=None): def adaptive_avg_pool1d(x, output_size, name=None):
""" """
This API implements adaptive average pooling 1d operation. Adaptive average pooling 1d operation on :attr:`x` according to :attr:`output_size`.
See more details in :ref:`api_nn_pooling_AdaptiveAvgPool1d` .
Notes:
See more details in :ref:`api_nn_pooling_AdaptiveAvgPool1d` .
Args: Args:
x (Tensor): The input tensor of pooling operator, which is a 3-D tensor x (Tensor): The input Tensor of pooling, which is a 3-D tensor with shape :math:`[N, C, L]`, where :math:`N` is batch size, :math:`C` is the number of channels and :math:`L` is the length of the feature. The data type is float32 or float64.
with shape [N, C, L]. The format of input tensor is NCL, output_size (int): The target output size. Its data type must be int.
where N is batch size, C is the number of channels, L is the name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.
length of the feature. The data type is float32 or float64.
output_size (int): The target output size. It must be an integer.
name(str, optional): For detailed information, please refer
to :ref:`api_guide_Name`. Usually name is no need to set and
None by default.
Returns: Returns:
Tensor: The output tensor of adaptive average pooling result. The data type is same Tensor: The result of 1D adaptive average pooling. Its data type is same as input.
as input tensor.
Examples: Examples:
.. code-block:: python .. code-block:: python
:name: code-example1 :name: adaptive_avg_pool1d-example
# average adaptive pool1d # average adaptive pool1d
# suppose input data in shape of [N, C, L], `output_size` is m or [m], # suppose input data in shape of [N, C, L], `output_size` is m or [m],
......
...@@ -22,28 +22,26 @@ class XavierNormal(XavierInitializer): ...@@ -22,28 +22,26 @@ class XavierNormal(XavierInitializer):
This class implements the Xavier weight initializer from the paper This class implements the Xavier weight initializer from the paper
`Understanding the difficulty of training deep feedforward neural `Understanding the difficulty of training deep feedforward neural
networks <http://proceedings.mlr.press/v9/glorot10a/glorot10a.pdf>`_ networks <http://proceedings.mlr.press/v9/glorot10a/glorot10a.pdf>`_
by Xavier Glorot and Yoshua Bengio, using a normal distribution. by Xavier Glorot and Yoshua Bengio, using a normal distribution whose mean is :math:`0` and standard deviation is
The mean is 0 and the standard deviation is
.. math:: .. math::
\sqrt{\frac{2.0}{fan\_in + fan\_out}} \sqrt{\frac{2.0}{fan\_in + fan\_out}}.
Args: Args:
fan_in (float, optional): fan_in for Xavier initialization, It is fan_in (float, optional): fan_in for Xavier initialization, which is
inferred from the tensor. The default value is None. inferred from the Tensor. The default value is None.
fan_out (float, optional): fan_out for Xavier initialization, it is fan_out (float, optional): fan_out for Xavier initialization, which is
inferred from the tensor. The default value is None. inferred from the Tensor. The default value is None.
name(str, optional): The default value is None. Normally there is no need for user to set this name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.
property. For more information, please refer to :ref:`api_guide_Name`.
Returns: Returns:
A parameter initialized by Xavier weight, using a normal distribution. A parameter initialized by Xavier weight, using a normal distribution.
Examples: Examples:
.. code-block:: python .. code-block:: python
:name: initializer_XavierNormal-example
import paddle import paddle
...@@ -81,25 +79,25 @@ class XavierUniform(XavierInitializer): ...@@ -81,25 +79,25 @@ class XavierUniform(XavierInitializer):
This initializer is designed to keep the scale of the gradients This initializer is designed to keep the scale of the gradients
approximately same in all the layers. In case of Uniform distribution, approximately same in all the layers. In case of Uniform distribution,
the range is [-x, x], where the range is :math:`[-x,x]`, where
.. math:: .. math::
x = \sqrt{\frac{6.0}{fan\_in + fan\_out}} x = \sqrt{\frac{6.0}{fan\_in + fan\_out}}.
Args: Args:
fan_in (float, optional): fan_in for Xavier initialization, it is fan_in (float, optional): fan_in for Xavier initialization, which is
inferred from the tensor. The default value is None. inferred from the Tensor. The default value is None.
fan_out (float, optional): fan_out for Xavier initialization, it is fan_out (float, optional): fan_out for Xavier initialization, which is
inferred from the tensor. The default value is None. inferred from the Tensor. The default value is None.
name(str, optional): The default value is None. Normally there is no need for user to set this name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.
property. For more information, please refer to :ref:`api_guide_Name`.
Returns: Returns:
A parameter initialized by Xavier weight, using a uniform distribution. A parameter initialized by Xavier weight, using a uniform distribution.
Examples: Examples:
.. code-block:: python .. code-block:: python
:name: initializer_XavierUniform-example
import paddle import paddle
......
...@@ -619,42 +619,32 @@ class MaxPool3D(Layer): ...@@ -619,42 +619,32 @@ class MaxPool3D(Layer):
class AdaptiveAvgPool1D(Layer): class AdaptiveAvgPool1D(Layer):
r""" r"""
This operation applies a 1D adaptive average pooling over an input signal composed A 1D adaptive average pooling over an input signal composed
of several input planes, based on the input, output_size, return_mask parameters. of several input planes, based on :attr:`output_size`.
Input(X) and output(Out) are in NCL format, where N is batch Input and output are in NCL format, where N is batch
size, C is the number of channels, L is the length of the feature. size, C is the number of channels and L is the length of the feature.
The output tensor shape will be [N, C, output_size]. The shape of output will be :math:`[N, C, output\_size]`.
For average adaptive pool1d: The formulation for average adaptive pool1d is
.. math:: .. math::
lstart &= floor(i * L_{in} / L_{out}) lstart &= \lfloor i * L_{in} / L_{out}\rfloor,
lend &= ceil((i + 1) * L_{in} / L_{out}) lend &= \lceil(i + 1) * L_{in} / L_{out}\rceil,
Output(i) &= \frac{ \sum Input[lstart:lend]}{lend - lstart} Output(i) &= \frac{\sum Input[lstart:lend]}{lend - lstart}.
Parameters: Parameters:
output_size(int): The target output size. It must be an integer. output_size(int): The target output size. Its data type must be int.
name(str, optional): For detailed information, please refer to :ref:`api_guide_Name`. name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.
Usually name is no need to set and None by default.
Returns: Returns:
A callable object of AdaptiveAvgPool1D. A callable object for computing 1D adaptive average pooling.
Raises:
ValueError: 'output_size' should be an integer.
Shape:
- x(Tensor): 3-D tensor. The input tensor of adaptive avg pool1d operator, which is a 3-D tensor.
The data type can be float32, float64.
- output(Tensor): 3-D tensor. The output tensor of adaptive avg pool1d operator, which is a 3-D tensor.
The data type is same as input x.
Examples: Examples:
.. code-block:: python .. code-block:: python
:name: AdaptiveAvgPool1D-example
# average adaptive pool1d # average adaptive pool1d
# suppose input data in shape of [N, C, L], `output_size` is m or [m], # suppose input data in shape of [N, C, L], `output_size` is m or [m],
# output shape is [N, C, m], adaptive pool divide L dimension # output shape is [N, C, m], adaptive pool divide L dimension
......
...@@ -1479,22 +1479,21 @@ def empty_like(x, dtype=None, name=None): ...@@ -1479,22 +1479,21 @@ def empty_like(x, dtype=None, name=None):
def assign(x, output=None): def assign(x, output=None):
""" """
The OP copies the :attr:`x` to the :attr:`output`. Copy value of the :attr:`x` to the :attr:`output`.
Parameters: Parameters:
x (Tensor|np.ndarray|list|tuple|scalar): A tensor, numpy ndarray, tuple/list of scalar, x (Tensor|np.ndarray|list|tuple|scalar): A Tensor, numpy ndarray, tuple/list of scalar,
or scalar. Its data type supports float16, float32, float64, int32, int64, and bool. or scalar. Its data type can be float16, float32, float64, int32, int64 or bool. Note: the float64 data will be converted to float32 because of current platform protobuf
Note: the float64 data will be converted to float32 because of current platform protobuf
data limitation. data limitation.
output (Tensor, optional): A tensor. If :attr:`output` is None, a new tensor will output (Tensor, optional): A Tensor. If :attr:`output` is None, a new Tensor will be created as :attr:`output`. Default: None.
be created as :attr:`output`. Default: None.
Returns: Returns:
Tensor: A tensor with the same shape, data type and value as :attr:`x`. Tensor: A Tensor with the same shape, data type and value as :attr:`x`.
Examples: Examples:
.. code-block:: python .. code-block:: python
:name: assign-example
import paddle import paddle
import numpy as np import numpy as np
data = paddle.full(shape=[3, 2], fill_value=2.5, dtype='float64') # [[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]] data = paddle.full(shape=[3, 2], fill_value=2.5, dtype='float64') # [[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]]
......
...@@ -572,49 +572,46 @@ def mode(x, axis=-1, keepdim=False, name=None): ...@@ -572,49 +572,46 @@ def mode(x, axis=-1, keepdim=False, name=None):
def where(condition, x=None, y=None, name=None): def where(condition, x=None, y=None, name=None):
r""" r"""
Return a tensor of elements selected from either $x$ or $y$, depending on $condition$. Return a Tensor of elements selected from either :attr:`x` or :attr:`y` according to corresponding elements of :attr:`condition`. Concretely,
**Note**:
``paddle.where(condition)`` is identical to ``paddle.nonzero(condition, as_tuple=True)``.
.. math:: .. math::
out_i = out_i =
\begin{cases} \begin{cases}
x_i, \quad \text{if} \ condition_i \ is \ True \\ x_i, & \text{if} \ condition_i \ \text{is} \ True \\
y_i, \quad \text{if} \ condition_i \ is \ False \\ y_i, & \text{if} \ condition_i \ \text{is} \ False \\
\end{cases} \end{cases}.
Notes:
``numpy.where(condition)`` is identical to ``paddle.nonzero(condition, as_tuple=True)``, please refer to :ref:`api_tensor_search_nonzero`.
Args: Args:
condition(Tensor): The condition to choose x or y. When True(nonzero), yield x, otherwise yield y. condition (Tensor): The condition to choose x or y. When True (nonzero), yield x, otherwise yield y.
x(Tensor or Scalar, optional): x is a Tensor or Scalar with data type float32, float64, int32, int64. Either both or neither of x and y should be given. x (Tensor|scalar, optional): A Tensor or scalar to choose when the condition is True with data type of float32, float64, int32 or int64. Either both or neither of x and y should be given.
y(Tensor or Scalar, optional): y is a Tensor or Scalar with data type float32, float64, int32, int64. Either both or neither of x and y should be given. y (Tensor|scalar, optional): A Tensor or scalar to choose when the condition is False with data type of float32, float64, int32 or int64. Either both or neither of x and y should be given.
name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.
name(str, optional): 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`.
Returns: Returns:
Tensor: A Tensor with the same data dype as x. Tensor: A Tensor with the same shape as :attr:`condition` and same data type as :attr:`x` and :attr:`y`.
Examples: Examples:
.. code-block:: python .. code-block:: python
:name:where-example
import paddle import paddle
x = paddle.to_tensor([0.9383, 0.1983, 3.2, 1.2]) x = paddle.to_tensor([0.9383, 0.1983, 3.2, 1.2])
y = paddle.to_tensor([1.0, 1.0, 1.0, 1.0]) y = paddle.to_tensor([1.0, 1.0, 1.0, 1.0])
out = paddle.where(x>1, x, y) out = paddle.where(x>1, x, y)
print(out) print(out)
#out: [1.0, 1.0, 3.2, 1.2] #out: [1.0, 1.0, 3.2, 1.2]
out = paddle.where(x>1) out = paddle.where(x>1)
print(out) print(out)
#out: (Tensor(shape=[2, 1], dtype=int64, place=CPUPlace, stop_gradient=True, #out: (Tensor(shape=[2, 1], dtype=int64, place=CPUPlace, stop_gradient=True,
# [[2], # [[2],
# [3]]),) # [3]]),)
""" """
if np.isscalar(x): if np.isscalar(x):
x = paddle.full([1], x, np.array([x]).dtype.name) x = paddle.full([1], x, np.array([x]).dtype.name)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册