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

【PaddlePaddle Hackathon 4 No.17】为 Paddle 新增 cummax / cummin API #401

Merged
merged 7 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 7 additions & 6 deletions rfcs/APIs/20220316_api_design_for_cummax.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# paddle.[tensor.]cummax 设计文档
# paddle.[Tensor.]cummax 设计文档

| API名称 | paddle.[Tensor.]cummax |
| ------------------------------------------------------------ | ----------------------------------- |
Expand All @@ -12,7 +12,7 @@

## 1、相关背景

cummax 是指求累积最大值(cumulative max)的功能。即求
cummax函数的功能为求累积最小值(cumulative max)。对于输入向量/矩阵,第i个位置的计算方式为:
$$
y_i = \max(x_1, x_2, x_3, \cdots , x_i)
$$
Expand Down Expand Up @@ -268,20 +268,21 @@ PyTorch 还提供了基于 CUDA 的算子实现。

## 命名与参数设计

API设计为`paddle.cummax(x, axis, name)`以及`paddle.tensor.cummax(axis, name)`。
API设计为`paddle.cummax(x, axis, name)`以及`paddle.Tensor.cummax(axis, name)`。

paddle.cummax
----------------------
参数
:::::::::
- x (Tensor) - 累积最大值的输入,需要进行累积最大值操作的 Tensor。
- axis (int, 可选) - 指明需要统计的维度。-1代表最后一维。默认:None,将输入展开为一维变量再进行累加计算。
- axis (int, 可选) - 指明需要统计的维度。-1代表最后一维。默认:None,将输入展开为一维变量再进行累积最大值计算。
- dtype (str,可选) - 指定输出索引的数据类型,可以为int32和int64,默认:int64。
- name (str,可选) - 具体用法请参见 [Name](https://www.paddlepaddle.org.cn/documentation/docs/zh/api_guides/low_level/program.html#api-guide-name),一般无需设置,默认值为 None。
返回
:::::::::
- Out (tuple) - 返回累积最大值结果和对应的索引信息。结果的数据类型和输入`x`一致。索引的数据类型是 int64
- Out (tuple) - 返回累积最大值结果和对应的索引信息。累积最大值结果的数据类型和输入`x`一致。

paddle.tensor.cummax指向paddle.cummax,两者是相同的API
paddle.Tensor.cummax指向paddle.cummax,两者是相同的API

## 底层OP设计

Expand Down
17 changes: 9 additions & 8 deletions rfcs/APIs/20230302_api_design_for_cummin.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# paddle.[tensor.]cummin 设计文档
# paddle.[Tensor.]cummin 设计文档

| API名称 | paddle.[Tensor.]cummin |
| ------------------------------------------------------------ | ----------------------------------- |
Expand All @@ -12,7 +12,7 @@

## 1、相关背景

cummin 是指求累积最小值(cumulative min)的功能。即求
cummin函数的功能为求累积最小值(cumulative min)。对于输入向量/矩阵,第i个位置的计算方式为:
$$
y_i = \min(x_1, x_2, x_3, \cdots , x_i)
$$
Expand All @@ -21,7 +21,7 @@ PyTorch、NumPy 和 Pandas 提供了相似算子。

## 2、功能目标

cummin API 是一个按轴寻找累计最大值和最大值所在位置的 API。此任务的目标是在 Paddle 框架中,新增 cummin API,调用路径为:`paddle.cummin`和 `paddle.tensor.cummin`。
cummin API 是一个按轴寻找累计最大值和最大值所在位置的 API。此任务的目标是在 Paddle 框架中,新增 cummin API,调用路径为:`paddle.cummin`和 `paddle.Tensor.cummin`。
Copy link
Contributor

Choose a reason for hiding this comment

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

这里不对

Copy link
Contributor

Choose a reason for hiding this comment

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

不应该是寻找最大值

## 3、意义

完善矩阵运算的基本功能,增强统计运算完善度。
Expand Down Expand Up @@ -265,20 +265,21 @@ PyTorch 还提供了基于 CUDA 的算子实现。

## 命名与参数设计

API设计为`paddle.cummin(x, axis, name)`以及`paddle.tensor.cummin(axis, name)`。
API设计为`paddle.cummin(x, axis, name)`以及`paddle.Tensor.cummin(axis, name)`。
Copy link
Contributor

Choose a reason for hiding this comment

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

这里也要补上dtype


paddle.cummin
----------------------
参数
:::::::::
- x (Tensor) - 累积最小值的输入,需要进行累积最小值操作的 Tensor。
- axis (int, 可选) - 指明需要统计的维度。-1代表最后一维。默认:None,将输入展开为一维变量再进行累加计算。
- name (str,可选) - 具体用法请参见 [Name](https://www.paddlepaddle.org.cn/documentation/docs/zh/api_guides/low_level/program.html#api-guide-name),一般无需设置,默认值为 None。
- axis (int, 可选) - 指明需要统计的维度。-1代表最后一维。默认:None,将输入展开为一维变量再进行累积最小值计算。
- dtype (str,可选) - 指定输出索引的数据类型,可以为int32和int64,默认:int64。
- name (str,可选) - 具体用法请参见 [Name](https://www.paddlepaddle.org.cn/documentation/docs/zh/api_guides/low_level/program.html#api-guide-name),一般无需设置,默认值为 None。
返回
Copy link
Contributor

Choose a reason for hiding this comment

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

返回索引的api,需要对索引的dtype进行限制,增加一个索引输出的dtype参数吧
具体可参照这里的数据类型规范 https://www.paddlepaddle.org.cn/documentation/docs/zh/dev_guides/api_contributing_guides/api_design_guidelines_standard_cn.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

:::::::::
- Out (tuple) - 返回累积最小值结果和对应的索引信息。结果的数据类型和输入`x`一致。索引的数据类型是 int64
- Out (tuple) - 返回累积最小值结果和对应的索引信息。累积最小值结果的数据类型和输入`x`一致。

paddle.tensor.cummin指向paddle.cummin,两者是相同的API
paddle.Tensor.cummin指向paddle.cummin,两者是相同的API

Copy link
Contributor

Choose a reason for hiding this comment

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

写明返回值;以写中文文档形式写这里的命名以及参数设计

Copy link
Contributor

Choose a reason for hiding this comment

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

且返回值中有标的api,需要提供dtype参数,限制返回的下标数据类型(int32, int64),默认为int64 具体参考 https://www.paddlepaddle.org.cn/documentation/docs/zh/dev_guides/api_contributing_guides/api_design_guidelines_standard_cn.html API命名与设计规范

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

## 底层OP设计

Expand Down