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

【Hackathon 8th No.1】add lu_solve api for paddle #7052

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

decade-afk
Copy link
Contributor

No description provided.

Copy link

paddle-bot bot commented Feb 20, 2025

感谢你贡献飞桨文档,文档预览构建中,Docs-New 跑完后即可预览,预览链接:http://preview-pr-7052.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html
预览工具的更多说明,请参考:飞桨文档预览工具

Copy link
Collaborator

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

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

中文文档还需要更新么?

@decade-afk
Copy link
Contributor Author

中文文档还需要更新么?

不用了,该写的都写了

- **b** (Tensor) - 输入的欲进行线性方程组求解的右值,类型为 Tensor。 ``b`` 的形状应为 ``[*, M, K]``,其中 ``*`` 为零或更大的批次维度,数据类型为 float32, float64。
- **lu** (Tensor) - LU 分解结果矩阵,由 L、U 拼接组成,类型为 Tensor。 ``lu`` 的形状应为 ``[*, M, M]``,其中 ``*`` 为零或更大的批次维度。数据类型和 ``b`` 相同。
- **pivots** (Tensor) - LU 分解结果的主元信息,类型为 Tensor。 ``pivots`` 的形状应为 ``[*, M]``,其中 ``*`` 为零或更大的批次维度。数据类型为 int32。
- **trans** (str,可选) - 是否对 A 进行转置,默认值为 N。
Copy link
Collaborator

Choose a reason for hiding this comment

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

写一下trans的取值?可以是N、T、C

.. math::
b = A * X

当 `trans` 为 `T` 时,公式为:
Copy link
Collaborator

Choose a reason for hiding this comment

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

trans为C时的公式也写下吧


| PyTorch | PaddlePaddle | 备注 |
| ------- | ------------ | ----------------------------------------------------- |
| B | b | 表示欲进行线性方程组求解的右值 Tensor ,仅参数名不一致。 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

参数顺序以Pytorch的为主,第一个是LU

| B | b | 表示欲进行线性方程组求解的右值 Tensor ,仅参数名不一致。 |
| pivots | pivots | 表示 LU 分解结果的主元信息 Tensor 。 |
| LU | lu | 表示 LU 分解结果矩阵,由 L、U 拼接组成,仅参数名不一致。 |
| left | - | 表示待求解向量是否在左侧, Paddle 无此参数,暂无转写方式。|
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个可以转写吧,根据你之前的描述,可以利用转置来变换公式,将左边变换到右边

| pivots | pivots | 表示 LU 分解结果的主元信息 Tensor 。 |
| LU | lu | 表示 LU 分解结果矩阵,由 L、U 拼接组成,仅参数名不一致。 |
| left | - | 表示待求解向量是否在左侧, Paddle 无此参数,暂无转写方式。|
| adjoint | trans | 表示是否使用转置 LU 分解结果, PyTorch 为 bool 类型,Paddle 为 str 类型,需要转写。|
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个应该是共轭转置?adjoint=True时对应tranc='C'

| LU | lu | 表示 LU 分解结果矩阵,由 L、U 拼接组成,仅参数名不一致。 |
| left | - | 表示待求解向量是否在左侧, Paddle 无此参数,暂无转写方式。|
| adjoint | trans | 表示是否使用转置 LU 分解结果, PyTorch 为 bool 类型,Paddle 为 str 类型,需要转写。|
| out | - | 表示输出的 Tensor 元组 , Paddle 无此参数,需要转写。 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

有四种情况下的转写,看看是不是这样变换的:

x=torch.linalg.lu_solve(lu, pivots, b) -> x=paddle.lu_solve(b, lu, pivots)
x=torch.linalg.lu_solve(lu, pivots, b, adjoint=True) -> x=paddle.lu_solve(b, lu, pivots, trans=‘C’)
x=torch.linalg.lu_solve(lu, pivots, b, left=False) -> x=paddle.lu_solve(b^H, lu, pivots, trans=‘C’)^H
	X A=b -> A^H X^H=b^H
x=torch.linalg.lu_solve(lu, pivots, b, left=False, adjoint=True) -> x=paddle.lu_solve(b^H, lu, pivots)^H
 	X A^H=b -> A X^H=b^H

paddle.assign(y, A)
```

#### adjoint
Copy link
Collaborator

Choose a reason for hiding this comment

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

adjoint与left的四种组合情况转写

Copy link
Contributor Author

Choose a reason for hiding this comment

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

adjoint与left的四种组合情况转写

已经都改好了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor PaddlePaddle Hackathon 飞桨黑客松活动issue与PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants