Skip to content

Commit bf7de59

Browse files
zhengshengningLuckycheng222
authored andcommitted
[API compatibility] English documentation for adding API aliases (PaddlePaddle#74643)
* add docs1 * English documentation for adding API aliases.
1 parent d0bb22f commit bf7de59

File tree

10 files changed

+107
-6
lines changed

10 files changed

+107
-6
lines changed

python/paddle/base/dygraph/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ def no_grad(func=None):
334334
335335
Also functions as a decorator. (Make sure to instantiate without parenthesis.)
336336
337+
.. note::
338+
Alias Support: The parameter name ``orig_func`` can be used as an alias for ``func``.
339+
337340
Examples:
338341
339342
.. code-block:: python

python/paddle/nn/functional/input.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,14 @@ def embedding(
202202
The input padding_idx is less than 0, it is automatically converted to padding_idx = -1 + 128 = 127
203203
It will pad all-zero data when id is 127.
204204
205+
.. note::
206+
Alias Support: The parameter name ``input`` can be used as an alias for ``x``.
207+
For example, ``embedding(input=tensor_x, ...)`` is equivalent to ``embedding(x=tensor_x, ...)``.
208+
205209
Args:
206210
x(Tensor): A Tensor with type int32/int64, which contains the id information. The value of the input id should
207211
satisfy :math:`0 <= id < weight.shape[0]` .
212+
alias: ``input``.
208213
weight (Tensor): The weight. A Tensor with shape of lookup table parameter. It should have two elements which
209214
indicates the size of the dictionary of embeddings and the size of each embedding vector respectively.
210215
sparse(bool, optional): The flag indicating whether to use sparse update. This parameter only

python/paddle/sparse/unary.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,10 @@ def reshape(x: Tensor, shape: ShapeLike, name: str | None = None) -> Tensor:
905905
906906
- 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.
907907
908+
.. note::
909+
Alias Support: The parameter name ``input`` can be used as an alias for ``x``.
910+
For example, ``reshape(input=tensor_x, ...)`` is equivalent to ``reshape(x=tensor_x, ...)``.
911+
908912
Args:
909913
x (Tensor): The input sparse tensor with data type ``float32``, ``float64``, ``int32``, ``int64`` or ``bool``.
910914
shape (list|tuple): Define the target shape. At most one dimension of the target shape can be -1.

python/paddle/tensor/creation.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,9 +1358,14 @@ def ones_like(
13581358
Returns a Tensor filled with the value 1, with the same shape and
13591359
data type (use ``dtype`` if ``dtype`` is not None) as ``x``.
13601360
1361+
.. note::
1362+
Alias Support: The parameter name ``input`` can be used as an alias for ``x``.
1363+
For example, ``ones_like(input=tensor_x, ...)`` is equivalent to ``ones_like(x=tensor_x, ...)``.
1364+
13611365
Args:
13621366
x(Tensor): The input tensor which specifies shape and dtype. The
13631367
dtype of ``x`` can be bool, float16, float32, float64, int32, int64.
1368+
alias: ``input``.
13641369
dtype(str|np.dtype, optional): The data type of the
13651370
output tensor. Supported data types: bool, float16, float32, float64,
13661371
int32, int64. If ``dtype`` is None, the data type is the same as ``x``.
@@ -1412,10 +1417,19 @@ def zeros(
14121417
"""
14131418
Creates a tensor of specified :attr:`shape` and :attr:`dtype`, and fills it with 0.
14141419
1420+
.. note::
1421+
Alias Support: The parameter name ``size`` can be used as an alias for ``shape``.
1422+
``shape`` can be a variable number of arguments.
1423+
For example:
1424+
``paddle.ones(1, 2, 3, dtype=paddle.float32)``
1425+
``paddle.ones(size=[1, 2, 3], dtype=paddle.float32)``
1426+
14151427
Args:
1416-
shape (tuple|list|Tensor): Shape of the Tensor to be created. The data type is ``int32`` or ``int64`` .
1428+
shape (tuple|list|Tensor|variable number of arguments): Shape of the Tensor to be created. The data type is ``int32`` or ``int64`` .
1429+
alias: ``size``.
14171430
If ``shape`` is a list or tuple, each element of it should be integer or 0-D Tensor with shape [].
14181431
If ``shape`` is an Tensor, it should be an 1-D Tensor which represents a list.
1432+
``shape`` can be a variable number of arguments.
14191433
dtype(np.dtype|str, optional): Data type of output Tensor, it supports
14201434
bool, float16, float32, float64, int32 and int64. Default: if None, the data type is float32.
14211435
property. For more information, please refer to :ref:`api_guide_Name`.

python/paddle/tensor/logic.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,9 +1346,15 @@ def bitwise_or(
13461346
13471347
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
13481348
1349+
.. note::
1350+
Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``other`` can be used as an alias for ``y``.
1351+
For example, ``bitwise_or(input=tensor_x, other=tensor_y, ...)`` is equivalent to ``bitwise_or(x=tensor_x, y=tensor_y, ...)``.
1352+
13491353
Args:
13501354
x (Tensor): Input Tensor of ``bitwise_or`` . It is a N-D Tensor of bool, uint8, int8, int16, int32, int64.
1355+
alias: ``input``.
13511356
y (Tensor): Input Tensor of ``bitwise_or`` . It is a N-D Tensor of bool, uint8, int8, int16, int32, int64.
1357+
alias: ``oth``.
13521358
out (Tensor|None, optional): Result of ``bitwise_or`` . It is a N-D Tensor with the same data type of input Tensor. Default: None.
13531359
name (str|None, optional): The default value is None. Normally there is no need for
13541360
user to set this property. For more information, please refer to :ref:`api_guide_Name`.

python/paddle/tensor/manipulation.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3496,14 +3496,20 @@ def unique_consecutive(
34963496
This function is different from :ref:`api_paddle_unique` in the sense that this function
34973497
only eliminates consecutive duplicate values. This semantics is similar to :ref:`api_paddle_unique` in C++.
34983498
3499+
.. note::
3500+
Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``dim`` can be used as an alias for ``axis``.
3501+
For example, ``unique_consecutive(input=tensor_x, dim=1, ...)`` is equivalent to ``unique_consecutive(x=tensor_x, axis=1, ...)``.
3502+
34993503
Args:
35003504
x(Tensor): the input tensor, it's data type should be float32, float64, int32, int64.
3505+
alias: ``input``.
35013506
return_inverse(bool, optional): If True, also return the indices for where elements in
35023507
the original input ended up in the returned unique consecutive tensor. Default is False.
35033508
return_counts(bool, optional): If True, also return the counts for each unique consecutive element.
35043509
Default is False.
35053510
axis(int, optional): The axis to apply unique consecutive. If None, the input will be flattened.
35063511
Default is None.
3512+
alias: ``dim``.
35073513
dtype(np.dtype|str, optional): The data type `inverse` tensor: int32 or int64.
35083514
Default: int64.
35093515
name(str|None, optional): Name for the operation. For more information, please refer to
@@ -4904,11 +4910,17 @@ def broadcast_to(
49044910
:alt: broadcast_to API
49054911
:align: center
49064912
4913+
.. note::
4914+
Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``size`` can be used as an alias for ``shape``.
4915+
For example, ``broadcast_to(input=tensor_x, size=[2, 3], ...)`` is equivalent to ``broadcast_to(x=tensor_x, shape=[2, 3], ...)``.
4916+
49074917
Args:
49084918
x (Tensor): The input tensor, its data type is bool, float16, float32, float64, int32, int64, uint8 or uint16.
4919+
alias: ``input``.
49094920
shape (list|tuple|Tensor): The result shape after broadcasting. The data type is int32. If shape is a list or tuple, all its elements
49104921
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.
49114922
The value -1 in shape means keeping the corresponding dimension unchanged.
4923+
alias: ``size``.
49124924
name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
49134925
Returns:
49144926
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:
64466458
return as_real(x=input)
64476459

64486460

6461+
@param_two_alias(["x", "input"], ["axis", "dim"])
64496462
def repeat_interleave(
64506463
x: Tensor,
64516464
repeats: int | Tensor,
@@ -6467,11 +6480,16 @@ def repeat_interleave(
64676480
:alt: legend of repeat_interleave API
64686481
:align: center
64696482
6483+
.. note::
6484+
Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``dim`` can be used as an alias for ``axis``.
6485+
For example, ``repeat_interleave(input=tensor_x, dim=1, ...)`` is equivalent to ``repeat_interleave(x=tensor_x, axis=1, ...)``.
64706486
64716487
Args:
64726488
x (Tensor): The input Tensor to be operated. The data of ``x`` can be one of float32, float64, int32, int64.
6489+
alias: ``input``.
64736490
repeats (Tensor|int): The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis.
64746491
axis (int|None, optional): The dimension in which we manipulate. Default: None, the output tensor is flatten.
6492+
alias: ``dim``.
64756493
name(str|None, optional): The default value is None. Normally there is no
64766494
need for user to set this property. For more information, please
64776495
refer to :ref:`api_guide_Name`.
@@ -6855,12 +6873,18 @@ def take_along_axis(
68556873
"""
68566874
Take values from the input array by given indices matrix along the designated axis.
68576875
6876+
.. note::
6877+
Alias Support: The parameter name ``input`` can be used as an alias for ``arr``, and ``dim`` can be used as an alias for ``axis``.
6878+
For example, ``repeat_interleave(input=tensor_arr, dim=1, ...)`` is equivalent to ``repeat_interleave(arr=tensor_arr, axis=1, ...)``.
6879+
68586880
Args:
68596881
arr (Tensor) : The input Tensor. Supported data types are bfloat16, float16, float32, float64,
68606882
int32, int64, uint8.
6883+
alias: ``input``.
68616884
indices (Tensor) : Indices to take along each 1d slice of arr. This must match the dimension of arr,
68626885
and need to broadcast against arr. Supported data type are int32 and int64.
68636886
axis (int) : The axis to take 1d slices along.
6887+
alias: ``dim``.
68646888
broadcast (bool, optional): whether the indices broadcast.
68656889
68666890
Returns:
@@ -7564,9 +7588,19 @@ def view(
75647588
Note that the output Tensor will share data with origin Tensor and doesn't
75657589
have a Tensor copy in ``dygraph`` mode.
75667590
7591+
.. note::
7592+
Alias Support: The parameter name ``size`` and ``dtype`` can be used as an alias for ``shape_or_dtype``.
7593+
``shape_or_dtype`` can be a variable number of arguments.
7594+
For example:
7595+
``tensor_x.view(dtype=paddle.float32)``
7596+
``tensor_x.view(size=[-1, 1, 3])``
7597+
``tensor_x.view(-1, 1, 3)``
7598+
75677599
Args:
75687600
x (Tensor): An N-D Tensor. The data type is ``float32``, ``float64``, ``int32``, ``int64`` or ``bool``
7569-
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.
7601+
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.
7602+
``shape_or_dtype`` can be a variable number of arguments.
7603+
alias: ``size`` or ``dtype``.
75707604
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
75717605
75727606
Returns:

python/paddle/tensor/math.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4790,12 +4790,18 @@ def prod(
47904790
"""
47914791
Compute the product of tensor elements over the given axis.
47924792
4793+
.. note::
4794+
Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``dim`` can be used as an alias for ``axis``.
4795+
For example, ``prod(input=tensor_x, dim=1, ...)`` is equivalent to ``prod(x=tensor_x, axis=1, ...)``.
4796+
47934797
Args:
47944798
x (Tensor): The input tensor, its data type should be bfloat16, float16, float32, float64, int32, int64, complex64, complex128.
4799+
alias: ``input``.
47954800
axis (int|list|tuple|None, optional): The axis along which the product is computed. If :attr:`None`,
47964801
multiply all elements of `x` and return a Tensor with a single element,
47974802
otherwise must be in the range :math:`[-x.ndim, x.ndim)`. If :math:`axis[i]<0`,
47984803
the axis to reduce is :math:`x.ndim + axis[i]`. Default is None.
4804+
alias: ``dim``.
47994805
keepdim (bool, optional): Whether to reserve the reduced dimension in the output Tensor. The result
48004806
tensor will have one fewer dimension than the input unless `keepdim` is true. Default is False.
48014807
dtype (str|paddle.dtype|np.dtype, optional): The desired date type of returned tensor, can be bfloat16,
@@ -6511,11 +6517,17 @@ def diff(
65116517
Higher-order differences are computed by using paddle.diff() recursively.
65126518
The number of n supports any positive integer value.
65136519
6520+
.. note::
6521+
Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``dim`` can be used as an alias for ``axis``.
6522+
For example, ``diff(input=tensor_x, dim=1, ...)`` is equivalent to ``diff(x=tensor_x, axis=1, ...)``.
6523+
65146524
Args:
65156525
x (Tensor): The input tensor to compute the forward difference on, the data type is float16, float32, float64, bool, int32, int64.
6526+
alias: ``input``.
65166527
n (int, optional): The number of times to recursively compute the difference.
65176528
Supports any positive integer value. Default:1
65186529
axis (int, optional): The axis to compute the difference along. Default:-1
6530+
alias: ``dim``.
65196531
prepend (Tensor|None, optional): The tensor to prepend to input along axis before computing the difference.
65206532
It's dimensions must be equivalent to that of x,
65216533
and its shapes must match x's shape except on axis.

python/paddle/tensor/random.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,14 @@ def multinomial(
457457
0. ``replacement`` indicates whether it is a replaceable sample. If ``replacement``
458458
is True, a category can be sampled more than once.
459459
460+
.. note::
461+
Alias Support: The parameter name ``input`` can be used as an alias for ``x``.
462+
For example, ``multinomial(input=tensor_x, ...)`` is equivalent to ``multinomial(x=tensor_x, ...)``.
463+
460464
Args:
461465
x(Tensor): A tensor with probabilities for generating the random number. The data type
462466
should be float32, float64.
467+
alias: ``input``.
463468
num_samples(int, optional): Number of samples, default is 1.
464469
replacement(bool, optional): Whether it is a replaceable sample, default is False.
465470
name(str|None, optional): The default value is None. Normally there is no
@@ -1967,9 +1972,14 @@ def exponential_(
19671972
19681973
f(x) = \lambda e^{-\lambda x}
19691974
1975+
.. note::
1976+
Alias Support: The parameter name ``lambd`` can be used as an alias for ``lam``.
1977+
For example, ``exponential_(tensor_x, lambd=1.0, ...)`` is equivalent to ``exponential_(tensor_x, lam=1.0, ...)``.
1978+
19701979
Args:
19711980
x(Tensor): Input tensor. The data type should be float32, float64.
19721981
lam(float, optional): :math:`\lambda` parameter of Exponential Distribution. Default, 1.0.
1982+
alias: ``lambd``.
19731983
name(str|None, optional): The default value is None. Normally there is no
19741984
need for user to set this property. For more information, please
19751985
refer to :ref:`api_guide_Name`.

python/paddle/tensor/stat.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,15 @@ def var(
164164
"""
165165
Computes the variance of ``x`` along ``axis`` .
166166
167+
.. note::
168+
Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``dim`` can be used as an alias for ``axis``.
169+
For example, ``var(input=tensor_x, dim=1, ...)`` is equivalent to ``var(x=tensor_x, axis=1, ...)``.
170+
167171
Args:
168172
x (Tensor): The input Tensor with data type float16, float32, float64.
173+
alias: ``input``.
169174
axis (int|list|tuple|None, optional): The axis along which to perform variance calculations. ``axis`` should be int, list(int) or tuple(int).
175+
alias: ``dim``.
170176
171177
- 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`` .
172178
- 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(
506512
"""
507513
Compute the median along the specified axis.
508514
515+
.. note::
516+
Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``dim`` can be used as an alias for ``axis``.
517+
When an alias replacement occurs, the default parameter for mode setting is min instead of avg.
518+
For example, ``median(input=tensor_x, dim=1, ...)`` is equivalent to ``median(x=tensor_x, axis=1, ...)``.
519+
509520
Args:
510521
x (Tensor): The input Tensor, it's data type can be bfloat16, float16, float32, float64, int32, int64.
522+
alias: ``input``.
511523
axis (int|None, optional): The axis along which to perform median calculations ``axis`` should be int.
524+
alias: ``dim``.
512525
``axis`` should be in range [-D, D), where D is the dimensions of ``x`` .
513526
If ``axis`` is less than 0, it works the same way as :math:`axis + D`.
514527
If ``axis`` is None, median is calculated over all elements of ``x``. Default is None.
@@ -520,6 +533,7 @@ def median(
520533
mode (str, optional): Whether to use mean or min operation to calculate
521534
the median values when the input tensor has an even number of elements
522535
in the dimension ``axis``. Support 'avg' and 'min'. Default is 'avg'.
536+
When an alias replacement occurs, the default parameter for mode setting is min instead of avg.
523537
name (str|None, optional): Name for the operation (optional, default is None).
524538
For more information, please refer to :ref:`api_guide_Name`.
525539

python/paddle/utils/decorator_utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,17 @@ def process(
262262
return args, kwargs
263263

264264

265-
"""
265+
def view_decorator():
266+
"""
266267
Usage Example:
267268
paddle.view(x=tensor_x, shape_or_dtype=[-1, 1, 3], name=None)
268269
tensor_x.view(paddle.float32) -> paddle.view(tensor_x, paddle.float32)
269270
tensor_x.view(dtype=paddle.float32) -> paddle.view(tensor_x, dtype=paddle.float32)
270271
tensor_x.view([-1, 1, 3]) -> paddle.view(tensor_x, [-1, 1, 3])
271272
tensor_x.view(-1, 1, 3) -> paddle.view(tensor_x, -1, 1, 3)
272273
tensor_x.view(size=[-1, 1, 3]) -> paddle.view(tensor_x, size=[-1, 1, 3])
273-
"""
274-
274+
"""
275275

276-
def view_decorator():
277276
def decorator(func: Callable[_InputT, _RetT]) -> Callable[_InputT, _RetT]:
278277
@functools.wraps(func)
279278
def wrapper(*args: _InputT.args, **kwargs: _InputT.kwargs) -> _RetT:

0 commit comments

Comments
 (0)