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 第四期】No.6:为 Paddle 新增 ldexp API #407

Merged
merged 7 commits into from
Mar 8, 2023

Conversation

longranger2
Copy link
Contributor

【PaddlePaddle Hackathon 第四期】No.6:为 Paddle 新增 ldexp API

@paddle-bot
Copy link

paddle-bot bot commented Mar 2, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请检查PR提交格式和内容是否完备,具体请参考示例模版
Your PR has been submitted. Thanks for your contribution!
Please check its format and content. For this, you can refer to Template and Demo.

@@ -0,0 +1,169 @@
# paddle.ldexp 设计文档

|API名称 | paddle.Idexp |
Copy link
Collaborator

Choose a reason for hiding this comment

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

是小写的L,不是大写的i
image
全文都得改一下,包括文件名

任务 Issue: [No.6:为 Paddle 新增 ldexp API](https://github.com/PaddlePaddle/Paddle/issues/50630#task6)

## 2、功能目标
增加API `paddle.ldexp` 和 `paddle.Tensor.ldexp`,实现 `ldexp(double x, int exponent)`函数,函数返回 x 乘以 2 的 exponent 次幂
Copy link
Collaborator

@luotao1 luotao1 Mar 3, 2023

Choose a reason for hiding this comment

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

实现 ldexp(double x, int exponent)函数,

下面参数设计里写的是,请对齐

paddle.ldexp(
    input: Tensor,
    other: Tensor
)

1. 使用`paddle.exp`对输入exponent,进行以自然数 e 为底指数运算
2. 将步骤1得到的值乘以x即可

但在实际实现时,不能完全直接复用上述方案,理由如下:
Copy link
Collaborator

Choose a reason for hiding this comment

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

将步骤1得到的值乘以x即可

这个对么,paddle.exp是e为底,paddle.ldexp是2为底

paddle.ldexp(
input: Tensor,
other: Tensor
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

需要写一下input和other的数据类型


## 七、可行性分析及规划排期
具体规划:
- 阶段一:完成API功能开放
Copy link
Collaborator

Choose a reason for hiding this comment

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

开放-》开发

@longranger2
Copy link
Contributor Author

longranger2 commented Mar 3, 2023

@luotao1 修改好了~,辛苦review下


# 五、设计思路与实现方案

## 命名与参数设计
添加 API
```python
paddle.ldexp(
input: Tensor,
other: Tensor
input: 多纬Tensor,数据类型为 float16 、 float32 、 float64 、 int32 或 int64
Copy link
Collaborator

Choose a reason for hiding this comment

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

多纬-》多维

Copy link
Contributor Author

Choose a reason for hiding this comment

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

修改好了~

@longranger2 longranger2 requested a review from luotao1 March 7, 2023 06:26
任务 Issue: [No.6:为 Paddle 新增 ldexp API](https://github.com/PaddlePaddle/Paddle/issues/50630#task6)

## 2、功能目标
增加API `paddle.ldexp` 和 `paddle.Tensor.ldexp`,实现 `ldexp(input, other)`函数,函数返回 x 乘以 2 的 other 次幂
Copy link
Collaborator

Choose a reason for hiding this comment

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

2 的 other 次幂,下面数据类型变了,这里可以强调下是整数幂

添加 API
```python
paddle.ldexp(
input: 多纬Tensor,数据类型为 float32 、 float64 、 int32 或 int64
Copy link
Collaborator

Choose a reason for hiding this comment

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

多纬Tensor-》多维,为什么这里去掉float16呢

Copy link
Contributor Author

Choose a reason for hiding this comment

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

因为我测试代码的时候,发现我目前实现方式是不支持float16😭
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

因为我测试代码的时候,发现我目前实现方式是不支持float16

好的

input * 2^{other}
$$

通过调研发现,Paddle 本身已实现 paddle.pow 可以计算2的整数次幂函数,可利用paddle.pow API 与 input 相乘实现 paddl.lexp。
Copy link
Collaborator

Choose a reason for hiding this comment

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

paddl.lexp-》paddle.ldexp

@@ -123,8 +123,8 @@ math_ldexp_impl(PyObject *module, double x, PyObject *i)
添加 API
```python
paddle.ldexp(
input: 多纬Tensor,数据类型为 float32 、 float64 、 int32 或 int64
other: 多维Tensor,数据类型为 int32 或 int64
input: 多纬Tensor,数据类型为 float32、float64、int32 或 int64
Copy link
Collaborator

Choose a reason for hiding this comment

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

input: 多纬Tensor。多维

@@ -137,7 +137,7 @@ $$
input * 2^{other}
$$

通过调研发现,Paddle 本身已实现 paddle.pow 可以计算2的整数次幂函数,可利用paddle.pow API 与 input 相乘实现 paddl.lexp
通过调研发现,Paddle 本身已实现 paddle.pow 可以计算2的整数次幂函数,可利用paddle.pow API 与 input 相乘实现 paddl.ldexp
Copy link
Collaborator

Choose a reason for hiding this comment

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

paddl.ldexp -》paddle.ldexp

@longranger2
Copy link
Contributor Author

修改好了~

@longranger2 longranger2 requested a review from luotao1 March 8, 2023 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants