Skip to content

Commit

Permalink
add copysign to np transform utils
Browse files Browse the repository at this point in the history
  • Loading branch information
cremebrule committed Dec 19, 2024
1 parent 46c6ecb commit a1fbadd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions omnigibson/utils/transform_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@


@torch.compile
def _copysign(a, b):
def copysign(a, b):
# type: (float, torch.Tensor) -> torch.Tensor
a = torch.tensor(a, device=b.device, dtype=torch.float).repeat(b.shape[0])
return torch.abs(a) * torch.sign(b)
Expand Down Expand Up @@ -588,7 +588,7 @@ def quat2euler(q):
roll = torch.atan2(sinr_cosp, cosr_cosp)
# pitch (y-axis rotation)
sinp = 2.0 * (q[:, qw] * q[:, qy] - q[:, qz] * q[:, qx])
pitch = torch.where(torch.abs(sinp) >= 1, _copysign(math.pi / 2.0, sinp), torch.asin(sinp))
pitch = torch.where(torch.abs(sinp) >= 1, copysign(math.pi / 2.0, sinp), torch.asin(sinp))
# yaw (z-axis rotation)
siny_cosp = 2.0 * (q[:, qw] * q[:, qz] + q[:, qx] * q[:, qy])
cosy_cosp = q[:, qw] * q[:, qw] + q[:, qx] * q[:, qx] - q[:, qy] * q[:, qy] - q[:, qz] * q[:, qz]
Expand Down
5 changes: 5 additions & 0 deletions omnigibson/utils/transform_utils_np.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
_TUPLE2AXES = dict((v, k) for k, v in _AXES2TUPLE.items())


def copysign(a, b):
a = np.array(a).repeat(b.shape[0])
return np.abs(a) * np.sign(b)


def anorm(x, axis=None, keepdims=False):
"""Compute L2 norms alogn specified axes."""
return np.linalg.norm(x, axis=axis, keepdims=keepdims)
Expand Down

0 comments on commit a1fbadd

Please sign in to comment.