Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

映射文档 No.61 #5902

Merged
merged 4 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## [torch 参数更多]torch.Tensor.quantile

### [torch.Tensor.quantile](https://pytorch.org/docs/1.13/generated/torch.Tensor.quantile.html#torch.Tensor.quantile)

```python
torch.Tensor.quantile(q, dim=None, keepdim=False, *, interpolation='linear')
```

### [paddle.Tensor.quantile](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#quantile-q-axis-none-keepdim-false-name-none)

```python
paddle.Tensor.quantile(q, axis=None, keepdim=False, name=None)
```

其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:

### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | ------------------------ |
| q | q |待计算的分位数。 |
| dim | axis |指定对 x 进行计算的轴,仅参数名不一致。|
| keepdim | keepdim |是否在输出 Tensor 中保留减小的维度。|
| interpolation | - |两个数据点的插补取值方法,Paddle 无此功能,暂无转写方式。|
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## [torch 参数更多]torch.Tensor.round

### [torch.Tensor.round](https://pytorch.org/docs/1.13/generated/torch.Tensor.round.html#torch.Tensor.round)

```python
torch.Tensor.round(decimals=0)
```

### [paddle.Tensor.round](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#round-name-none)

```python
paddle.Tensor.round(name=None)
```

其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:

### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| -------- | ------- | ------- |
| decimals | - | 舍入小数位数 |

### 转写示例
#### decimals:要舍入到的小数位数
```python
# Pytorch 写法
torch.tensor([3.345, 5.774]).round(decimals=2)

# Paddle 写法
(paddle.to_tensor([3.345, 5.774]) * 1e2).round() / 1e2

# 注:Paddle 可使用 10 的 decimals 次方来实现
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## [torch 参数更多]torch.Tensor.round_

### [torch.Tensor.round_](https://pytorch.org/docs/1.13/generated/torch.Tensor.round_.html#torch.Tensor.round_)

```python
torch.Tensor.round_(decimals=0)
```

### [paddle.Tensor.round_](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#round-name-none)

```python
paddle.Tensor.round_(name=None)
```

其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:

### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| -------- | ------- | ------- |
| decimals | - | 舍入小数位数 |

### 转写示例
#### decimals:要舍入到的小数位数
```python
# Pytorch 写法
torch.tensor([3.345, 5.774]).round_(decimals=2)

# Paddle 写法
(paddle.to_tensor([3.345, 5.774]) * 1e2).round_() / 1e2

# 注:Paddle 可使用 10 的 decimals 次方来实现
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

另起一行加一个代码块的符号吧 ```

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## [仅 paddle 参数更多]torch.Tensor.scatter

### [torch.Tensor.scatter](https://pytorch.org/docs/1.13/generated/torch.Tensor.scatter.html#torch.Tensor.scatter)

```python
torch.Tensor.scatter(dim, index, src)
```

### [paddle.Tensor.put_along_axis](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#put-along-axis-arr-index-value-axis-reduce-assign)

```python
paddle.Tensor.put_along_axis(index, value, axis, reduce="assign")

```

其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下:

### 参数映射
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以写一下 arr 参数应该如何设置呢

Copy link
Contributor Author

@co63oc co63oc May 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试Tensor.put_along_axis 不使用arr参数
图片
已修改API文档 #5910

| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | ------- |
| dim | axis | 表示在哪一个维度 scatter ,仅参数名不一致。 |
| index | index | 表示输入的索引张量,仅参数名不一致。 |
| src | value | 表示需要插入的值,仅参数名不一致。 |
| - | reduce | 归约操作类型,PyTorch 无此参数, Paddle 保持默认即可。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## [仅 paddle 参数更多]torch.Tensor.scatter_add

### [torch.Tensor.scatter_add](https://pytorch.org/docs/1.13/generated/torch.Tensor.scatter_add.html#torch.Tensor.scatter_add)

```python
torch.Tensor.scatter_add(dim, index, src)
```

### [paddle.Tensor.put_along_axis](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#put-along-axis-arr-index-value-axis-reduce-assign)

```python
paddle.Tensor.put_along_axis(index, value, axis, reduce="assign")
co63oc marked this conversation as resolved.
Show resolved Hide resolved

```

其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下:

### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | ------- |
| dim | axis | 表示在哪一个维度 scatter ,仅参数名不一致。 |
| index | index | 表示输入的索引张量,仅参数名不一致。 |
| src | value | 表示需要插入的值,仅参数名不一致。 |
| - | reduce | 归约操作类型,PyTorch 无此参数, Paddle 保持默认即可。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## [torch 参数更多]torch.Tensor.short

### [torch.Tensor.short](https://pytorch.org/docs/1.13/generated/torch.Tensor.short.html#torch.Tensor.short)

```python
torch.Tensor.short(memory_format=torch.preserve_format)
```

### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#put-along-axis-arr-index-value-axis-reduce-assign)

```python
paddle.Tensor.astype('int16')
```

其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:

### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------- | ------- | ------- |
| memory_format | - |表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## [torch 参数更多]torch.Tensor.size

### [torch.Tensor.size](https://pytorch.org/docs/1.13/generated/torch.Tensor.size.html#torch.Tensor.size)

```python
torch.Tensor.size(dim=None)
```

### [paddle.Tensor.shape](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#shape)

```python
paddle.Tensor.shape
```

其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:

### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | ------- |
| dim | - | 表示获取大小的轴,Paddle 无此参数,需要进行转写。 |

### 转写示例

```python
# Pytorch 写法
torch.tensor([-1, -2, 3]).size(0)

# Paddle 写法
paddle.to_tensor([-0.4, -0.2, 0.1, 0.3]).shape[0]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## [torch 参数更多]torch.Tensor.stft

### [torch.Tensor.stft](https://pytorch.org/docs/1.13/generated/torch.Tensor.stft.html#torch.Tensor.stft)

```python
torch.Tensor.stft(n_fft, hop_length=None, win_length=None, window=None, center=True, pad_mode='reflect', normalized=False, onesided=None, return_complex=None)
```

### [paddle.signal.stft](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/signal/stft_cn.html)

```python
paddle.signal.stft(x, n_fft, hop_length=None, win_length=None, window=None, center=True, pad_mode='reflect', normalized=False, onesided=True, name=None)
```

其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:

### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ---------- | ------------ | ------- |
| n_fft | n_fft | 离散傅里叶变换的样本点个数。 |
| hop_length | hop_length | 对输入分帧时,相邻两帧偏移的样本点个数。 |
| win_length | win_length | 信号窗的长度。 |
| window | window | 维度为 1D 长度为 win_length 的 Tensor。 |
| center | center | 选择是否将输入信号进行补长。 |
| pad_mode | pad_mode | 当 center 为 True 时,确定 padding 的模式。 |
| normalized | normalized | 是否将傅里叶变换的结果乘以值为 1/sqrt(n) 的缩放系数。 |
| onesided | onesided | 当输入为实信号时,选择是否只返回傅里叶变换结果的一半的频点值。 |
| return_complex | - | 表示当输入为复数时,是否以复数形式返回,还是将实部与虚部分开以实数形式返回。Paddle 目前只支持返回复数,分开返回实部与虚部的情况,需要使用 as_real 进行转写。 |

### 转写示例
#### return_complex:是否返回复数
```python
# Pytorch 写法
y = torch.rand(512,512).stft(n_fft=512, return_complex=False)

# Paddle 写法
y = paddle.as_real(paddle.signal.stft(paddle.rand((512,512)), n_fft=512))
```