diff --git a/python/paddle/base/dygraph/base.py b/python/paddle/base/dygraph/base.py index 1d2ff80247e640..fcdc2354297e59 100644 --- a/python/paddle/base/dygraph/base.py +++ b/python/paddle/base/dygraph/base.py @@ -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 diff --git a/python/paddle/nn/functional/input.py b/python/paddle/nn/functional/input.py index c51e48ebfe1a8c..8f1bc5554adb6b 100644 --- a/python/paddle/nn/functional/input.py +++ b/python/paddle/nn/functional/input.py @@ -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 diff --git a/python/paddle/sparse/unary.py b/python/paddle/sparse/unary.py index 82a4688fdbd669..fdc3ecc2fb5258 100644 --- a/python/paddle/sparse/unary.py +++ b/python/paddle/sparse/unary.py @@ -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. diff --git a/python/paddle/tensor/creation.py b/python/paddle/tensor/creation.py index ce23b5fe53259f..a6c550bcfbabfc 100644 --- a/python/paddle/tensor/creation.py +++ b/python/paddle/tensor/creation.py @@ -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``. @@ -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`. diff --git a/python/paddle/tensor/logic.py b/python/paddle/tensor/logic.py index 6e02ce0d548385..daa44fb57818d8 100755 --- a/python/paddle/tensor/logic.py +++ b/python/paddle/tensor/logic.py @@ -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`. diff --git a/python/paddle/tensor/manipulation.py b/python/paddle/tensor/manipulation.py index 1c6b10b08c7d3b..b3879bf38b08ed 100644 --- a/python/paddle/tensor/manipulation.py +++ b/python/paddle/tensor/manipulation.py @@ -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 @@ -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``. @@ -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, @@ -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`. @@ -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: @@ -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: diff --git a/python/paddle/tensor/math.py b/python/paddle/tensor/math.py index f9cc6e1e1f6e78..b7436709607678 100644 --- a/python/paddle/tensor/math.py +++ b/python/paddle/tensor/math.py @@ -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, @@ -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. diff --git a/python/paddle/tensor/random.py b/python/paddle/tensor/random.py index 939432af4a5490..5bd1f391ffb446 100644 --- a/python/paddle/tensor/random.py +++ b/python/paddle/tensor/random.py @@ -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 @@ -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`. diff --git a/python/paddle/tensor/stat.py b/python/paddle/tensor/stat.py index 6847f2b6288acf..f159748da04b93 100644 --- a/python/paddle/tensor/stat.py +++ b/python/paddle/tensor/stat.py @@ -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` . @@ -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. @@ -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`. diff --git a/python/paddle/utils/decorator_utils.py b/python/paddle/utils/decorator_utils.py index 1dd819c3c38171..8a68ca366949cb 100644 --- a/python/paddle/utils/decorator_utils.py +++ b/python/paddle/utils/decorator_utils.py @@ -262,7 +262,8 @@ 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) @@ -270,10 +271,8 @@ def process( 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: