π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
axis_angle typo fix (#2463)
Christie Jacob79216c5e1890
diff --git a/docs/source/geometry.conversions.rst b/docs/source/geometry.conversions.rstindex 2ad4bf03f..a24fe333b 100644--- a/docs/source/geometry.conversions.rst+++ b/docs/source/geometry.conversions.rst@@ -36,7 +36,7 @@ HomographyQuaternion-----------.. autofunction:: quaternion_to_angle_axis+.. autofunction:: quaternion_to_axis_angle.. autofunction:: quaternion_to_rotation_matrix.. autofunction:: quaternion_log_to_exp.. autofunction:: quaternion_exp_to_log@@ -45,14 +45,14 @@ QuaternionRotation Matrix----------------.. autofunction:: rotation_matrix_to_angle_axis+.. autofunction:: rotation_matrix_to_axis_angle.. autofunction:: rotation_matrix_to_quaternion-Angle Axis+Axis Angle-----------.. autofunction:: angle_axis_to_quaternion-.. autofunction:: angle_axis_to_rotation_matrix+.. autofunction:: axis_angle_to_quaternion+.. autofunction:: axis_angle_to_rotation_matrixEuler Angles------------diff --git a/kornia/geometry/camera/pinhole.py b/kornia/geometry/camera/pinhole.pyindex cfda3b6be..2bda29cf8 100644--- a/kornia/geometry/camera/pinhole.py+++ b/kornia/geometry/camera/pinhole.py@@ -576,7 +576,7 @@ def get_optical_pose_base(pinholes: Tensor) -> Tensor:raise NotImplementedError# TODO: We have rtvec_to_pose in torchgeometry# https://github.com/whh14/torchgeometry/blob/master/torchgeometry/conversions.py#L240- # But it relies on angle_axis_to_rotation_matrix+ # But it relies on axis_angle_to_rotation_matrix# And since then, it was changed from returning Nx4x4 matrix to Nx3x3# return rtvec_to_pose(optical_pose_parent) type: ignorediff --git a/kornia/geometry/conversions.py b/kornia/geometry/conversions.pyindex a6cef4565..3bc6e670f 100644--- a/kornia/geometry/conversions.py+++ b/kornia/geometry/conversions.py@@ -6,6 +6,7 @@ import torch.nn.functional as Ffrom kornia.constants import pifrom kornia.core import Tensor, concatenate, pad, stack, tensor, wherefrom kornia.core.check import KORNIA_CHECK, KORNIA_CHECK_SHAPE+from kornia.utils import deprecatedfrom kornia.utils.helpers import _torch_inverse_cast__all__ = [@@ -17,10 +18,14 @@ __all__ = ["convert_points_to_homogeneous","convert_affinematrix_to_homography","convert_affinematrix_to_homography3d",+ "axis_angle_to_rotation_matrix","angle_axis_to_rotation_matrix",+ "axis_angle_to_quaternion","angle_axis_to_quaternion",+ "rotation_matrix_to_axis_angle","rotation_matrix_to_angle_axis","rotation_matrix_to_quaternion",+ "quaternion_to_axis_angle","quaternion_to_angle_axis","quaternion_to_rotation_matrix","quaternion_log_to_exp",@@ -256,41 +261,41 @@ def convert_affinematrix_to_homography3d(A: Tensor) -> Tensor:return _convert_affinematrix_to_homography_impl(A)-def angle_axis_to_rotation_matrix(angle_axis: Tensor) -> Tensor:+def axis_angle_to_rotation_matrix(axis_angle: Tensor) -> Tensor:r"""Convert 3d vector of axis-angle rotation to 3x3 rotation matrix.Args:- angle_axis: tensor of 3d vector of axis-angle rotations in radians with shape :math:`(N, 3)`.+ axis_angle: tensor of 3d vector of axis-angle rotations in radians with shape :math:`(N, 3)`.Returns:tensor of rotation matrices of shape :math:`(N, 3, 3)`.Example:>>> input = tensor([[0., 0., 0.]])- >>> angle_axis_to_rotation_matrix(input)+ >>> axis_angle_to_rotation_matrix(input)tensor([[[1., 0., 0.],[0., 1., 0.],[0., 0., 1.]]])>>> input = tensor([[1.5708, 0., 0.]])- >>> angle_axis_to_rotation_matrix(input)+ >>> axis_angle_to_rotation_matrix(input)tensor([[[ 1.0000e+00, 0.0000e+00, 0.0000e+00],[ 0.0000e+00, -3.6200e-06, -1.0000e+00],[ 0.0000e+00, 1.0000e+00, -3.6200e-06]]])"""- if not isinstance(angle_axis, Tensor):- raise TypeError(f"Input type is not a Tensor. Got {type(angle_axis)}")+ if not isinstance(axis_angle, Tensor):+ raise TypeError(f"Input type is not a Tensor. Got {type(axis_angle)}")- if not angle_axis.shape[-1] == 3:- raise ValueError(f"Input size must be a (*, 3) tensor. Got {angle_axis.shape}")+ if not axis_angle.shape[-1] == 3:+ raise ValueError(f"Input size must be a (*, 3) tensor. Got {axis_angle.shape}")- def _compute_rotation_matrix(angle_axis: Tensor, theta2: Tensor, eps: float = 1e-6) -> Tensor:+ def _compute_rotation_matrix(axis_angle: Tensor, theta2: Tensor, eps: float = 1e-6) -> Tensor:# We want to be careful to only evaluate the square root if the- # norm of the angle_axis vector is greater than zero. Otherwise+ # norm of the axis_angle vector is greater than zero. Otherwise# we get a division by zero.k_one = 1.0theta = torch.sqrt(theta2)- wxyz = angle_axis / (theta + eps)+ wxyz = axis_angle / (theta + eps)wx, wy, wz = torch.chunk(wxyz, 3, dim=1)cos_theta = torch.cos(theta)sin_theta = torch.sin(theta)@@ -307,21 +312,21 @@ def angle_axis_to_rotation_matrix(angle_axis: Tensor) -> Tensor:rotation_matrix = concatenate([r00, r01, r02, r10, r11, r12, r20, r21, r22], dim=1)return rotation_matrix.view(-1, 3, 3)- def _compute_rotation_matrix_taylor(angle_axis: Tensor) -> Tensor:- rx, ry, rz = torch.chunk(angle_axis, 3, dim=1)+ def _compute_rotation_matrix_taylor(axis_angle: Tensor) -> Tensor:+ rx, ry, rz = torch.chunk(axis_angle, 3, dim=1)k_one = torch.ones_like(rx)rotation_matrix = concatenate([k_one, -rz, ry, rz, k_one, -rx, -ry, rx, k_one], dim=1)return rotation_matrix.view(-1, 3, 3)# stolen from ceres/rotation.h- _angle_axis = torch.unsqueeze(angle_axis, dim=1)- theta2 = torch.matmul(_angle_axis, _angle_axis.transpose(1, 2))+ _axis_angle = torch.unsqueeze(axis_angle, dim=1)+ theta2 = torch.matmul(_axis_angle, _axis_angle.transpose(1, 2))theta2 = torch.squeeze(theta2, dim=1)# compute rotation matrices- rotation_matrix_normal = _compute_rotation_matrix(angle_axis, theta2)- rotation_matrix_taylor = _compute_rotation_matrix_taylor(angle_axis)+ rotation_matrix_normal = _compute_rotation_matrix(axis_angle, theta2)+ rotation_matrix_taylor = _compute_rotation_matrix_taylor(axis_angle)# create mask to handle both caseseps = 1e-6@@ -334,7 +339,12 @@ def angle_axis_to_rotation_matrix(angle_axis: Tensor) -> Tensor:return rotation_matrix # Nx3x3-def rotation_matrix_to_angle_axis(rotation_matrix: Tensor) -> Tensor:+@deprecated(replace_with='axis_angle_to_rotation_matrix', version='0.7.0')+def angle_axis_to_rotation_matrix(axis_angle: Tensor) -> Tensor:+ return axis_angle_to_rotation_matrix(axis_angle)+++def rotation_matrix_to_axis_angle(rotation_matrix: Tensor) -> Tensor:r"""Convert 3x3 rotation matrix to Rodrigues vector in radians.Args:@@ -347,13 +357,13 @@ def rotation_matrix_to_angle_axis(rotation_matrix: Tensor) -> Tensor:>>> input = tensor([[1., 0., 0.],... [0., 1., 0.],... [0., 0., 1.]])- >>> rotation_matrix_to_angle_axis(input)+ >>> rotation_matrix_to_axis_angle(input)tensor([0., 0., 0.])>>> input = tensor([[1., 0., 0.],... [0., 0., -1.],... [0., 1., 0.]])- >>> rotation_matrix_to_angle_axis(input)+ >>> rotation_matrix_to_axis_angle(input)tensor([1.5708, 0.0000, 0.0000])"""if not isinstance(rotation_matrix, Tensor):@@ -362,7 +372,12 @@ def rotation_matrix_to_angle_axis(rotation_matrix: Tensor) -> Tensor:if not rotation_matrix.shape[-2:] == (3, 3):raise ValueError(f"Input size must be a (*, 3, 3) tensor. Got {rotation_matrix.shape}")quaternion: Tensor = rotation_matrix_to_quaternion(rotation_matrix)- return quaternion_to_angle_axis(quaternion)+ return quaternion_to_axis_angle(quaternion)+++@deprecated(replace_with='rotation_matrix_to_axis_angle', version='0.7.0')+def rotation_matrix_to_angle_axis(rotation_matrix: Tensor) -> Tensor:+ return rotation_matrix_to_axis_angle(rotation_matrix)def rotation_matrix_to_quaternion(rotation_matrix: Tensor, eps: float = 1.0e-8) -> Tensor:@@ -541,8 +556,8 @@ def quaternion_to_rotation_matrix(quaternion: Tensor) -> Tensor:return matrix-def quaternion_to_angle_axis(quaternion: Tensor) -> Tensor:- """Convert quaternion vector to angle axis of rotation in radians.+def quaternion_to_axis_angle(quaternion: Tensor) -> Tensor:+ """Convert quaternion vector to axis angle of rotation in radians.The quaternion should be in (w, x, y, z) format.@@ -552,7 +567,7 @@ def quaternion_to_angle_axis(quaternion: Tensor) -> Tensor:quaternion: tensor with quaternions.Return:- tensor with angle axis of rotation.+ tensor with axis angle of rotation.Shape:- Input: :math:`(*, 4)` where `*` means, any number of dimensions@@ -560,7 +575,7 @@ def quaternion_to_angle_axis(quaternion: Tensor) -> Tensor:Example:>>> quaternion = tensor((1., 0., 0., 0.))- >>> quaternion_to_angle_axis(quaternion)+ >>> quaternion_to_axis_angle(quaternion)tensor([0., 0., 0.])"""if not torch.is_tensor(quaternion):@@ -591,11 +606,16 @@ def quaternion_to_angle_axis(quaternion: Tensor) -> Tensor:k_neg: Tensor = 2.0 * torch.ones_like(sin_theta)k: Tensor = where(sin_squared_theta > 0.0, k_pos, k_neg)- angle_axis: Tensor = torch.zeros_like(quaternion)[..., :3]- angle_axis[..., 0] += q1 * k- angle_axis[..., 1] += q2 * k- angle_axis[..., 2] += q3 * k- return angle_axis+ axis_angle: Tensor = torch.zeros_like(quaternion)[..., :3]+ axis_angle[..., 0] += q1 * k+ axis_angle[..., 1] += q2 * k+ axis_angle[..., 2] += q3 * k+ return axis_angle+++@deprecated(replace_with='quaternion_to_axis_angle', version='0.7.0')+def quaternion_to_angle_axis(quaternion: Tensor) -> Tensor:+ return quaternion_to_axis_angle(quaternion)def quaternion_log_to_exp(quaternion: Tensor, eps: float = 1.0e-8) -> Tensor:@@ -680,15 +700,15 @@ def quaternion_exp_to_log(quaternion: Tensor, eps: float = 1.0e-8) -> Tensor:# https://github.com/facebookresearch/QuaterNet/blob/master/common/quaternion.py#L138-def angle_axis_to_quaternion(angle_axis: Tensor) -> Tensor:- r"""Convert an angle axis to a quaternion.+def axis_angle_to_quaternion(axis_angle: Tensor) -> Tensor:+ r"""Convert an axis angle to a quaternion.The quaternion vector has components in (w, x, y, z) format.Adapted from ceres C++ library: ceres-solver/include/ceres/rotation.hArgs:- angle_axis: tensor with angle axis in radians.+ axis_angle: tensor with axis angle in radians.Return:tensor with quaternion.@@ -698,20 +718,20 @@ def angle_axis_to_quaternion(angle_axis: Tensor) -> Tensor:- Output: :math:`(*, 4)`Example:- >>> angle_axis = tensor((0., 1., 0.))- >>> angle_axis_to_quaternion(angle_axis)+ >>> axis_angle = tensor((0., 1., 0.))+ >>> axis_angle_to_quaternion(axis_angle)tensor([0.8776, 0.0000, 0.4794, 0.0000])"""- if not torch.is_tensor(angle_axis):- raise TypeError(f"Input type is not a Tensor. Got {type(angle_axis)}")+ if not torch.is_tensor(axis_angle):+ raise TypeError(f"Input type is not a Tensor. Got {type(axis_angle)}")- if not angle_axis.shape[-1] == 3:- raise ValueError(f"Input must be a tensor of shape Nx3 or 3. Got {angle_axis.shape}")+ if not axis_angle.shape[-1] == 3:+ raise ValueError(f"Input must be a tensor of shape Nx3 or 3. Got {axis_angle.shape}")# unpack input and compute conversion- a0: Tensor = angle_axis[..., 0:1]- a1: Tensor = angle_axis[..., 1:2]- a2: Tensor = angle_axis[..., 2:3]+ a0: Tensor = axis_angle[..., 0:1]+ a1: Tensor = axis_angle[..., 1:2]+ a2: Tensor = axis_angle[..., 2:3]theta_squared: Tensor = a0 * a0 + a1 * a1 + a2 * a2theta: Tensor = torch.sqrt(theta_squared)@@ -725,7 +745,7 @@ def angle_axis_to_quaternion(angle_axis: Tensor) -> Tensor:k: Tensor = where(mask, k_pos, k_neg)w: Tensor = where(mask, torch.cos(half_theta), ones)- quaternion: Tensor = torch.zeros(size=(*angle_axis.shape[:-1], 4), dtype=angle_axis.dtype, device=angle_axis.device)+ quaternion: Tensor = torch.zeros(size=(*axis_angle.shape[:-1], 4), dtype=axis_angle.dtype, device=axis_angle.device)quaternion[..., 1:2] = a0 * kquaternion[..., 2:3] = a1 * kquaternion[..., 3:4] = a2 * k@@ -733,6 +753,11 @@ def angle_axis_to_quaternion(angle_axis: Tensor) -> Tensor:return quaternion+@deprecated(replace_with='axis_angle_to_quaternion', version='0.7.0')+def angle_axis_to_quaternion(axis_angle: Tensor) -> Tensor:+ return axis_angle_to_quaternion(axis_angle)++# inspired by: https://stackoverflow.com/questions/56207448/efficient-quaternions-to-euler-transformationdiff --git a/kornia/geometry/epipolar/scene.py b/kornia/geometry/epipolar/scene.pyindex 0fec2e7e6..2bd498d81 100644--- a/kornia/geometry/epipolar/scene.py+++ b/kornia/geometry/epipolar/scene.py@@ -4,7 +4,7 @@ from typing import Dictimport torch-from kornia.geometry.conversions import angle_axis_to_rotation_matrix+from kornia.geometry.conversions import axis_angle_to_rotation_matrixfrom kornia.geometry.linalg import transform_pointsfrom .projection import projection_from_KRt, random_intrinsics@@ -22,7 +22,7 @@ def generate_scene(num_views: int, num_points: int) -> Dict[str, torch.Tensor]:rvec = torch.rand(num_views, 3)rvec = ang * rvec / torch.norm(rvec, dim=1, keepdim=True) # Nx3- rot_mat = angle_axis_to_rotation_matrix(rvec) # Nx3x3+ rot_mat = axis_angle_to_rotation_matrix(rvec) # Nx3x3# matches with cv2.Rodrigues -> yay !# Create random translation per viewdiff --git a/kornia/geometry/quaternion.py b/kornia/geometry/quaternion.pyindex 0924be711..206080475 100644--- a/kornia/geometry/quaternion.py+++ b/kornia/geometry/quaternion.py@@ -8,7 +8,7 @@ from typing import Optional, Tuple, Unionfrom kornia.core import Device, Dtype, Module, Parameter, Tensor, concatenate, rand, stack, tensor, wherefrom kornia.core.check import KORNIA_CHECK_TYPEfrom kornia.geometry.conversions import (- angle_axis_to_quaternion,+ axis_angle_to_quaternion,normalize_quaternion,quaternion_to_rotation_matrix,rotation_matrix_to_quaternion,@@ -272,7 +272,7 @@ class Quaternion(Module):Parameter containing:tensor([[0.8776, 0.4794, 0.0000, 0.0000]], requires_grad=True)"""- return cls(angle_axis_to_quaternion(axis_angle))+ return cls(axis_angle_to_quaternion(axis_angle))@classmethoddef identity(diff --git a/kornia/geometry/transform/imgwarp.py b/kornia/geometry/transform/imgwarp.pyindex eab8f9650..f6b53215d 100644--- a/kornia/geometry/transform/imgwarp.py+++ b/kornia/geometry/transform/imgwarp.py@@ -7,8 +7,8 @@ from torch.nn.functional import grid_samplefrom kornia.core import Tensor, concatenate, stack, tensor, zerosfrom kornia.core.check import KORNIA_CHECK, KORNIA_CHECK_SHAPEfrom kornia.geometry.conversions import (- angle_axis_to_rotation_matrix,angle_to_rotation_matrix,+ axis_angle_to_rotation_matrix,convert_affinematrix_to_homography,convert_affinematrix_to_homography3d,deg2rad,@@ -693,7 +693,7 @@ def get_affine_matrix3d(translations: tensor containing the translation vector (dx,dy,dz) with shape :math:`(B, 3)`.center: tensor containing the center vector (x,y,z) with shape :math:`(B, 3)`.scale: tensor containing the scale factor with shape :math:`(B)`.- angle: angle axis vector containing the rotation angles in degrees in the form+ angle: axis angle vector containing the rotation angles in degrees in the formof (rx, ry, rz) with shape :math:`(B, 3)`. Internally it calls Rodrigues to computethe rotation matrix from axis-angle.sxy: tensor containing the shear factor in the xy-direction with shape :math:`(B)`.@@ -915,7 +915,7 @@ def get_projective_transform(center: Tensor, angles: Tensor, scales: Tensor) ->Args:center: center of the rotation (x,y,z) in the source with shape :math:`(B, 3)`.- angles: angle axis vector containing the rotation angles in degrees in the form+ angles: axis angle vector containing the rotation angles in degrees in the formof (rx, ry, rz) with shape :math:`(B, 3)`. Internally it calls Rodrigues to computethe rotation matrix from axis-angle.scales: scale factor for x-y-z-directions with shape :math:`(B, 3)`.@@ -936,8 +936,8 @@ def get_projective_transform(center: Tensor, angles: Tensor, scales: Tensor) ->raise AssertionError(center.dtype, angles.dtype)# create rotation matrix- angle_axis_rad: Tensor = deg2rad(angles)- rmat: Tensor = angle_axis_to_rotation_matrix(angle_axis_rad) # Bx3x3+ axis_angle_rad: Tensor = deg2rad(angles)+ rmat: Tensor = axis_angle_to_rotation_matrix(axis_angle_rad) # Bx3x3scaling_matrix: Tensor = eye_like(3, rmat)scaling_matrix = scaling_matrix * scales.unsqueeze(dim=1)rmat = rmat @ scaling_matrix.to(rmat)diff --git a/test/geometry/calibration/test_pnp.py b/test/geometry/calibration/test_pnp.pyindex b5f1c41f8..f3638381f 100644--- a/test/geometry/calibration/test_pnp.py+++ b/test/geometry/calibration/test_pnp.py@@ -47,10 +47,10 @@ class TestSolvePnpDlt:torch.manual_seed(84)tau = 2 * 3.141592653589793- angle_axis_1 = self._get_samples(shape=(1, 3), low=-tau, high=tau, dtype=dtype, device=device)- angle_axis_2 = self._get_samples(shape=(1, 3), low=-tau, high=tau, dtype=dtype, device=device)- rotation_1 = kornia.geometry.angle_axis_to_rotation_matrix(angle_axis_1)- rotation_2 = kornia.geometry.angle_axis_to_rotation_matrix(angle_axis_2)+ axis_angle_1 = self._get_samples(shape=(1, 3), low=-tau, high=tau, dtype=dtype, device=device)+ axis_angle_2 = self._get_samples(shape=(1, 3), low=-tau, high=tau, dtype=dtype, device=device)+ rotation_1 = kornia.geometry.axis_angle_to_rotation_matrix(axis_angle_1)+ rotation_2 = kornia.geometry.axis_angle_to_rotation_matrix(axis_angle_2)translation_1 = self._get_samples(shape=(3,), low=-100, high=100, dtype=dtype, device=device)translation_2 = self._get_samples(shape=(3,), low=-100, high=100, dtype=dtype, device=device)diff --git a/test/geometry/test_conversions.py b/test/geometry/test_conversions.pyindex 373835872..eee0cf27c 100644--- a/test/geometry/test_conversions.py+++ b/test/geometry/test_conversions.py@@ -45,72 +45,72 @@ def rtol(device, dtype):class TestAngleAxisToQuaternion:def test_smoke(self, device, dtype):- angle_axis = torch.zeros(3, dtype=dtype, device=device)- quaternion = kornia.geometry.conversions.angle_axis_to_quaternion(angle_axis)+ axis_angle = torch.zeros(3, dtype=dtype, device=device)+ quaternion = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)assert quaternion.shape == (4,)@pytest.mark.parametrize("batch_size", (1, 3, 8))def test_smoke_batch(self, batch_size, device, dtype):- angle_axis = torch.zeros(batch_size, 3, device=device, dtype=dtype)- quaternion = kornia.geometry.conversions.angle_axis_to_quaternion(angle_axis)+ axis_angle = torch.zeros(batch_size, 3, device=device, dtype=dtype)+ quaternion = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)assert quaternion.shape == (batch_size, 4)def test_zero_angle(self, device, dtype, atol, rtol):- angle_axis = torch.tensor((0.0, 0.0, 0.0), device=device, dtype=dtype)+ axis_angle = torch.tensor((0.0, 0.0, 0.0), device=device, dtype=dtype)expected = torch.tensor((1.0, 0.0, 0.0, 0.0), device=device, dtype=dtype)- quaternion = kornia.geometry.conversions.angle_axis_to_quaternion(angle_axis)+ quaternion = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)assert_close(quaternion, expected, atol=atol, rtol=rtol)def test_small_angle_x(self, device, dtype, atol, rtol):theta = 1.0e-2- angle_axis = torch.tensor((theta, 0.0, 0.0), device=device, dtype=dtype)+ axis_angle = torch.tensor((theta, 0.0, 0.0), device=device, dtype=dtype)expected = torch.tensor((np.cos(theta / 2.0), np.sin(theta / 2.0), 0.0, 0.0), device=device, dtype=dtype)- quaternion = kornia.geometry.conversions.angle_axis_to_quaternion(angle_axis)+ quaternion = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)assert_close(quaternion, expected, atol=atol, rtol=rtol)def test_small_angle_y(self, device, dtype, atol, rtol):theta = 1.0e-2- angle_axis = torch.tensor((0.0, theta, 0.0), device=device, dtype=dtype)+ axis_angle = torch.tensor((0.0, theta, 0.0), device=device, dtype=dtype)expected = torch.tensor((np.cos(theta / 2.0), 0.0, np.sin(theta / 2.0), 0.0), device=device, dtype=dtype)- quaternion = kornia.geometry.conversions.angle_axis_to_quaternion(angle_axis)+ quaternion = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)assert_close(quaternion, expected, atol=atol, rtol=rtol)def test_small_angle_z(self, device, dtype, atol, rtol):theta = 1.0e-2- angle_axis = torch.tensor((0.0, 0.0, theta), device=device, dtype=dtype)+ axis_angle = torch.tensor((0.0, 0.0, theta), device=device, dtype=dtype)expected = torch.tensor((np.cos(theta / 2.0), 0.0, 0.0, np.sin(theta / 2.0)), device=device, dtype=dtype)- quaternion = kornia.geometry.conversions.angle_axis_to_quaternion(angle_axis)+ quaternion = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)assert_close(quaternion, expected, atol=atol, rtol=rtol)def test_x_rotation(self, device, dtype, atol, rtol):half_sqrt2 = 0.5 * np.sqrt(2.0)- angle_axis = torch.tensor((kornia.pi / 2.0, 0.0, 0.0), device=device, dtype=dtype)+ axis_angle = torch.tensor((kornia.pi / 2.0, 0.0, 0.0), device=device, dtype=dtype)expected = torch.tensor((half_sqrt2, half_sqrt2, 0.0, 0.0), device=device, dtype=dtype)- quaternion = kornia.geometry.conversions.angle_axis_to_quaternion(angle_axis)+ quaternion = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)assert_close(quaternion, expected, atol=atol, rtol=rtol)def test_y_rotation(self, device, dtype, atol, rtol):half_sqrt2 = 0.5 * np.sqrt(2.0)- angle_axis = torch.tensor((0.0, kornia.pi / 2.0, 0.0), device=device, dtype=dtype)+ axis_angle = torch.tensor((0.0, kornia.pi / 2.0, 0.0), device=device, dtype=dtype)expected = torch.tensor((half_sqrt2, 0.0, half_sqrt2, 0.0), device=device, dtype=dtype)- quaternion = kornia.geometry.conversions.angle_axis_to_quaternion(angle_axis)+ quaternion = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)assert_close(quaternion, expected, atol=atol, rtol=rtol)def test_z_rotation(self, device, dtype, atol, rtol):half_sqrt2 = 0.5 * np.sqrt(2.0)- angle_axis = torch.tensor((0.0, 0.0, kornia.pi / 2.0), device=device, dtype=dtype)+ axis_angle = torch.tensor((0.0, 0.0, kornia.pi / 2.0), device=device, dtype=dtype)expected = torch.tensor((half_sqrt2, 0.0, 0.0, half_sqrt2), device=device, dtype=dtype)- quaternion = kornia.geometry.conversions.angle_axis_to_quaternion(angle_axis)+ quaternion = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)assert_close(quaternion, expected, atol=atol, rtol=rtol)def test_gradcheck(self, device, dtype):eps = torch.finfo(dtype).eps- angle_axis = torch.tensor((0.0, 0.0, 0.0), device=device, dtype=dtype) + eps- angle_axis = tensor_to_gradcheck_var(angle_axis)+ axis_angle = torch.tensor((0.0, 0.0, 0.0), device=device, dtype=dtype) + eps+ axis_angle = tensor_to_gradcheck_var(axis_angle)# evaluate function gradientassert gradcheck(- partial(kornia.geometry.conversions.angle_axis_to_quaternion),- (angle_axis,),+ partial(kornia.geometry.conversions.axis_angle_to_quaternion),+ (axis_angle,),raise_exception=True,fast_mode=True,)@@ -119,59 +119,59 @@ class TestAngleAxisToQuaternion:class TestQuaternionToAngleAxis:def test_smoke(self, device, dtype):quaternion = torch.zeros(4, device=device, dtype=dtype)- angle_axis = kornia.geometry.conversions.quaternion_to_angle_axis(quaternion)- assert angle_axis.shape == (3,)+ axis_angle = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)+ assert axis_angle.shape == (3,)@pytest.mark.parametrize("batch_size", (1, 3, 8))def test_smoke_batch(self, batch_size, device, dtype):quaternion = torch.zeros(batch_size, 4, device=device, dtype=dtype)- angle_axis = kornia.geometry.conversions.quaternion_to_angle_axis(quaternion)- assert angle_axis.shape == (batch_size, 3)+ axis_angle = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)+ assert axis_angle.shape == (batch_size, 3)def test_unit_quaternion(self, device, dtype, atol, rtol):quaternion = torch.tensor((1.0, 0.0, 0.0, 0.0), device=device, dtype=dtype)expected = torch.tensor((0.0, 0.0, 0.0), device=device, dtype=dtype)- angle_axis = kornia.geometry.conversions.quaternion_to_angle_axis(quaternion)- assert_close(angle_axis, expected, atol=atol, rtol=rtol)+ axis_angle = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)+ assert_close(axis_angle, expected, atol=atol, rtol=rtol)def test_x_rotation(self, device, dtype, atol, rtol):quaternion = torch.tensor((0.0, 1.0, 0.0, 0.0), device=device, dtype=dtype)expected = torch.tensor((kornia.pi, 0.0, 0.0), device=device, dtype=dtype)- angle_axis = kornia.geometry.conversions.quaternion_to_angle_axis(quaternion)- assert_close(angle_axis, expected, atol=atol, rtol=rtol)+ axis_angle = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)+ assert_close(axis_angle, expected, atol=atol, rtol=rtol)def test_y_rotation(self, device, dtype, atol, rtol):quaternion = torch.tensor((0.0, 0.0, 1.0, 0.0), device=device, dtype=dtype)expected = torch.tensor((0.0, kornia.pi, 0.0), device=device, dtype=dtype)- angle_axis = kornia.geometry.conversions.quaternion_to_angle_axis(quaternion)- assert_close(angle_axis, expected, atol=atol, rtol=rtol)+ axis_angle = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)+ assert_close(axis_angle, expected, atol=atol, rtol=rtol)def test_z_rotation(self, device, dtype, atol, rtol):quaternion = torch.tensor((np.sqrt(3.0) / 2.0, 0.0, 0.0, 0.5), device=device, dtype=dtype)expected = torch.tensor((0.0, 0.0, kornia.pi / 3.0), device=device, dtype=dtype)- angle_axis = kornia.geometry.conversions.quaternion_to_angle_axis(quaternion)- assert_close(angle_axis, expected, atol=atol, rtol=rtol)+ axis_angle = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)+ assert_close(axis_angle, expected, atol=atol, rtol=rtol)def test_small_angle_x(self, device, dtype, atol, rtol):theta = 1.0e-2quaternion = torch.tensor((np.cos(theta / 2.0), np.sin(theta / 2.0), 0.0, 0.0), device=device, dtype=dtype)expected = torch.tensor((theta, 0.0, 0.0), device=device, dtype=dtype)- angle_axis = kornia.geometry.conversions.quaternion_to_angle_axis(quaternion)- assert_close(angle_axis, expected, atol=atol, rtol=rtol)+ axis_angle = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)+ assert_close(axis_angle, expected, atol=atol, rtol=rtol)def test_small_angle_y(self, device, dtype, atol, rtol):theta = 1.0e-2quaternion = torch.tensor((np.cos(theta / 2), 0.0, np.sin(theta / 2), 0.0), device=device, dtype=dtype)expected = torch.tensor((0.0, theta, 0.0), device=device, dtype=dtype)- angle_axis = kornia.geometry.conversions.quaternion_to_angle_axis(quaternion)- assert_close(angle_axis, expected, atol=atol, rtol=rtol)+ axis_angle = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)+ assert_close(axis_angle, expected, atol=atol, rtol=rtol)def test_small_angle_z(self, device, dtype, atol, rtol):theta = 1.0e-2quaternion = torch.tensor((np.cos(theta / 2), 0.0, 0.0, np.sin(theta / 2)), device=device, dtype=dtype)expected = torch.tensor((0.0, 0.0, theta), device=device, dtype=dtype)- angle_axis = kornia.geometry.conversions.quaternion_to_angle_axis(quaternion)- assert_close(angle_axis, expected, atol=atol, rtol=rtol)+ axis_angle = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)+ assert_close(axis_angle, expected, atol=atol, rtol=rtol)def test_gradcheck(self, device, dtype):eps = torch.finfo(dtype).eps@@ -179,7 +179,7 @@ class TestQuaternionToAngleAxis:quaternion = tensor_to_gradcheck_var(quaternion)# evaluate function gradientassert gradcheck(- partial(kornia.geometry.conversions.quaternion_to_angle_axis),+ partial(kornia.geometry.conversions.quaternion_to_axis_angle),(quaternion,),raise_exception=True,fast_mode=True,@@ -444,27 +444,27 @@ class TestQuaternionExpToLog:class TestAngleAxisToRotationMatrix:@pytest.mark.parametrize("batch_size", (1, 2, 5))- def test_rand_angle_axis_gradcheck(self, batch_size, device, dtype, atol, rtol):+ def test_rand_axis_angle_gradcheck(self, batch_size, device, dtype, atol, rtol):# generate input data- angle_axis = torch.rand(batch_size, 3, device=device, dtype=dtype)+ axis_angle = torch.rand(batch_size, 3, device=device, dtype=dtype)eye_batch = create_eye_batch(batch_size, 3, device=device, dtype=dtype)# apply transform- rotation_matrix = kornia.geometry.conversions.angle_axis_to_rotation_matrix(angle_axis)+ rotation_matrix = kornia.geometry.conversions.axis_angle_to_rotation_matrix(axis_angle)rotation_matrix_eye = torch.matmul(rotation_matrix, rotation_matrix.transpose(-2, -1))assert_close(rotation_matrix_eye, eye_batch, atol=atol, rtol=rtol)# evaluate function gradient- angle_axis = tensor_to_gradcheck_var(angle_axis) # to var+ axis_angle = tensor_to_gradcheck_var(axis_angle) # to varassert gradcheck(- kornia.geometry.conversions.angle_axis_to_rotation_matrix,- (angle_axis,),+ kornia.geometry.conversions.axis_angle_to_rotation_matrix,+ (axis_angle,),raise_exception=True,fast_mode=True,)- def test_angle_axis_to_rotation_matrix(self, device, dtype, atol, rtol):+ def test_axis_angle_to_rotation_matrix(self, device, dtype, atol, rtol):rmat_1 = torch.tensor(((-0.30382753, -0.95095137, -0.05814062),@@ -489,7 +489,7 @@ class TestAngleAxisToRotationMatrix:rmat = torch.stack((rmat_2, rmat_1), dim=0)rvec = torch.stack((rvec_2, rvec_1), dim=0)- assert_close(kornia.geometry.conversions.angle_axis_to_rotation_matrix(rvec), rmat, atol=atol, rtol=rtol)+ assert_close(kornia.geometry.conversions.axis_angle_to_rotation_matrix(rvec), rmat, atol=atol, rtol=rtol)class TestRotationMatrixToAngleAxis:@@ -513,13 +513,13 @@ class TestRotationMatrixToAngleAxis:# evaluate function gradientrotation_matrix = tensor_to_gradcheck_var(rotation_matrix) # to varassert gradcheck(- kornia.geometry.conversions.rotation_matrix_to_angle_axis,+ kornia.geometry.conversions.rotation_matrix_to_axis_angle,(rotation_matrix,),raise_exception=True,fast_mode=True,)- def test_rotation_matrix_to_angle_axis(self, device, dtype, atol, rtol):+ def test_rotation_matrix_to_axis_angle(self, device, dtype, atol, rtol):rmat_1 = torch.tensor(((-0.30382753, -0.95095137, -0.05814062),@@ -544,7 +544,7 @@ class TestRotationMatrixToAngleAxis:rmat = torch.stack((rmat_2, rmat_1), dim=0)rvec = torch.stack((rvec_2, rvec_1), dim=0)- assert_close(kornia.geometry.conversions.rotation_matrix_to_angle_axis(rmat), rvec, atol=atol, rtol=rtol)+ assert_close(kornia.geometry.conversions.rotation_matrix_to_axis_angle(rmat), rvec, atol=atol, rtol=rtol)def test_pi():@@ -1099,7 +1099,7 @@ class TestCamtoworldGraphicsToVision:# generate input datat_vis = torch.tensor([2, 3, 4], device=device, dtype=dtype).view(1, 3, 1).repeat(batch_size, 1, 1)angles = torch.tensor([0, kornia.pi / 2.0, 0.0], device=device, dtype=dtype)[None]- R_vis = kornia.geometry.angle_axis_to_rotation_matrix(angles).repeat(batch_size, 1, 1)+ R_vis = kornia.geometry.axis_angle_to_rotation_matrix(angles).repeat(batch_size, 1, 1)K_vis = Rt_to_matrix4x4(R_vis, t_vis)K_graf = camtoworld_vision_to_graphics_4x4(K_vis)@@ -1128,7 +1128,7 @@ class TestCamtoworldGraphicsToVision:def test_gradcheck(self, batch_size, device, dtype):t_vis = torch.tensor([2, 3, 4], device=device, dtype=dtype).view(1, 3, 1).repeat(batch_size, 1, 1)angles = torch.tensor([0, kornia.pi / 2.0, 0.0], device=device, dtype=dtype)[None]- R_vis = kornia.geometry.angle_axis_to_rotation_matrix(angles).repeat(batch_size, 1, 1)+ R_vis = kornia.geometry.axis_angle_to_rotation_matrix(angles).repeat(batch_size, 1, 1)K_vis = Rt_to_matrix4x4(R_vis, t_vis)assert gradcheck(camtoworld_graphics_to_vision_4x4, (tensor_to_gradcheck_var(K_vis)), raise_exception=True, fast_mode=True@@ -1144,7 +1144,7 @@ class TestCamtoworldRtToPoseRt:# generate input datat = torch.tensor([2, 3, 4], device=device, dtype=dtype).view(1, 3, 1).repeat(batch_size, 1, 1)angles = torch.tensor([0, kornia.pi / 2.0, 0.0], device=device, dtype=dtype)[None]- R = kornia.geometry.angle_axis_to_rotation_matrix(angles).repeat(batch_size, 1, 1)+ R = kornia.geometry.axis_angle_to_rotation_matrix(angles).repeat(batch_size, 1, 1)Rp, tp = camtoworld_to_worldtocam_Rt(R, t)@@ -1163,7 +1163,7 @@ class TestCamtoworldRtToPoseRt:def test_gradcheck(self, batch_size, device, dtype):t = torch.tensor([2, 3, 4], device=device, dtype=dtype).view(1, 3, 1).repeat(batch_size, 1, 1)angles = torch.tensor([0, kornia.pi / 2.0, 0.0], device=device, dtype=dtype)[None]- R = kornia.geometry.angle_axis_to_rotation_matrix(angles).repeat(batch_size, 1, 1)+ R = kornia.geometry.axis_angle_to_rotation_matrix(angles).repeat(batch_size, 1, 1)assert gradcheck(camtoworld_to_worldtocam_Rt,(tensor_to_gradcheck_var(R), tensor_to_gradcheck_var(t)),@@ -1184,11 +1184,11 @@ class TestCARKitToColmap:t = torch.tensor([1, 0, 0], device=device, dtype=dtype).view(1, 3, 1)ang_deg = torch.tensor([45, 60.0, 0.0], device=device, dtype=dtype)[None]ang_rad = kornia.geometry.conversions.deg2rad(ang_deg)- qvec = kornia.geometry.angle_axis_to_quaternion(ang_rad)+ qvec = kornia.geometry.axis_angle_to_quaternion(ang_rad)q_colmap, t_colmap = ARKitQTVecs_to_ColmapQTVecs(qvec, t)- angles_colmap = kornia.geometry.conversions.quaternion_to_angle_axis(q_colmap)+ angles_colmap = kornia.geometry.conversions.quaternion_to_axis_angle(q_colmap)angles_colmap = kornia.geometry.conversions.rad2deg(angles_colmap)expected_angles = torch.tensor([[116.8870620728, 0.0, -71.7524719238]], device=device, dtype=dtype)expected_t = torch.tensor([[[-0.5256], [0.3558], [0.7727]]], device=device, dtype=dtype)diff --git a/test/integration/test_conversions.py b/test/integration/test_conversions.pyindex 51a1ffcb6..98a045e25 100644--- a/test/integration/test_conversions.py+++ b/test/integration/test_conversions.py@@ -24,37 +24,37 @@ def rtol(device, dtype):class TestAngleAxisToQuaternionToAngleAxis:def test_zero_angle(self, device, dtype, atol, rtol):- angle_axis = torch.tensor((0.0, 0.0, 0.0), device=device, dtype=dtype)- quaternion = kornia.geometry.conversions.angle_axis_to_quaternion(angle_axis)- angle_axis_hat = kornia.geometry.conversions.quaternion_to_angle_axis(quaternion)- assert_close(angle_axis_hat, angle_axis, atol=atol, rtol=rtol)+ axis_angle = torch.tensor((0.0, 0.0, 0.0), device=device, dtype=dtype)+ quaternion = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)+ axis_angle_hat = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)+ assert_close(axis_angle_hat, axis_angle, atol=atol, rtol=rtol)@pytest.mark.parametrize("axis", (0, 1, 2))def test_small_angle(self, axis, device, dtype, atol, rtol):theta = 1.0e-2array = [0.0, 0.0, 0.0]array[axis] = theta- angle_axis = torch.tensor(array, device=device, dtype=dtype)- quaternion = kornia.geometry.conversions.angle_axis_to_quaternion(angle_axis)- angle_axis_hat = kornia.geometry.conversions.quaternion_to_angle_axis(quaternion)- assert_close(angle_axis_hat, angle_axis, atol=atol, rtol=rtol)+ axis_angle = torch.tensor(array, device=device, dtype=dtype)+ quaternion = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)+ axis_angle_hat = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)+ assert_close(axis_angle_hat, axis_angle, atol=atol, rtol=rtol)@pytest.mark.parametrize("axis", (0, 1, 2))def test_rotation(self, axis, device, dtype, atol, rtol):# half_sqrt2 = 0.5 * np.sqrt(2)array = [0.0, 0.0, 0.0]array[axis] = kornia.pi / 2.0- angle_axis = torch.tensor(array, device=device, dtype=dtype)- quaternion = kornia.geometry.conversions.angle_axis_to_quaternion(angle_axis)- angle_axis_hat = kornia.geometry.conversions.quaternion_to_angle_axis(quaternion)- assert_close(angle_axis_hat, angle_axis, atol=atol, rtol=rtol)+ axis_angle = torch.tensor(array, device=device, dtype=dtype)+ quaternion = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)+ axis_angle_hat = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)+ assert_close(axis_angle_hat, axis_angle, atol=atol, rtol=rtol)class TestQuaternionToAngleAxisToQuaternion:def test_unit_quaternion(self, device, dtype, atol, rtol):quaternion = torch.tensor((1.0, 0.0, 0.0, 0.0), device=device, dtype=dtype)- angle_axis = kornia.geometry.conversions.quaternion_to_angle_axis(quaternion)- quaternion_hat = kornia.geometry.conversions.angle_axis_to_quaternion(angle_axis)+ axis_angle = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)+ quaternion_hat = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)assert_close(quaternion_hat, quaternion, atol=atol, rtol=rtol)@pytest.mark.parametrize("axis", (0, 1, 2))@@ -62,8 +62,8 @@ class TestQuaternionToAngleAxisToQuaternion:array = [0.0, 0.0, 0.0, 0.0]array[1 + axis] = 1.0quaternion = torch.tensor(array, device=device, dtype=dtype)- angle_axis = kornia.geometry.conversions.quaternion_to_angle_axis(quaternion)- quaternion_hat = kornia.geometry.conversions.angle_axis_to_quaternion(angle_axis)+ axis_angle = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)+ quaternion_hat = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)assert_close(quaternion_hat, quaternion, atol=atol, rtol=rtol)@pytest.mark.parametrize("axis", (0, 1, 2))@@ -72,8 +72,8 @@ class TestQuaternionToAngleAxisToQuaternion:array = [np.cos(theta / 2), 0.0, 0.0, 0.0]array[1 + axis] = np.sin(theta / 2.0)quaternion = torch.tensor(array, device=device, dtype=dtype)- angle_axis = kornia.geometry.conversions.quaternion_to_angle_axis(quaternion)- quaternion_hat = kornia.geometry.conversions.angle_axis_to_quaternion(angle_axis)+ axis_angle = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)+ quaternion_hat = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)assert_close(quaternion_hat, quaternion, atol=atol, rtol=rtol)@@ -89,14 +89,14 @@ class TestQuaternionToRotationMatrixToAngleAxis:assert mm.shape[-1] == 3assert mm.shape[-2] == 3- angle_axis = kornia.geometry.conversions.rotation_matrix_to_angle_axis(mm)- assert angle_axis.shape[-1] == 3- angle_axis_expected = [[0.0, 0.0, 0.0]]- angle_axis_expected[0][axis] = kornia.pi- angle_axis_expected = torch.tensor(angle_axis_expected, device=device, dtype=dtype)- assert_close(angle_axis, angle_axis_expected, atol=atol, rtol=rtol)+ axis_angle = kornia.geometry.conversions.rotation_matrix_to_axis_angle(mm)+ assert axis_angle.shape[-1] == 3+ axis_angle_expected = [[0.0, 0.0, 0.0]]+ axis_angle_expected[0][axis] = kornia.pi+ axis_angle_expected = torch.tensor(axis_angle_expected, device=device, dtype=dtype)+ assert_close(axis_angle, axis_angle_expected, atol=atol, rtol=rtol)- quaternion_hat = kornia.geometry.conversions.angle_axis_to_quaternion(angle_axis)+ quaternion_hat = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)assert_close(quaternion_hat, quaternion, atol=atol, rtol=rtol)@pytest.mark.parametrize("axis", (0, 1, 2))@@ -106,10 +106,10 @@ class TestQuaternionToRotationMatrixToAngleAxis:quaternion = torch.tensor(array, device=device, dtype=dtype)assert quaternion.shape[-1] == 4- angle_axis = kornia.geometry.conversions.quaternion_to_angle_axis(quaternion)- assert angle_axis.shape[-1] == 3+ axis_angle = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)+ assert axis_angle.shape[-1] == 3- rot_m = kornia.geometry.conversions.angle_axis_to_rotation_matrix(angle_axis)+ rot_m = kornia.geometry.conversions.axis_angle_to_rotation_matrix(axis_angle)assert rot_m.shape[-1] == 3assert rot_m.shape[-2] == 3@@ -120,35 +120,35 @@ class TestQuaternionToRotationMatrixToAngleAxis:def test_triplet_amq(self, axis, device, dtype, atol, rtol):array = [[0.0, 0.0, 0.0]]array[0][axis] = kornia.pi / 2.0- angle_axis = torch.tensor(array, device=device, dtype=dtype)- assert angle_axis.shape[-1] == 3+ axis_angle = torch.tensor(array, device=device, dtype=dtype)+ assert axis_angle.shape[-1] == 3- rot_m = kornia.geometry.conversions.angle_axis_to_rotation_matrix(angle_axis)+ rot_m = kornia.geometry.conversions.axis_angle_to_rotation_matrix(axis_angle)assert rot_m.shape[-1] == 3assert rot_m.shape[-2] == 3quaternion = kornia.geometry.conversions.rotation_matrix_to_quaternion(rot_m)assert quaternion.shape[-1] == 4- angle_axis_hat = kornia.geometry.conversions.quaternion_to_angle_axis(quaternion)- assert_close(angle_axis_hat, angle_axis, atol=atol, rtol=rtol)+ axis_angle_hat = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)+ assert_close(axis_angle_hat, axis_angle, atol=atol, rtol=rtol)@pytest.mark.parametrize("axis", (0, 1, 2))def test_triplet_aqm(self, axis, device, dtype, atol, rtol):array = [[0.0, 0.0, 0.0]]array[0][axis] = kornia.pi / 2.0- angle_axis = torch.tensor(array, device=device, dtype=dtype)- assert angle_axis.shape[-1] == 3+ axis_angle = torch.tensor(array, device=device, dtype=dtype)+ assert axis_angle.shape[-1] == 3- quaternion = kornia.geometry.conversions.angle_axis_to_quaternion(angle_axis)+ quaternion = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)assert quaternion.shape[-1] == 4rot_m = kornia.geometry.conversions.quaternion_to_rotation_matrix(quaternion)assert rot_m.shape[-1] == 3assert rot_m.shape[-2] == 3- angle_axis_hat = kornia.geometry.conversions.rotation_matrix_to_angle_axis(rot_m)- assert_close(angle_axis_hat, angle_axis, atol=atol, rtol=rtol)+ axis_angle_hat = kornia.geometry.conversions.rotation_matrix_to_axis_angle(rot_m)+ assert_close(axis_angle_hat, axis_angle, atol=atol, rtol=rtol)class TestAngleOfRotations:@@ -262,18 +262,18 @@ class TestAngleOfRotations:@pytest.mark.parametrize('axis_name', ('x', 'y', 'z'))@pytest.mark.parametrize("angle_deg", (-179.9, -90.0, -45.0, 0, 45, 90, 179.9))- def test_angle_axis(self, axis_name, angle_deg, device, dtype, atol, rtol):+ def test_axis_angle(self, axis_name, angle_deg, device, dtype, atol, rtol):angle = (angle_deg * kornia.pi / 180.0).to(dtype).to(device).repeat(2, 1)rot_m, axis = TestAngleOfRotations.axis_and_angle_to_rotation_matrix(axis_name=axis_name, angle=angle, device=device, dtype=dtype)- angle_axis = kornia.geometry.conversions.rotation_matrix_to_angle_axis(rot_m)- # compute angle_axis rotation angle- angle_hat = angle_axis.norm(p=2, dim=-1, keepdim=True)- # invert angle, if angle_axis axis points in the opposite direction of the original axis- dots = (angle_axis * axis).sum(dim=-1, keepdim=True)+ axis_angle = kornia.geometry.conversions.rotation_matrix_to_axis_angle(rot_m)+ # compute axis_angle rotation angle+ angle_hat = axis_angle.norm(p=2, dim=-1, keepdim=True)+ # invert angle, if axis_angle axis points in the opposite direction of the original axis+ dots = (axis_angle * axis).sum(dim=-1, keepdim=True)angle_hat = torch.where(dots < 0.0, angle_hat * -1.0, angle_hat)- # angle_axis angle should match input angle+ # axis_angle angle should match input angleassert_close(angle_hat, angle, atol=atol, rtol=rtol)# magnitude of angle should match matrix rotation anglematrix_angle_abs = TestAngleOfRotations.matrix_angle_abs(rot_m)@@ -290,17 +290,17 @@ class TestAngleOfRotations:)quaternion = kornia.geometry.conversions.rotation_matrix_to_quaternion(rot_m, eps=eps)log_q = kornia.geometry.conversions.quaternion_exp_to_log(quaternion, eps=eps)- # compute angle_axis rotation angle+ # compute axis_angle rotation angleangle_hat = 2.0 * log_q.norm(p=2, dim=-1, keepdim=True)# make sure it lands between [-pi..pi)mask = pi < angle_hatwhile torch.any(mask):angle_hat = torch.where(mask, angle_hat - 2.0 * kornia.pi, angle_hat)mask = pi < angle_hat- # invert angle, if angle_axis axis points in the opposite direction of the original axis+ # invert angle, if axis_angle axis points in the opposite direction of the original axisdots = (log_q * axis).sum(dim=-1, keepdim=True)angle_hat = torch.where(dots < 0.0, angle_hat * -1.0, angle_hat)- # angle_axis angle should match input angle+ # axis_angle angle should match input angleassert_close(angle_hat, angle, atol=atol, rtol=rtol)# magnitude of angle should match matrix rotation anglematrix_angle_abs = TestAngleOfRotations.matrix_angle_abs(rot_m)