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.214 torch.linalg.tensorinv #6059

Closed
Closed
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
Prev Previous commit
update tensorinv mapping type
RedContritio committed Oct 16, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 33353dc02d7abbbf21a6136f2d9a89084367f41b
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
## [组合替代实现]torch.linalg.tensorinv
## [功能缺失]torch.linalg.tensorinv

### [torch.linalg.inv](https://pytorch.org/docs/stable/generated/torch.linalg.tensorinv.html#torch-linalg-tensorinv)

```python
torch.linalg.tensorinv(A, ind=2, *, out=None)
```

PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。

## 转写示例


```python
# PyTorch 写法:
A = torch.eye(4 * 6).reshape((4, 6, 8, 3))
A_inv = torch.linalg.tensorinv(A, ind=2)

# Paddle 转写:
A = paddle.eye(4 * 6).reshape((4, 6, 8, 3))
ind = 2
A_dim_0 = prod(A.shape[ind:]) # 4 * 6 == 24
A_dim_1 = prod(A.shape[:ind]) # 8 * 3 == 24
# assert A_dim_0 == A_dim_1
A_ = paddle.reshape(A, [A_dim_0, A_dim_1])
A_inv_ = paddle.linalg.inv(A_)

A_inv = paddle.reshape(A_inv_, A.shape[ind:] + A.shape[:ind])
```
PaddlePaddle 目前无对应 API。