Skip to content

Compatibility problem with pytorch trace #52

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

Closed
jplumail opened this issue Jul 17, 2023 · 3 comments
Closed

Compatibility problem with pytorch trace #52

jplumail opened this issue Jul 17, 2023 · 3 comments

Comments

@jplumail
Copy link

torch.linalg.trace should work on stacks of matrices.

But this

import array_api_compat.torch as torch

a = torch.reshape(torch.arange(10*5*5), (10,5,5))
torch.linalg.trace(a)

throws RuntimeError: trace: expected a matrix, but got tensor with dim 3.

The pytorch's trace function doesn't handle stacks: see the docs.

@asmeurer
Copy link
Member

asmeurer commented Jul 19, 2023

Thanks for the report. What's a good way to work around this? @lezcano

@lezcano
Copy link

lezcano commented Jul 19, 2023

x.diagonal(0, -2, -1).sum(-1)

@asmeurer
Copy link
Member

asmeurer commented Mar 8, 2024

This was fixed in #80

@asmeurer asmeurer closed this as completed Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants