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

[pull] main from kornia:main #81

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Changes from all commits
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
12 changes: 8 additions & 4 deletions kornia/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,15 @@ def _torch_linalg_svdvals(input: Tensor) -> Tensor:
def _torch_solve_cast(A: Tensor, B: Tensor) -> Tensor:
"""Make torch.solve work with other than fp32/64.

For stable operation, the input matrices should be cast to fp64, and the output will be cast back to the input
dtype.
For stable operation, the input matrices should be cast to fp64, and the output will
be cast back to the input dtype. However, fp64 is not yet supported on MPS.
"""
# cast to fp64 and solve
out = torch.linalg.solve(A.to(torch.float64), B.to(torch.float64))
if is_mps_tensor_safe(A):
dtype = torch.float32
else:
dtype = torch.float64

out = torch.linalg.solve(A.to(dtype), B.to(dtype))

# cast back to the input dtype
return out.to(A.dtype)
Expand Down