Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/paddle/base/dygraph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ def no_grad(func=None):

Also functions as a decorator. (Make sure to instantiate without parenthesis.)

.. note::
Alias Support: The parameter name ``orig_func`` can be used as an alias for ``func``.

Examples:

.. code-block:: python
Expand Down
5 changes: 5 additions & 0 deletions python/paddle/nn/functional/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,14 @@ def embedding(
The input padding_idx is less than 0, it is automatically converted to padding_idx = -1 + 128 = 127
It will pad all-zero data when id is 127.

.. note::
Alias Support: The parameter name ``input`` can be used as an alias for ``x``.
For example, ``embedding(input=tensor_x, ...)`` is equivalent to ``embedding(x=tensor_x, ...)``.

Args:
x(Tensor): A Tensor with type int32/int64, which contains the id information. The value of the input id should
satisfy :math:`0 <= id < weight.shape[0]` .
alias: ``input``.
weight (Tensor): The weight. A Tensor with shape of lookup table parameter. It should have two elements which
indicates the size of the dictionary of embeddings and the size of each embedding vector respectively.
sparse(bool, optional): The flag indicating whether to use sparse update. This parameter only
Expand Down
4 changes: 4 additions & 0 deletions python/paddle/sparse/unary.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,10 @@ def reshape(x: Tensor, shape: ShapeLike, name: str | None = None) -> Tensor:

- 3. Given a 3-D tensor x with a shape [2, 4, 6], and the target shape is [-1, 0, 3, 2], the reshape operator will transform x into a 4-D tensor with shape [2, 4, 3, 2] and leaving x's data unchanged. In this case, besides -1, 0 means the actual dimension value is going to be copied from the corresponding dimension of x.

.. note::
Alias Support: The parameter name ``input`` can be used as an alias for ``x``.
For example, ``reshape(input=tensor_x, ...)`` is equivalent to ``reshape(x=tensor_x, ...)``.

Args:
x (Tensor): The input sparse tensor with data type ``float32``, ``float64``, ``int32``, ``int64`` or ``bool``.
shape (list|tuple): Define the target shape. At most one dimension of the target shape can be -1.
Expand Down
16 changes: 15 additions & 1 deletion python/paddle/tensor/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1347,9 +1347,14 @@ def ones_like(
Returns a Tensor filled with the value 1, with the same shape and
data type (use ``dtype`` if ``dtype`` is not None) as ``x``.

.. note::
Alias Support: The parameter name ``input`` can be used as an alias for ``x``.
For example, ``ones_like(input=tensor_x, ...)`` is equivalent to ``ones_like(x=tensor_x, ...)``.

Args:
x(Tensor): The input tensor which specifies shape and dtype. The
dtype of ``x`` can be bool, float16, float32, float64, int32, int64.
alias: ``input``.
dtype(str|np.dtype, optional): The data type of the
output tensor. Supported data types: bool, float16, float32, float64,
int32, int64. If ``dtype`` is None, the data type is the same as ``x``.
Expand Down Expand Up @@ -1401,10 +1406,19 @@ def zeros(
"""
Creates a tensor of specified :attr:`shape` and :attr:`dtype`, and fills it with 0.

.. note::
Alias Support: The parameter name ``size`` can be used as an alias for ``shape``.
``shape`` can be a variable number of arguments.
For example:
``paddle.ones(1, 2, 3, dtype=paddle.float32)``
``paddle.ones(size=[1, 2, 3], dtype=paddle.float32)``

Args:
shape (tuple|list|Tensor): Shape of the Tensor to be created. The data type is ``int32`` or ``int64`` .
shape (tuple|list|Tensor|variable number of arguments): Shape of the Tensor to be created. The data type is ``int32`` or ``int64`` .
alias: ``size``.
If ``shape`` is a list or tuple, each element of it should be integer or 0-D Tensor with shape [].
If ``shape`` is an Tensor, it should be an 1-D Tensor which represents a list.
``shape`` can be a variable number of arguments.
dtype(np.dtype|str, optional): Data type of output Tensor, it supports
bool, float16, float32, float64, int32 and int64. Default: if None, the data type is float32.
property. For more information, please refer to :ref:`api_guide_Name`.
Expand Down
6 changes: 6 additions & 0 deletions python/paddle/tensor/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1346,9 +1346,15 @@ def bitwise_or(

.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor

.. note::
Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``other`` can be used as an alias for ``y``.
For example, ``bitwise_or(input=tensor_x, other=tensor_y, ...)`` is equivalent to ``bitwise_or(x=tensor_x, y=tensor_y, ...)``.

Args:
x (Tensor): Input Tensor of ``bitwise_or`` . It is a N-D Tensor of bool, uint8, int8, int16, int32, int64.
alias: ``input``.
y (Tensor): Input Tensor of ``bitwise_or`` . It is a N-D Tensor of bool, uint8, int8, int16, int32, int64.
alias: ``oth``.
out (Tensor|None, optional): Result of ``bitwise_or`` . It is a N-D Tensor with the same data type of input Tensor. Default: None.
name (str|None, 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`.
Expand Down
36 changes: 35 additions & 1 deletion python/paddle/tensor/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3496,14 +3496,20 @@ def unique_consecutive(
This function is different from :ref:`api_paddle_unique` in the sense that this function
only eliminates consecutive duplicate values. This semantics is similar to :ref:`api_paddle_unique` in C++.

.. note::
Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``dim`` can be used as an alias for ``axis``.
For example, ``unique_consecutive(input=tensor_x, dim=1, ...)`` is equivalent to ``unique_consecutive(x=tensor_x, axis=1, ...)``.

Args:
x(Tensor): the input tensor, it's data type should be float32, float64, int32, int64.
alias: ``input``.
return_inverse(bool, optional): If True, also return the indices for where elements in
the original input ended up in the returned unique consecutive tensor. Default is False.
return_counts(bool, optional): If True, also return the counts for each unique consecutive element.
Default is False.
axis(int, optional): The axis to apply unique consecutive. If None, the input will be flattened.
Default is None.
alias: ``dim``.
dtype(np.dtype|str, optional): The data type `inverse` tensor: int32 or int64.
Default: int64.
name(str|None, optional): Name for the operation. For more information, please refer to
Expand Down Expand Up @@ -4904,11 +4910,17 @@ def broadcast_to(
:alt: broadcast_to API
:align: center

.. note::
Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``size`` can be used as an alias for ``shape``.
For example, ``broadcast_to(input=tensor_x, size=[2, 3], ...)`` is equivalent to ``broadcast_to(x=tensor_x, shape=[2, 3], ...)``.

Args:
x (Tensor): The input tensor, its data type is bool, float16, float32, float64, int32, int64, uint8 or uint16.
alias: ``input``.
shape (list|tuple|Tensor): The result shape after broadcasting. The data type is int32. If shape is a list or tuple, all its elements
should be integers or 0-D or 1-D Tensors with the data type int32. If shape is a Tensor, it should be an 1-D Tensor with the data type int32.
The value -1 in shape means keeping the corresponding dimension unchanged.
alias: ``size``.
name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
Returns:
N-D Tensor, A Tensor with the given shape. The data type is the same as ``x``.
Expand Down Expand Up @@ -6446,6 +6458,7 @@ def view_as_real(input: Tensor) -> Tensor:
return as_real(x=input)


@param_two_alias(["x", "input"], ["axis", "dim"])
def repeat_interleave(
x: Tensor,
repeats: int | Tensor,
Expand All @@ -6467,11 +6480,16 @@ def repeat_interleave(
:alt: legend of repeat_interleave API
:align: center

.. note::
Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``dim`` can be used as an alias for ``axis``.
For example, ``repeat_interleave(input=tensor_x, dim=1, ...)`` is equivalent to ``repeat_interleave(x=tensor_x, axis=1, ...)``.

Args:
x (Tensor): The input Tensor to be operated. The data of ``x`` can be one of float32, float64, int32, int64.
alias: ``input``.
repeats (Tensor|int): The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis.
axis (int|None, optional): The dimension in which we manipulate. Default: None, the output tensor is flatten.
alias: ``dim``.
name(str|None, 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`.
Expand Down Expand Up @@ -6855,12 +6873,18 @@ def take_along_axis(
"""
Take values from the input array by given indices matrix along the designated axis.

.. note::
Alias Support: The parameter name ``input`` can be used as an alias for ``arr``, and ``dim`` can be used as an alias for ``axis``.
For example, ``repeat_interleave(input=tensor_arr, dim=1, ...)`` is equivalent to ``repeat_interleave(arr=tensor_arr, axis=1, ...)``.

Args:
arr (Tensor) : The input Tensor. Supported data types are bfloat16, float16, float32, float64,
int32, int64, uint8.
alias: ``input``.
indices (Tensor) : Indices to take along each 1d slice of arr. This must match the dimension of arr,
and need to broadcast against arr. Supported data type are int32 and int64.
axis (int) : The axis to take 1d slices along.
alias: ``dim``.
broadcast (bool, optional): whether the indices broadcast.

Returns:
Expand Down Expand Up @@ -7502,9 +7526,19 @@ def view(
Note that the output Tensor will share data with origin Tensor and doesn't
have a Tensor copy in ``dygraph`` mode.

.. note::
Alias Support: The parameter name ``size`` and ``dtype`` can be used as an alias for ``shape_or_dtype``.
``shape_or_dtype`` can be a variable number of arguments.
For example:
``tensor_x.view(dtype=paddle.float32)``
``tensor_x.view(size=[-1, 1, 3])``
``tensor_x.view(-1, 1, 3)``

Args:
x (Tensor): An N-D Tensor. The data type is ``float32``, ``float64``, ``int32``, ``int64`` or ``bool``
shape_or_dtype (list|tuple|np.dtype|str|VarType): Define the target shape or dtype. If list or tuple, shape_or_dtype represents shape, each element of it should be integer. If np.dtype or str or VarType, shape_or_dtype represents dtype, it can be bool, float16, float32, float64, int8, int32, int64, uint8.
shape_or_dtype (list|tuple|np.dtype|str|VarType|variable number of arguments): Define the target shape or dtype. If list or tuple, shape_or_dtype represents shape, each element of it should be integer. If np.dtype or str or VarType, shape_or_dtype represents dtype, it can be bool, float16, float32, float64, int8, int32, int64, uint8.
``shape_or_dtype`` can be a variable number of arguments.
alias: ``size`` or ``dtype``.
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.

Returns:
Expand Down
12 changes: 12 additions & 0 deletions python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -4790,12 +4790,18 @@ def prod(
"""
Compute the product of tensor elements over the given axis.

.. note::
Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``dim`` can be used as an alias for ``axis``.
For example, ``prod(input=tensor_x, dim=1, ...)`` is equivalent to ``prod(x=tensor_x, axis=1, ...)``.

Args:
x (Tensor): The input tensor, its data type should be bfloat16, float16, float32, float64, int32, int64, complex64, complex128.
alias: ``input``.
axis (int|list|tuple|None, optional): The axis along which the product is computed. If :attr:`None`,
multiply all elements of `x` and return a Tensor with a single element,
otherwise must be in the range :math:`[-x.ndim, x.ndim)`. If :math:`axis[i]<0`,
the axis to reduce is :math:`x.ndim + axis[i]`. Default is None.
alias: ``dim``.
keepdim (bool, optional): Whether to reserve the reduced dimension in the output Tensor. The result
tensor will have one fewer dimension than the input unless `keepdim` is true. Default is False.
dtype (str|paddle.dtype|np.dtype, optional): The desired date type of returned tensor, can be bfloat16,
Expand Down Expand Up @@ -6511,11 +6517,17 @@ def diff(
Higher-order differences are computed by using paddle.diff() recursively.
The number of n supports any positive integer value.

.. note::
Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``dim`` can be used as an alias for ``axis``.
For example, ``diff(input=tensor_x, dim=1, ...)`` is equivalent to ``diff(x=tensor_x, axis=1, ...)``.

Args:
x (Tensor): The input tensor to compute the forward difference on, the data type is float16, float32, float64, bool, int32, int64.
alias: ``input``.
n (int, optional): The number of times to recursively compute the difference.
Supports any positive integer value. Default:1
axis (int, optional): The axis to compute the difference along. Default:-1
alias: ``dim``.
prepend (Tensor|None, optional): The tensor to prepend to input along axis before computing the difference.
It's dimensions must be equivalent to that of x,
and its shapes must match x's shape except on axis.
Expand Down
10 changes: 10 additions & 0 deletions python/paddle/tensor/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,14 @@ def multinomial(
0. ``replacement`` indicates whether it is a replaceable sample. If ``replacement``
is True, a category can be sampled more than once.

.. note::
Alias Support: The parameter name ``input`` can be used as an alias for ``x``.
For example, ``multinomial(input=tensor_x, ...)`` is equivalent to ``multinomial(x=tensor_x, ...)``.

Args:
x(Tensor): A tensor with probabilities for generating the random number. The data type
should be float32, float64.
alias: ``input``.
num_samples(int, optional): Number of samples, default is 1.
replacement(bool, optional): Whether it is a replaceable sample, default is False.
name(str|None, optional): The default value is None. Normally there is no
Expand Down Expand Up @@ -1964,9 +1969,14 @@ def exponential_(

f(x) = \lambda e^{-\lambda x}

.. note::
Alias Support: The parameter name ``lambd`` can be used as an alias for ``lam``.
For example, ``exponential_(tensor_x, lambd=1.0, ...)`` is equivalent to ``exponential_(tensor_x, lam=1.0, ...)``.

Args:
x(Tensor): Input tensor. The data type should be float32, float64.
lam(float, optional): :math:`\lambda` parameter of Exponential Distribution. Default, 1.0.
alias: ``lambd``.
name(str|None, 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`.
Expand Down
14 changes: 14 additions & 0 deletions python/paddle/tensor/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,15 @@ def var(
"""
Computes the variance of ``x`` along ``axis`` .

.. note::
Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``dim`` can be used as an alias for ``axis``.
For example, ``var(input=tensor_x, dim=1, ...)`` is equivalent to ``var(x=tensor_x, axis=1, ...)``.

Args:
x (Tensor): The input Tensor with data type float16, float32, float64.
alias: ``input``.
axis (int|list|tuple|None, optional): The axis along which to perform variance calculations. ``axis`` should be int, list(int) or tuple(int).
alias: ``dim``.

- If ``axis`` is a list/tuple of dimension(s), variance is calculated along all element(s) of ``axis`` . ``axis`` or element(s) of ``axis`` should be in range [-D, D), where D is the dimensions of ``x`` .
- If ``axis`` or element(s) of ``axis`` is less than 0, it works the same way as :math:`axis + D` .
Expand Down Expand Up @@ -506,9 +512,16 @@ def median(
"""
Compute the median along the specified axis.

.. note::
Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``dim`` can be used as an alias for ``axis``.
When an alias replacement occurs, the default parameter for mode setting is min instead of avg.
For example, ``median(input=tensor_x, dim=1, ...)`` is equivalent to ``median(x=tensor_x, axis=1, ...)``.

Args:
x (Tensor): The input Tensor, it's data type can be bfloat16, float16, float32, float64, int32, int64.
alias: ``input``.
axis (int|None, optional): The axis along which to perform median calculations ``axis`` should be int.
alias: ``dim``.
``axis`` should be in range [-D, D), where D is the dimensions of ``x`` .
If ``axis`` is less than 0, it works the same way as :math:`axis + D`.
If ``axis`` is None, median is calculated over all elements of ``x``. Default is None.
Expand All @@ -520,6 +533,7 @@ def median(
mode (str, optional): Whether to use mean or min operation to calculate
the median values when the input tensor has an even number of elements
in the dimension ``axis``. Support 'avg' and 'min'. Default is 'avg'.
When an alias replacement occurs, the default parameter for mode setting is min instead of avg.
name (str|None, optional): Name for the operation (optional, default is None).
For more information, please refer to :ref:`api_guide_Name`.

Expand Down
7 changes: 3 additions & 4 deletions python/paddle/utils/decorator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,17 @@ def process(
return args, kwargs


"""
def view_decorator():
"""
Usage Example:
paddle.view(x=tensor_x, shape_or_dtype=[-1, 1, 3], name=None)
tensor_x.view(paddle.float32) -> paddle.view(tensor_x, paddle.float32)
tensor_x.view(dtype=paddle.float32) -> paddle.view(tensor_x, dtype=paddle.float32)
tensor_x.view([-1, 1, 3]) -> paddle.view(tensor_x, [-1, 1, 3])
tensor_x.view(-1, 1, 3) -> paddle.view(tensor_x, -1, 1, 3)
tensor_x.view(size=[-1, 1, 3]) -> paddle.view(tensor_x, size=[-1, 1, 3])
"""

"""

def view_decorator():
def decorator(func: Callable[_InputT, _RetT]) -> Callable[_InputT, _RetT]:
@functools.wraps(func)
def wrapper(*args: _InputT.args, **kwargs: _InputT.kwargs) -> _RetT:
Expand Down