Skip to content

Commit ed19196

Browse files
authored
[API Compatibility] add many api (PaddlePaddle#7411)
* update * update * update * update
1 parent 17c1aa7 commit ed19196

File tree

10 files changed

+149
-14
lines changed

10 files changed

+149
-14
lines changed

docs/api/paddle/Tensor_cn.rst

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,7 @@ index_put(indices, value, accumulate=False, name=None)
17771777

17781778
请参考 :ref:`cn_api_paddle_index_put`
17791779

1780-
repeat_interleave(repeats, axis=None, name=None)
1780+
repeat_interleave(repeats, axis=None, name=None, \*, output_size=None)
17811781
:::::::::
17821782

17831783
返回:计算后的 Tensor
@@ -2061,7 +2061,7 @@ max(axis=None, keepdim=False, name=None)
20612061

20622062
请参考 :ref:`cn_api_paddle_max`
20632063

2064-
amax(axis=None, keepdim=False, name=None)
2064+
amax(axis=None, keepdim=False, name=None, \*, out=None)
20652065
:::::::::
20662066

20672067
返回:计算后的 Tensor
@@ -2070,7 +2070,7 @@ amax(axis=None, keepdim=False, name=None)
20702070

20712071
请参考 :ref:`cn_api_paddle_amax`
20722072

2073-
maximum(y, axis=-1, name=None)
2073+
maximum(y, axis=-1, name=None, \*, out=None)
20742074
:::::::::
20752075

20762076
返回:计算后的 Tensor
@@ -2115,7 +2115,7 @@ min(axis=None, keepdim=False, name=None)
21152115

21162116
请参考 :ref:`cn_api_paddle_min`
21172117

2118-
amin(axis=None, keepdim=False, name=None)
2118+
amin(axis=None, keepdim=False, name=None, \*, out=None)
21192119
:::::::::
21202120

21212121
返回:计算后的 Tensor
@@ -2124,7 +2124,7 @@ amin(axis=None, keepdim=False, name=None)
21242124

21252125
请参考 :ref:`cn_api_paddle_amin`
21262126

2127-
minimum(y, axis=-1, name=None)
2127+
minimum(y, axis=-1, name=None, \*, out=None)
21282128
:::::::::
21292129

21302130
返回:计算后的 Tensor
@@ -2680,7 +2680,7 @@ vsplit(num_or_indices, name=None)
26802680

26812681
请参考 :ref:`cn_api_paddle_vsplit`
26822682

2683-
sqrt(name=None)
2683+
sqrt(name=None, \*, out=None)
26842684
:::::::::
26852685

26862686
返回:计算后的 Tensor
@@ -2808,6 +2808,22 @@ tile(repeat_times, name=None)
28082808

28092809
请参考 :ref:`cn_api_paddle_tile`
28102810

2811+
repeat(\*repeats, name=None)
2812+
:::::::::
2813+
2814+
沿着指定维度重复当前 Tensor。返回一个新的 Tensor,其形状为当前 Tensor 的形状与 sizes 的乘积。
2815+
2816+
参数:
2817+
- **repeats** (tuple|list|int) - 指定每个维度重复的次数。可以是单个整数,也可以是元组或列表。
2818+
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。
2819+
2820+
返回:重复后的 Tensor
2821+
2822+
返回类型:Tensor
2823+
2824+
**代码示例**
2825+
COPY-FROM: paddle.Tensor.repeat
2826+
28112827
to(*args, **kwargs)
28122828
:::::::::
28132829
@@ -2838,7 +2854,7 @@ tolist()
28382854

28392855
请参考 :ref:`cn_api_paddle_tolist`
28402856

2841-
topk(k, axis=None, largest=True, sorted=True, name=None)
2857+
topk(k, axis=None, largest=True, sorted=True, name=None, \*, out=None)
28422858
:::::::::
28432859

28442860
返回:计算后的 Tensor
@@ -2865,6 +2881,15 @@ transpose(perm, name=None)
28652881

28662882
请参考 :ref:`cn_api_paddle_transpose`
28672883

2884+
permute(dims, name=None)
2885+
:::::::::
2886+
2887+
返回:计算后的 Tensor
2888+
2889+
返回类型:Tensor
2890+
2891+
请参考 :ref:`cn_api_paddle_permute`
2892+
28682893
triangular_solve(b, upper=True, transpose=False, unitriangular=False, name=None)
28692894
:::::::::
28702895

docs/api/paddle/compat/Overview_cn.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ PyTorch 兼容函数
1919
" :ref:`softmax <cn_api_paddle_compat_softmax>` ", "softmax 函数"
2020
" :ref:`sort <cn_api_paddle_compat_sort>` ", "同时返回 values 及 indices 的排序"
2121
" :ref:`split <cn_api_paddle_compat_split>` ", "允许非整除块大小输入的 Tensor 轴向切分"
22+
" :ref:`median <cn_api_paddle_compat_median>` ", "兼容版中位数,支持 dim/keepdim/out 签名"
23+
" :ref:`nanmedian <cn_api_paddle_compat_nanmedian>` ", "忽略 NaN 的兼容版中位数,支持 dim/keepdim/out 签名"
2224

2325

2426
.. _about_compat_class:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.. _cn_api_paddle_compat_median:
2+
3+
median
4+
-------------------------------
5+
6+
.. py:function:: paddle.compat.median(input, dim=None, keepdim=False, *, out=None)
7+
8+
PyTorch 兼容的 :ref:`cn_api_paddle_median` 版本,提供完全一致的函数签名与行为:
9+
- 当 ``dim`` 为 ``None`` 时,返回所有元素的中位数。
10+
- 当 ``dim`` 指定维度时,返回该维度的中位数与对应索引。
11+
12+
.. note::
13+
此 API 遵循 ``torch.median`` 的函数签名和行为以实现 PyTorch 兼容。如需使用 Paddle 原生实现,请参考 :ref:`cn_api_paddle_median`。
14+
15+
参数
16+
::::::::::
17+
- **input** (Tensor) - 输入 N 维 Tensor,支持 bool、bfloat16、float16、float32、float64、int32、int64 数据类型。
18+
- **dim** (int,可选) - 指定计算中位数的维度。为 ``None`` 时计算全局中位数。默认 ``None``。
19+
- **keepdim** (bool,可选) - 是否保留被约简的维度。默认 ``False``。
20+
- **out** (tuple(Tensor, Tensor)|Tensor,可选) - 关键字参数。当指定 ``dim`` 时,可传入二元组 ``(values, indices)`` 用于原位写回中位数与索引;当未指定 ``dim`` 时,可传入单个 ``Tensor`` 用于写回标量结果。默认 ``None``。
21+
22+
返回
23+
::::::::::
24+
- 当 ``dim`` 为 ``None``:返回一个标量 ``Tensor``,为 ``input`` 的中位数。
25+
- 当 ``dim`` 指定:返回具名元组 ``(values, indices)``,分别是中位数与其索引。
26+
27+
代码示例
28+
::::::::::
29+
30+
COPY-FROM: paddle.compat.median
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.. _cn_api_paddle_compat_nanmedian:
2+
3+
nanmedian
4+
-------------------------------
5+
6+
.. py:function:: paddle.compat.nanmedian(input, *, dim=None, keepdim=False, *, out=None)
7+
8+
PyTorch 兼容的 :ref:`cn_api_paddle_nanmedian` 版本,提供完全一致的函数签名与行为:
9+
- 忽略 NaN 元素计算中位数。
10+
- 当 ``dim`` 为 ``None`` 时,返回所有非 NaN 元素的中位数;
11+
- 当 ``dim`` 指定维度时,返回该维度上非 NaN 元素的中位数与对应索引;若某个切片全为 NaN,则返回 NaN 和索引 0。
12+
13+
.. note::
14+
此 API 遵循 ``torch.nanmedian`` 的函数签名和行为以实现 PyTorch 兼容。如需使用 Paddle 原生实现,请参考 :ref:`cn_api_paddle_nanmedian`。
15+
16+
参数
17+
::::::::::
18+
- **input** (Tensor) - 输入 N 维 Tensor,支持 bfloat16、float16、float32、float64 数据类型。
19+
- **dim** (int,可选) - 指定计算中位数的维度。为 ``None`` 时计算全局中位数。默认 ``None``。
20+
- **keepdim** (bool,可选) - 是否保留被约简的维度。默认 ``False``。
21+
- **out** (tuple(Tensor, Tensor)|Tensor,可选) - 关键字参数。当指定 ``dim`` 时,可传入二元组 ``(values, indices)`` 用于原位写回中位数与索引;当未指定 ``dim`` 时,可传入单个 ``Tensor`` 用于写回标量结果。默认 ``None``。
22+
23+
返回
24+
::::::::::
25+
- 当 ``dim`` 为 ``None``:返回一个标量 ``Tensor``,为忽略 NaN 后的中位数。
26+
- 当 ``dim`` 指定:返回具名元组 ``(values, indices)``,分别是中位数与其索引。
27+
28+
代码示例
29+
::::::::::
30+
31+
COPY-FROM: paddle.compat.nanmedian

docs/api/paddle/maximum_cn.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
maximum
44
-------------------------------
55

6-
.. py:function:: paddle.maximum(x, y, name=None)
6+
.. py:function:: paddle.maximum(x, y, name=None, *, out=None)
77
88
99
逐元素对比输入的两个 Tensor,并且把各个位置更大的元素保存到返回结果中。
@@ -18,11 +18,16 @@ maximum
1818

1919
.. _Tensor 介绍: ../../guides/beginner/tensor_cn.html#id7
2020

21+
2122
参数
2223
:::::::::
23-
- **x** (Tensor)- 输入的 Tensor。数据类型为 ``bfloat16`` 、 ``float16`` 、 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64`` 。
24-
- **y** (Tensor)- 输入的 Tensor。数据类型为 ``bfloat16`` 、 ``float16`` 、 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64`` 。
24+
- **x** (Tensor)- 输入的 Tensor。数据类型为 ``bfloat16`` 、 ``float16`` 、 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64`` 。
25+
``别名: input``
26+
- **y** (Tensor) - 输入的 Tensor。数据类型为 ``bfloat16`` 、 ``float16`` 、 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64`` 。
27+
``别名: other``
2528
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。
29+
- **out** (Tensor,可选) - 关键字参数。输出 Tensor,用于存储计算结果。如果指定,则结果将写入此 Tensor 中。
30+
2631

2732
返回
2833
:::::::::

docs/api/paddle/minimum_cn.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
minimum
44
-------------------------------
55

6-
.. py:function:: paddle.minimum(x, y, name=None)
6+
.. py:function:: paddle.minimum(x, y, name=None, *, out=None)
77
88
99
逐元素对比输入的两个 Tensor,并且把各个位置更小的元素保存到返回结果中。
@@ -18,11 +18,15 @@ minimum
1818

1919
.. _Tensor 介绍: ../../guides/beginner/tensor_cn.html#id7
2020

21+
2122
参数
2223
:::::::::
2324
- **x** (Tensor) - 输入的 Tensor。数据类型为 ``bfloat16`` 、 ``float16`` 、 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64`` 。
25+
``别名: input``
2426
- **y** (Tensor) - 输入的 Tensor。数据类型为 ``bfloat16`` 、 ``float16`` 、 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64`` 。
27+
``别名: other``
2528
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。
29+
- **out** (Tensor,可选) - 关键字参数。输出 Tensor,用于存储计算结果。如果指定,则结果将写入此 Tensor 中。
2630

2731
返回
2832
:::::::::

docs/api/paddle/permute_cn.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.. _cn_api_paddle_permute:
2+
3+
permute
4+
-------------------------------
5+
6+
.. py:function:: paddle.permute(input, dims, name=None)
7+
8+
根据 dims 对输入的多维 Tensor 进行数据重排。返回多维 Tensor 的第 i 维对应输入 Tensor 的 dims[i] 维。
9+
10+
参数
11+
::::::::::::
12+
13+
- **input** (Tensor) - 输入:input:[N_1, N_2, ..., N_k, D]多维 Tensor,可选的数据类型为 bool, float16, bfloat16, float32, float64, int8, int16, int32, int64, uint8, uint16, complex64, complex128。
14+
- **dims** (list|tuple) - dims 长度必须和 input 的维度相同,并依照 dims 中的数据进行重排。
15+
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。
16+
17+
返回
18+
::::::::::::
19+
``Tensor``,经过 dims 指定顺序重排后的多维 Tensor,数据类型与输入一致,shape 为根据 dims 重新排列后的 shape。
20+
21+
22+
代码示例
23+
::::::::::::
24+
25+
COPY-FROM: paddle.permute

docs/api/paddle/repeat_interleave_cn.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
repeat_interleave
44
-------------------------------
55

6-
.. py:function:: paddle.repeat_interleave(x, repeats, axis=None, name=None)
6+
.. py:function:: paddle.repeat_interleave(x, repeats, axis=None, name=None, *, output_size=None)
77
沿着指定轴 ``axis`` 对输入 ``x`` 进行复制,创建并返回到一个新的 Tensor。当 ``repeats`` 为 ``1-D`` Tensor 时,``repeats`` 长度必须和指定轴 ``axis`` 维度一致,``repeats`` 对应位置的值表示 ``x`` 对应位置元素需要复制的次数。当 ``repeats`` 为 int 时,``x`` 沿指定轴 ``axis`` 上所有元素复制 ``repeats`` 次。
88

99

@@ -12,6 +12,9 @@ repeat_interleave
1212

1313
最终输出为二维张量 ``[[1, 1, 1, 2, 2, 3], [4, 4, 4, 5, 5, 6]]``。
1414

15+
.. note::
16+
别名支持: 参数名 ``input`` 可替代 ``x``, ``dim`` 可替代 ``axis``;
17+
1518
.. figure:: ../../images/api_legend/repeat_interleave.png
1619
:width: 500
1720
:alt: 示例一图示
@@ -28,6 +31,8 @@ repeat_interleave
2831
- **axis** (int,可选) – 指定对输入 ``x`` 进行运算的轴,若未指定,默认值为 None,使用输入 Tensor 的 flatten 形式。
2932
- **dim** - ``axis`` 的别名,行为完全一致。
3033
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。
34+
- **output_size** (int64,可选) – 关键字参数。输出 Tensor 的总大小,用于优化内存分配。若未指定,默认值为 None。
35+
3136

3237

3338
返回

docs/api/paddle/sqrt_cn.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
sqrt
44
-------------------------------
55

6-
.. py:function:: paddle.sqrt(x, name=None)
6+
.. py:function:: paddle.sqrt(x, name=None, *, out=None)
77
88
99
@@ -12,6 +12,9 @@ sqrt
1212

1313
.. math:: out=\sqrt x=x^{1/2}
1414

15+
.. note::
16+
别名支持: 参数名 ``input`` 可替代 ``x``;
17+
1518
.. note::
1619
请确保输入中的数值是非负数。
1720

@@ -20,7 +23,9 @@ sqrt
2023

2124

2225
- **x** (Tensor) - 支持任意维度的 Tensor。数据类型为 float16,float32,float64,complex64 或 complex128。
26+
``别名: input``
2327
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。
28+
- **out** (Tensor,可选) - 关键字参数。输出 Tensor,用于存储计算结果。如果指定,则结果将写入此 Tensor 中。
2429

2530
返回
2631
::::::::::::

docs/api/paddle/topk_cn.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
topk
44
-------------------------------
55

6-
.. py:function:: paddle.topk(x, k, axis=None, largest=True, sorted=True, name=None)
6+
.. py:function:: paddle.topk(x, k, axis=None, largest=True, sorted=True, name=None, *, out=None)
77
88
沿着可选的 ``axis`` 查找 topk 最大或者最小的结果和结果所在的索引信息。
99
如果是一维 Tensor,则直接返回 topk 查询的结果。如果是多维 Tensor,则在指定的轴上查询 topk 的结果。
1010

1111
参数
1212
:::::::::
1313
- **x** (Tensor) - 输入的多维 ``Tensor`` ,支持的数据类型:float32、float64、int32、int64。
14+
``别名: input``
1415
- **k** (int,Tensor) - 在指定的轴上进行 top 寻找的数量。
1516
- **axis** (int,可选) - 指定对输入 Tensor 进行运算的轴, ``axis`` 的有效范围是[-R, R),R 是输入 ``x`` 的 Rank, ``axis`` 为负时与 ``axis`` + R 等价。默认值为-1。
17+
``别名: dim``
1618
- **largest** (bool,可选) - 指定算法排序的方向。如果设置为 True,排序算法按照降序的算法排序,否则按照升序排序。默认值为 True。
1719
- **sorted** (bool,可选) - 控制返回的结果是否按照有序返回,默认为 True。
1820
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。
21+
- **out** (tuple,可选) - 关键字参数。输出元组,用于存储计算结果和索引。如果指定,则结果将写入此元组中。
1922

2023
返回
2124
:::::::::

0 commit comments

Comments
 (0)