Skip to content

Commit

Permalink
映射文档 No. 2 (#5702)
Browse files Browse the repository at this point in the history
* add task 2

* update conversion

* fix conversation
  • Loading branch information
DrRyanHuang authored Mar 21, 2023
1 parent b1b1677 commit 3f9af5f
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 0 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## [ 无参数 ] torch.Tensor.T

### [torch.Tensor.T](https://pytorch.org/docs/stable/tensors.html#torch.Tensor.T)

```python
torch.Tensor.T
```

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

```python
paddle.Tensor.T
```

两者功能一致,均无参数。
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## [ 无参数 ] torch.Tensor.device

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

```python
torch.Tensor.device
```

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

```python
paddle.Tensor.place
```

两者功能一致,均无参数,都用来查看一个 Tensor 的设备位置。
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## [ 无参数 ] torch.Tensor.grad

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

```python
torch.Tensor.grad
```

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

```python
paddle.Tensor.grad
```

两者功能一致,均无参数,都用来查看一个 Tensor 的梯度。
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## [ 无参数 ] torch.Tensor.imag

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

```python
torch.Tensor.imag
```

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

```python
paddle.Tensor.imag
```

两者功能一致,均无参数,用于返回原复数 Tensor 的虚部数值。
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## [ 无参数 ] torch.Tensor.is_leaf

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

```python
torch.Tensor.is_leaf
```

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

```python
paddle.Tensor.is_leaf
```

两者功能一致,均无参数,判断 Tensor 是否为叶子 Tensor。
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## [ 无参数 ] torch.Tensor.is_sparse

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

```python
torch.Tensor.is_sparse
```

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

```python
paddle.Tensor.is_sparse()
```

两者功能一致,但使用方式不一致,前者可以直接访问属性,后者需要调用方法,具体如下:

### 转写示例
```
# torch 版本可以直接访问属性
# x = torch.rand(3)
# print(x.is_sparse)
# Paddle 版本需要调用
x = paddle.rand([3])
print(x.is_sparse())
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## [ 无参数 ] torch.Tensor.ndim

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

```python
torch.Tensor.ndim
```

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

```python
paddle.Tensor.ndim
```

两者功能一致,均无参数,查看一个 Tensor 的维度。
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## [ 无参数 ] torch.Tensor.real

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

```python
torch.Tensor.real
```

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

```python
paddle.Tensor.real
```

两者功能一致,均无参数,用于返回 Tensor 的实部数值。
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## [ 无参数 ] torch.Tensor.shape

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

```python
torch.Tensor.shape
```

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

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

两者功能一致,均无参数,都用来查看一个 Tensor 的 shape,shape 是 Tensor 的一个重要的概念,其描述了 tensor 在每个维度上的元素数量。
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## [ 仅参数名不一致 ] torch.nn.functional.affine_grid

### [torch.nn.functional.affine_grid](https://pytorch.org/docs/stable/generated/torch.nn.functional.affine_grid.html?highlight=affine_grid#torch.nn.functional.affine_grid)

```python
torch.nn.functional.affine_grid(theta,
size,
align_corners=None)
```

### [paddle.nn.functional.affine_grid](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/affine_grid_cn.html)

```python
paddle.nn.functional.affine_grid(theta,
out_shape,
align_corners=True,
name=None)
```

两者功能一致,仅参数名不一致,具体如下:
### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| theta | theta | 指定仿射变换矩阵 |
| size | out_shape | 表示指定目标输出图像大小,仅参数名不一致。 |
| align_corners | align_corners | 指定是否是像素中心对齐 |

0 comments on commit 3f9af5f

Please sign in to comment.