未验证 提交 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,
def adaptive_avg_pool1d(x, output_size, name=None):
"""
This API implements adaptive average pooling 1d operation.
See more details in :ref:`api_nn_pooling_AdaptiveAvgPool1d` .
Adaptive average pooling 1d operation on :attr:`x` according to :attr:`output_size`.
Notes:
See more details in :ref:`api_nn_pooling_AdaptiveAvgPool1d` .
Args:
x (Tensor): The input tensor of pooling operator, which is a 3-D tensor
with shape [N, C, L]. The format of input tensor is NCL,
where N is batch size, C is the number of channels, L is the
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.
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.
output_size (int): The target output size. Its data type must be int.
name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.
Returns:
Tensor: The output tensor of adaptive average pooling result. The data type is same
as input tensor.
Tensor: The result of 1D adaptive average pooling. Its data type is same as input.
Examples:
.. code-block:: python
:name: code-example1
:name: adaptive_avg_pool1d-example
# average adaptive pool1d
# suppose input data in shape of [N, C, L], `output_size` is m or [m],
......
......@@ -22,28 +22,26 @@ class XavierNormal(XavierInitializer):
This class implements the Xavier weight initializer from the paper
`Understanding the difficulty of training deep feedforward neural
networks <http://proceedings.mlr.press/v9/glorot10a/glorot10a.pdf>`_
by Xavier Glorot and Yoshua Bengio, using a normal distribution.
The mean is 0 and the standard deviation is
by Xavier Glorot and Yoshua Bengio, using a normal distribution whose mean is :math:`0` and standard deviation is
.. math::
\sqrt{\frac{2.0}{fan\_in + fan\_out}}
\sqrt{\frac{2.0}{fan\_in + fan\_out}}.
Args:
fan_in (float, optional): fan_in for Xavier initialization, It is
inferred from the tensor. The default value is None.
fan_out (float, optional): fan_out for Xavier initialization, it is
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
property. For more information, please refer to :ref:`api_guide_Name`.
fan_in (float, optional): fan_in for Xavier initialization, which is
inferred from the Tensor. The default value is None.
fan_out (float, optional): fan_out for Xavier initialization, which is
inferred from the Tensor. The default value is None.
name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.
Returns:
A parameter initialized by Xavier weight, using a normal distribution.
Examples:
.. code-block:: python
:name: initializer_XavierNormal-example
import paddle
......@@ -81,25 +79,25 @@ class XavierUniform(XavierInitializer):
This initializer is designed to keep the scale of the gradients
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::
x = \sqrt{\frac{6.0}{fan\_in + fan\_out}}
x = \sqrt{\frac{6.0}{fan\_in + fan\_out}}.
Args:
fan_in (float, optional): fan_in for Xavier initialization, it is
inferred from the tensor. The default value is None.
fan_out (float, optional): fan_out for Xavier initialization, it is
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
property. For more information, please refer to :ref:`api_guide_Name`.
fan_in (float, optional): fan_in for Xavier initialization, which is
inferred from the Tensor. The default value is None.
fan_out (float, optional): fan_out for Xavier initialization, which is
inferred from the Tensor. The default value is None.
name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.
Returns:
A parameter initialized by Xavier weight, using a uniform distribution.
Examples:
.. code-block:: python
:name: initializer_XavierUniform-example
import paddle
......
......@@ -619,42 +619,32 @@ class MaxPool3D(Layer):
class AdaptiveAvgPool1D(Layer):
r"""
This operation applies a 1D adaptive average pooling over an input signal composed
of several input planes, based on the input, output_size, return_mask parameters.
Input(X) and output(Out) are in NCL format, where N is batch
size, C is the number of channels, L is the length of the feature.
The output tensor shape will be [N, C, output_size].
A 1D adaptive average pooling over an input signal composed
of several input planes, based on :attr:`output_size`.
Input and output are in NCL format, where N is batch
size, C is the number of channels and L is the length of the feature.
The shape of output will be :math:`[N, C, output\_size]`.
For average adaptive pool1d:
The formulation for average adaptive pool1d is
.. 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:
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.
output_size(int): The target output size. Its data type must be int.
name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.
Returns:
A callable object of AdaptiveAvgPool1D.
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.
A callable object for computing 1D adaptive average pooling.
Examples:
.. code-block:: python
:name: AdaptiveAvgPool1D-example
# average adaptive pool1d
# 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
......
......@@ -1479,22 +1479,21 @@ def empty_like(x, dtype=None, name=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:
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.
Note: the float64 data will be converted to float32 because of current platform protobuf
x (Tensor|np.ndarray|list|tuple|scalar): A Tensor, numpy ndarray, tuple/list of scalar,
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
data limitation.
output (Tensor, optional): A tensor. If :attr:`output` is None, a new tensor will
be created as :attr:`output`. Default: None.
output (Tensor, optional): A Tensor. If :attr:`output` is None, a new Tensor will be created as :attr:`output`. Default: None.
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:
.. code-block:: python
:name: assign-example
import paddle
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]]
......
......@@ -572,49 +572,46 @@ def mode(x, axis=-1, keepdim=False, name=None):
def where(condition, x=None, y=None, name=None):
r"""
Return a tensor of elements selected from either $x$ or $y$, depending on $condition$.
**Note**:
``paddle.where(condition)`` is identical to ``paddle.nonzero(condition, as_tuple=True)``.
Return a Tensor of elements selected from either :attr:`x` or :attr:`y` according to corresponding elements of :attr:`condition`. Concretely,
.. math::
out_i =
\begin{cases}
x_i, \quad \text{if} \ condition_i \ is \ True \\
y_i, \quad \text{if} \ condition_i \ is \ False \\
\end{cases}
out_i =
\begin{cases}
x_i, & \text{if} \ condition_i \ \text{is} \ True \\
y_i, & \text{if} \ condition_i \ \text{is} \ False \\
\end{cases}.
Notes:
``numpy.where(condition)`` is identical to ``paddle.nonzero(condition, as_tuple=True)``, please refer to :ref:`api_tensor_search_nonzero`.
Args:
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.
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.
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`.
condition (Tensor): The condition to choose x or y. When True (nonzero), yield x, otherwise yield y.
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|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.
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:
.. code-block:: python
:name:where-example
import paddle
import paddle
x = paddle.to_tensor([0.9383, 0.1983, 3.2, 1.2])
y = paddle.to_tensor([1.0, 1.0, 1.0, 1.0])
out = paddle.where(x>1, x, y)
x = paddle.to_tensor([0.9383, 0.1983, 3.2, 1.2])
y = paddle.to_tensor([1.0, 1.0, 1.0, 1.0])
out = paddle.where(x>1, x, y)
print(out)
#out: [1.0, 1.0, 3.2, 1.2]
print(out)
#out: [1.0, 1.0, 3.2, 1.2]
out = paddle.where(x>1)
print(out)
#out: (Tensor(shape=[2, 1], dtype=int64, place=CPUPlace, stop_gradient=True,
# [[2],
# [3]]),)
out = paddle.where(x>1)
print(out)
#out: (Tensor(shape=[2, 1], dtype=int64, place=CPUPlace, stop_gradient=True,
# [[2],
# [3]]),)
"""
if np.isscalar(x):
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.
先完成此消息的编辑!
想要评论请 注册