Skip to content

Commit 1039ee5

Browse files
committed
Add optimized 'inv_T' geom utils.
1 parent 151117c commit 1039ee5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

genesis/utils/geom.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,22 @@ def inv_quat(quat):
400400
return _quat
401401

402402

403+
def inv_T(T):
404+
if isinstance(T, torch.Tensor):
405+
T_inv = torch.zeros(T)
406+
elif isinstance(T, np.ndarray):
407+
T_inv = np.zeros(T)
408+
else:
409+
gs.raise_exception(f"the input must be torch.Tensor or np.ndarray. got: {type(T)=}")
410+
411+
trans, R = T[..., :3, 3], T[..., :3, :3]
412+
T_inv[..., 3, 3] = 1.0
413+
T_inv[..., :3, 3] = -R.T @ trans
414+
T_inv[..., :3, :3] = R.T
415+
416+
return T_inv
417+
418+
403419
def normalize(x, eps: float = 1e-12):
404420
if isinstance(x, torch.Tensor):
405421
return x / x.norm(p=2, dim=-1).clamp(min=eps, max=None).unsqueeze(-1)

genesis/utils/misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def is_approx_multiple(a, b, tol=1e-7):
318318

319319
ALLOCATE_TENSOR_WARNING = (
320320
"Tensor had to be re-allocated because of incorrect dtype/device or non-contiguous memory. This may "
321-
"dramatically impede performance if it occurs in the critical path of your application."
321+
"impede performance if it occurs in the critical path of your application."
322322
)
323323

324324
FIELD_CACHE: dict[int, "FieldMetadata"] = OrderedDict()

0 commit comments

Comments
 (0)