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

映射文档 No. 349/350 #6067

Merged
merged 5 commits into from
Aug 3, 2023
Merged

映射文档 No. 349/350 #6067

merged 5 commits into from
Aug 3, 2023

Conversation

co63oc
Copy link
Contributor

@co63oc co63oc commented Jul 27, 2023

PaddlePaddle/PaConvert#112

349 torch.Tensor.mT 组合替代实现
350 torch.Tensor.mH 组合替代实现

@paddle-bot
Copy link

paddle-bot bot commented Jul 27, 2023

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

@zhwesky2010
Copy link
Collaborator

zhwesky2010 commented Jul 31, 2023

torch.Tensor.H也一起加进来吧,对应为:

x.T.conj()

torch.Tensor.mT
```

Paddle 无此 API,需要组合实现。
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.

已修改

# Paddle 写法
perm = list(range(x.ndim))
perm[-1], perm[-2] = perm[-2], perm[-1]
y = paddle.transpose(x, perm=perm)
Copy link
Collaborator

Choose a reason for hiding this comment

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

可以用类方法来写:

x.transpose(perm=[0, 1, 3, 2])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

y = x.mT

# Paddle 写法
perm = list(range(x.ndim))
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个是自动转的写法,写人工转换思路时可以灵活直白些,比如假设为4D就直接写:

x.transpose(perm=[0, 1, 3, 2])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

y = x.mH

# Paddle 写法
perm = list(range(x.ndim))
Copy link
Collaborator

Choose a reason for hiding this comment

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

可以用类方法来写,看起来更简洁:

x.transpose(perm=[0, 1, 3, 2]).conj()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

@co63oc
Copy link
Contributor Author

co63oc commented Aug 1, 2023

torch.Tensor.H也一起加进来吧,对应为:

x.T.conj()

已增加 torch.Tensor.H

### 转写示例

```python
# Pytorch 写法
Copy link
Collaborator

Choose a reason for hiding this comment

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

可以加一句,假设x为4D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

```

Paddle 无此 API,需要组合实现。
PyTorch 中等于 x.transpose(0, 1).conj(),Paddle 中 transpose 参数 perm 为转换后的维度位置
Copy link
Collaborator

Choose a reason for hiding this comment

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

加一句,该API仅针对2D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

# Pytorch 写法
y = x.mT

# 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为4D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

Copy link
Collaborator

@zhwesky2010 zhwesky2010 left a comment

Choose a reason for hiding this comment

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

LGTM

@zhwesky2010 zhwesky2010 merged commit 7f9579d into PaddlePaddle:develop Aug 3, 2023
1 check passed
@co63oc co63oc deleted the api349 branch August 30, 2023 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants