jboth commited on
Commit
ffd6a1b
·
verified ·
1 Parent(s): 3bbaee5

Upload pytorch3d_stub/pytorch3d/transforms/__init__.py with huggingface_hub

Browse files
pytorch3d_stub/pytorch3d/transforms/__init__.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Minimal pytorch3d.transforms stub – quaternion operations only."""
2
+ import torch
3
+
4
+ def quaternion_multiply(q1: torch.Tensor, q2: torch.Tensor) -> torch.Tensor:
5
+ """Hamilton product of two quaternions (w, x, y, z)."""
6
+ w1, x1, y1, z1 = q1.unbind(-1)
7
+ w2, x2, y2, z2 = q2.unbind(-1)
8
+ return torch.stack([
9
+ w1*w2 - x1*x2 - y1*y2 - z1*z2,
10
+ w1*x2 + x1*w2 + y1*z2 - z1*y2,
11
+ w1*y2 - x1*z2 + y1*w2 + z1*x2,
12
+ w1*z2 + x1*y2 - y1*x2 + z1*w2,
13
+ ], dim=-1)
14
+
15
+ def quaternion_invert(q: torch.Tensor) -> torch.Tensor:
16
+ """Invert a quaternion (w, x, y, z) -> (w, -x, -y, -z) / ||q||^2."""
17
+ scaling = torch.tensor([1, -1, -1, -1], device=q.device, dtype=q.dtype)
18
+ return q * scaling / (q * q).sum(dim=-1, keepdim=True).clamp(min=1e-10)