Skip to content

Commit

Permalink
Workaround when torch.hypot is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain BRÉGIER committed Apr 19, 2024
1 parent a24129b commit 4b8740d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion roma/euler.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def unitquat_to_euler(convention : str, quat, degrees=False, epsilon=1e-7):
# Compute second angle...
angles = [torch.empty(N, device=quat.device, dtype=quat.dtype) for _ in range(3)]

angles[1] = 2 * torch.atan2(torch.hypot(c, d), torch.hypot(a, b))
angles[1] = 2 * torch.atan2(roma.internal.hypot(c, d), roma.internal.hypot(a, b))

# ... and check if equal to is 0 or pi, causing a singularity
case1 = torch.abs(angles[1]) <= epsilon
Expand Down
10 changes: 9 additions & 1 deletion roma/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,12 @@ def norm(x, dim=None, keepdim=False):
except AttributeError:
# torch.linalg.norm was introduced in PyTorch 1.7, and torch.norm is deprecated.
def norm(x, dim=None, keepdim=False):
return torch.norm(x, dim=dim, keepdim=keepdim)
return torch.norm(x, dim=dim, keepdim=keepdim)

try:
torch.hypot
hypot = torch.hypot
except AttributeError:
# torch.hypot is not available in PyTorch 1.6.
def hypot(x, y):
return torch.sqrt(torch.square(x) + torch.square(y))

0 comments on commit 4b8740d

Please sign in to comment.