From 016fd440f1e3df80b087e32ae109c4d55f8c9e41 Mon Sep 17 00:00:00 2001 From: yjinzero Date: Sat, 15 Feb 2025 11:18:04 +0900 Subject: [PATCH] temoprarily copy noramlize() --- deploy/deploy_real/common/np_math.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/deploy/deploy_real/common/np_math.py b/deploy/deploy_real/common/np_math.py index 45434f8..610a4e9 100644 --- a/deploy/deploy_real/common/np_math.py +++ b/deploy/deploy_real/common/np_math.py @@ -37,6 +37,18 @@ def axis_angle_from_quat(quat: np.ndarray, eps: float = 1.0e-6) -> np.ndarray: ) return quat[..., 1:4] / sin_half_angles_over_angles[..., None] +def normalize(x: torch.Tensor, eps: float = 1e-9) -> torch.Tensor: + """Normalizes a given input tensor to unit length. + + Args: + x: Input tensor of shape (N, dims). + eps: A small value to avoid division by zero. Defaults to 1e-9. + + Returns: + Normalized tensor of shape (N, dims). + """ + return x / x.norm(p=2, dim=-1).clamp(min=eps, max=None).unsqueeze(-1) + def quat_from_angle_axis( angle: torch.Tensor,