-
Notifications
You must be signed in to change notification settings - Fork 766
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
【Hackathon 5th No.26】为 Paddle 新增 diagonal_scatter API (#6289)
* add diagonal scatter docs * update * fix: name * Update docs/api/paddle/diagonal_scatter_cn.rst Co-authored-by: ooo oo <[email protected]> * fix review suggestions * update * update * add difference compare --------- Co-authored-by: ooo oo <[email protected]>
- Loading branch information
1 parent
ab84306
commit f03f205
Showing
7 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -278,3 +278,4 @@ Methods | |
vander | ||
hypot | ||
hypot_ | ||
diagonal_scatter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.. _cn_api_paddle_diagonal_scatter: | ||
|
||
diagonal_scatter | ||
------------------------------- | ||
|
||
.. py:function:: paddle.diagonal_scatter(x, y, offset=0, axis1=0, axis2=1, name=None) | ||
根据参数 ``offset``、``axis1``、``axis2``,将张量 ``y`` 填充到张量 ``x`` 的对应位置。 | ||
|
||
这个函数将会返回一个新的 ``Tensor``。 | ||
|
||
参数 ``offset`` 确定从指定的二维平面中获取对角线的位置: | ||
|
||
- 如果 offset = 0,则嵌入主对角线。 | ||
- 如果 offset > 0,则嵌入主对角线右上的对角线。 | ||
- 如果 offset < 0,则嵌入主对角线左下的对角线。 | ||
|
||
参数 | ||
:::::::::::: | ||
|
||
- **x** (Tensor) - 输入张量,张量的维度至少为 2 维,支持 float16、float32、float64、bfloat16、uint8、int8、int16、int32、int64、bool、complex64、complex128 数据类型。 | ||
- **y** (Tensor) - 嵌入张量,将会被嵌入到输入张量中,支持 float16、float32、float64、bfloat16、uint8、int8、int16、int32、int64、bool、complex64、complex128 数据类型。 | ||
- **offset** (int, 可选) - 从指定的二维平面嵌入对角线的位置,默认值为 0,即主对角线。 | ||
- **axis1** (int, 可选) - 对角线的第一个维度,默认值为 0。 | ||
- **axis2** (int, 可选) - 对角线的第二个维度,默认值为 1。 | ||
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。 | ||
|
||
返回 | ||
:::::::::::: | ||
``Tensor``,返回一个根据给定的轴 ``axis`` 和偏移量 ``offset``,将张量 ``y`` 填充到张量 ``x`` 对应位置的新 ``Tensor``。 | ||
|
||
|
||
代码示例 | ||
:::::::::::: | ||
|
||
COPY-FROM: paddle.diagonal_scatter |
25 changes: 25 additions & 0 deletions
25
...ert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diagonal_scatter.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
## [ 仅参数名不一致 ] torch.Tensor.diagonal_scatter | ||
|
||
### [torch.Tensor.diagonal_scatter](https://pytorch.org/docs/stable/generated/torch.Tensor.diagonal_scatter.html?highlight=diagonal_scatter#torch.Tensor.diagonal_scatter) | ||
|
||
```python | ||
torch.Tensor.diagonal_scatter(input, src, offset=0, dim1=0, dim2=1) | ||
``` | ||
|
||
### [paddle.Tensor.diagonal_scatter](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#diagonal-scatter-x-y-offset-0-axis1-0-axis2-1-name-none) | ||
|
||
```python | ||
paddle.Tensor.diagonal_scatter(x, y, offset=0, axis1=0, axis2=1) | ||
``` | ||
|
||
两者功能一致且参数用法一致,仅参数名不一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
|---------|--------------| -------------------------------------------------- | | ||
| input | x | 输入张量,被嵌入的张量,仅参数名不一致。 | | ||
| src | y | 用于嵌入的张量,仅参数名不一致。 | | ||
| offset | offset | 从指定的二维平面嵌入对角线的位置,默认值为 0,即主对角线。 | | ||
| dim1 | axis1 | 对角线的第一个维度,默认值为 0,仅参数名不一致。 | | ||
| dim2 | axis2 | 对角线的第二个维度,默认值为 1,仅参数名不一致。 | |
33 changes: 33 additions & 0 deletions
33
...model_convert/convert_from_pytorch/api_difference/ops/torch.diagonal_scatter.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
## [ 仅参数名不一致 ] torch.diagonal_scatter | ||
|
||
### [torch.diagonal_scatter](https://pytorch.org/docs/stable/generated/torch.diagonal_scatter.html?highlight=diagonal_scatter#torch.diagonal_scatter) | ||
|
||
```python | ||
torch.diagonal_scatter(input, | ||
src, | ||
offset=0, | ||
dim1=0, | ||
dim2=1) | ||
``` | ||
|
||
### [paddle.diagonal_scatter](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/diagonal_scatter_cn.html) | ||
|
||
```python | ||
paddle.diagonal_scatter(x, | ||
y, | ||
offset=0, | ||
axis1=0, | ||
axis2=1) | ||
``` | ||
|
||
两者功能一致且参数用法一致,仅参数名不一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
|---------|--------------| -------------------------------------------------- | | ||
| <font color='red'> input </font> | <font color='red'> x </font> | 输入张量,被嵌入的张量,仅参数名不一致。 | | ||
| <font color='red'> src </font> | <font color='red'> y </font> | 用于嵌入的张量,仅参数名不一致。 | | ||
| <font color='red'> offset </font> | <font color='red'> offset </font> | 从指定的二维平面嵌入对角线的位置,默认值为 0,即主对角线。 | | ||
| <font color='red'> dim1 </font> | <font color='red'> axis1 </font> | 对角线的第一个维度,默认值为 0,仅参数名不一致。 | | ||
| <font color='red'> dim2 </font> | <font color='red'> axis2 </font> | 对角线的第二个维度,默认值为 1,仅参数名不一致。 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters