-
Notifications
You must be signed in to change notification settings - Fork 744
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
【Hackathon 5th No.33】为 Paddle 新增 atleast_1d / atleast_2d / atleast_3d API #6317
Changes from all commits
4bb8da3
dff577b
9509523
47e76f2
bb172f9
5826df2
7de1ef9
38cd108
48c671e
02b45cb
a05cbe9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.. _cn_api_paddle_atleast_1d: | ||
|
||
atleast_1d | ||
------------------------------- | ||
|
||
.. py:function:: paddle.atleast_1d(*inputs, name=None) | ||
|
||
将输入转换为张量并返回至少为 ``1`` 维的视图。标量输入会被转换, ``1`` 维或更高维的输入则会被保留。 | ||
|
||
参数 | ||
:::::::::::: | ||
|
||
- **inputs** (Tensor|list(Tensor)) - 一个或多个 Tensor,数据类型为: ``float16``, ``float32``, ``float64``, ``int16``, ``int32``, ``int64``, ``int8``, ``uint8``, ``complex64``, ``complex128``, ``bfloat16`` 或 ``bool``。 | ||
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。 | ||
|
||
返回 | ||
:::::::::::: | ||
Tensor 或者由 Tensor 组成的 list。当只有一个输入的时候返回一个 Tensor,当有多个输入的时候返回由 Tensor 组成的 list。 | ||
|
||
代码示例 | ||
:::::::::::: | ||
|
||
COPY-FROM: paddle.atleast_1d |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.. _cn_api_paddle_atleast_2d: | ||
|
||
atleast_2d | ||
------------------------------- | ||
|
||
.. py:function:: paddle.atleast_2d(*inputs, name=None) | ||
|
||
将输入转换为张量并返回至少为 ``2`` 维的视图。 ``2`` 维或更高维的输入会被保留。 | ||
|
||
参数 | ||
:::::::::::: | ||
|
||
- **inputs** (Tensor|list(Tensor)) - 一个或多个 Tensor,数据类型为: ``float16``, ``float32``, ``float64``, ``int16``, ``int32``, ``int64``, ``int8``, ``uint8``, ``complex64``, ``complex128``, ``bfloat16`` 或 ``bool``。 | ||
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。 | ||
|
||
返回 | ||
:::::::::::: | ||
Tensor 或者由 Tensor 组成的 list。当只有一个输入的时候返回一个 Tensor,当有多个输入的时候返回由 Tensor 组成的 list。 | ||
|
||
代码示例 | ||
:::::::::::: | ||
|
||
COPY-FROM: paddle.atleast_2d |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.. _cn_api_paddle_atleast_3d: | ||
|
||
atleast_3d | ||
------------------------------- | ||
|
||
.. py:function:: paddle.atleast_3d(*inputs, name=None) | ||
|
||
将输入转换为张量并返回至少为 ``3`` 维的视图。 ``3`` 维或更高维的输入会被保留。 | ||
|
||
参数 | ||
:::::::::::: | ||
|
||
- **inputs** (Tensor|list(Tensor)) - 一个或多个 Tensor,数据类型为: ``float16``, ``float32``, ``float64``, ``int16``, ``int32``, ``int64``, ``int8``, ``uint8``, ``complex64``, ``complex128``, ``bfloat16`` 或 ``bool``。 | ||
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。 | ||
|
||
返回 | ||
:::::::::::: | ||
Tensor 或者由 Tensor 组成的 list。当只有一个输入的时候返回一个 Tensor,当有多个输入的时候返回由 Tensor 组成的 list。 | ||
|
||
代码示例 | ||
:::::::::::: | ||
|
||
COPY-FROM: paddle.atleast_3d |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## [ 参数不一致 ]torch.atleast_1d | ||
|
||
### [torch.atleast_1d](https://pytorch.org/docs/stable/generated/torch.atleast_1d.html#torch-atleast-1d) | ||
|
||
```python | ||
torch.atleast_1d(*tensors) | ||
``` | ||
|
||
### [paddle.atleast_1d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/atleast_1d_cn.html#atleast_1d) | ||
|
||
```python | ||
paddle.atleast_1d(*inputs, name=None) | ||
``` | ||
|
||
PyTorch 与 Paddle 参数不一致,具体如下: | ||
|
||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| <font color='red'> tensors </font> | <font color='red'> inputs </font> | 输入的 Tensor,仅当 torch 输入为 tuple(Tensor)时,两者处理方式不一致,需要转写。其他情形下均一致。 | | ||
|
||
PyTorch 与 Paddle 功能一致,但对于由多个 Tensor 组成 tuple|list 输入的处理方式略有不同,具体请看转写示例。 | ||
|
||
### 转写示例 | ||
|
||
#### tensors: 输入为 tuple(Tensor)时 | ||
|
||
```python | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此行上面加一个: ####tensors: 输入为tuple(Tensor)时 然后只需要下面这两行代码,其他均删掉,转写示例 只写有差异的case,其他默认就相同 无需示例 |
||
# Pytorch 写法 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 写不一致的case就行,这里写伪代码,不用写多了 |
||
torch.atleast_1d((x, y)) | ||
|
||
# Paddle 写法 | ||
paddle.atleast_1d(x, y) | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## [ 参数不一致 ]torch.atleast_2d | ||
|
||
### [torch.atleast_2d](https://pytorch.org/docs/stable/generated/torch.atleast_2d.html#torch-atleast-2d) | ||
|
||
```python | ||
torch.atleast_2d(*tensors) | ||
``` | ||
|
||
### [paddle.atleast_2d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/atleast_2d_cn.html#atleast_2d) | ||
|
||
```python | ||
paddle.atleast_2d(*inputs, name=None) | ||
``` | ||
|
||
PyTorch 与 Paddle 参数不一致,具体如下: | ||
|
||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| <font color='red'> tensors </font> | <font color='red'> inputs </font> | 输入的 Tensor,仅当 torch 输入为 tuple(Tensor)时,两者处理方式不一致,需要转写。其他情形下均一致。 | | ||
|
||
PyTorch 与 Paddle 功能一致,但对于由多个 Tensor 组成 tuple|list 输入的处理方式略有不同,具体请看转写示例。 | ||
|
||
### 转写示例 | ||
|
||
#### tensors: 输入为 tuple(Tensor)时 | ||
|
||
```python | ||
# Pytorch 写法 | ||
torch.atleast_2d((x, y)) | ||
|
||
# Paddle 写法 | ||
paddle.atleast_2d(x, y) | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## [ 参数不一致 ]torch.atleast_3d | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个算 仅参数不一致 嘛,还是 参数不一致,不确定捏,孙师傅快来 @sunzhongkai588 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 嗯 很纠结 不知道该咋写 😂 ~~~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@zhwesky2010 麻烦看一下, |
||
|
||
### [torch.atleast_3d](https://pytorch.org/docs/stable/generated/torch.atleast_3d.html#torch-atleast-3d) | ||
|
||
```python | ||
torch.atleast_3d(*tensors) | ||
``` | ||
|
||
### [paddle.atleast_3d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/atleast_3d_cn.html#atleast_3d) | ||
|
||
```python | ||
paddle.atleast_3d(*inputs, name=None) | ||
``` | ||
|
||
PyTorch 与 Paddle 参数不一致,具体如下: | ||
|
||
### 参数映射 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同上 |
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| <font color='red'> tensors </font> | <font color='red'> inputs </font> | 输入的 Tensor,仅当 torch 输入为 tuple(Tensor)时,两者处理方式不一致,需要转写。其他情形下均一致。 | | ||
|
||
PyTorch 与 Paddle 功能一致,但对于由多个 Tensor 组成 tuple|list 输入的处理方式略有不同,具体请看转写示例。 | ||
|
||
### 转写示例 | ||
|
||
#### tensors: 输入为 tuple(Tensor)时 | ||
|
||
```python | ||
# Pytorch 写法 | ||
torch.atleast_3d((x, y)) | ||
|
||
# Paddle 写法 | ||
paddle.atleast_3d(x, y) | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有个疑问,这种多输入的Tensor,为什么会有类成员函数