Skip to content
Open
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
6 changes: 4 additions & 2 deletions src/foundry/utils/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def weighted_rigid_align(
# Computation of the covariance matrix
C = torch.einsum("bji,bjk->bik", w_resolved[..., None] * X_gt_resolved, X_resolved)

U, S, V = torch.linalg.svd(C)
# SVD has no bf16/half CUDA kernel and is numerically sensitive; compute the
# rotation in float32 and cast it back to the input dtype below.
U, S, V = torch.linalg.svd(C.float())

R = U @ V
B, _, _ = X_L.shape
Expand All @@ -71,7 +73,7 @@ def weighted_rigid_align(

det = torch.linalg.det(R)
F[..., -1, -1] = torch.sign(det)
R = U @ F @ V
R = (U @ F @ V).to(X_gt_L.dtype)

X_gt_L = X_gt_L - u_X_gt.unsqueeze(-2)
X_align_L = X_gt_L @ R + u_X.unsqueeze(-2)
Expand Down