示例#1
0
 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.angle_axis_to_quaternion(
         angle_axis, order=QuaternionCoeffOrder.WXYZ)
     angle_axis_hat = kornia.quaternion_to_angle_axis(
         quaternion, order=QuaternionCoeffOrder.WXYZ)
     assert_allclose(angle_axis_hat, angle_axis, atol=atol, rtol=rtol)
示例#2
0
 def test_y_rotation(self, device, dtype):
     quaternion = torch.tensor([0., 0., 1., 0.], device=device, dtype=dtype)
     expected = torch.tensor([0., kornia.pi, 0.],
                             device=device,
                             dtype=dtype)
     angle_axis = kornia.quaternion_to_angle_axis(quaternion)
     assert_allclose(angle_axis, expected, atol=1e-4, rtol=1e-4)
示例#3
0
 def test_unit_quaternion(self, device, dtype, atol, rtol):
     quaternion = torch.tensor((1., 0., 0., 0.), device=device, dtype=dtype)
     angle_axis = kornia.quaternion_to_angle_axis(
         quaternion, order=QuaternionCoeffOrder.WXYZ)
     quaternion_hat = kornia.angle_axis_to_quaternion(
         angle_axis, order=QuaternionCoeffOrder.WXYZ)
     assert_allclose(quaternion_hat, quaternion, atol=atol, rtol=rtol)
示例#4
0
 def test_unit_quaternion_xyzw(self, device, dtype, atol, rtol):
     quaternion = torch.tensor((0.0, 0.0, 0.0, 1.0), device=device, dtype=dtype)
     with pytest.warns(UserWarning):
         angle_axis = kornia.quaternion_to_angle_axis(quaternion, order=QuaternionCoeffOrder.XYZW)
     with pytest.warns(UserWarning):
         quaternion_hat = kornia.angle_axis_to_quaternion(angle_axis, order=QuaternionCoeffOrder.XYZW)
     assert_close(quaternion_hat, quaternion, atol=atol, rtol=rtol)
示例#5
0
 def test_small_angle(self, device, dtype):
     theta = 1e-2
     quaternion = torch.tensor(
         [np.cos(theta / 2), np.sin(theta / 2), 0., 0.]).to(device, dtype)
     expected = torch.tensor([theta, 0., 0.]).to(device, dtype)
     angle_axis = kornia.quaternion_to_angle_axis(quaternion)
     assert_allclose(angle_axis, expected)
示例#6
0
 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.angle_axis_to_quaternion(angle_axis, order=QuaternionCoeffOrder.WXYZ)
     angle_axis_hat = kornia.quaternion_to_angle_axis(quaternion, order=QuaternionCoeffOrder.WXYZ)
     assert_close(angle_axis_hat, angle_axis, atol=atol, rtol=rtol)
示例#7
0
 def test_small_angle(self, axis, device, dtype, atol, rtol):
     theta = 1.0e-2
     array = [0.0, 0.0, 0.0]
     array[axis] = theta
     angle_axis = torch.tensor(array, device=device, dtype=dtype)
     quaternion = kornia.angle_axis_to_quaternion(angle_axis, order=QuaternionCoeffOrder.WXYZ)
     angle_axis_hat = kornia.quaternion_to_angle_axis(quaternion, order=QuaternionCoeffOrder.WXYZ)
     assert_close(angle_axis_hat, angle_axis, atol=atol, rtol=rtol)
示例#8
0
 def test_rotation_xyzw(self, axis, device, dtype, atol, rtol):
     array = [0.0, 0.0, 0.0, 0.0]
     array[axis] = 1.0
     quaternion = torch.tensor(array, device=device, dtype=dtype)
     with pytest.warns(UserWarning):
         angle_axis = kornia.quaternion_to_angle_axis(quaternion, order=QuaternionCoeffOrder.XYZW)
     with pytest.warns(UserWarning):
         quaternion_hat = kornia.angle_axis_to_quaternion(angle_axis, order=QuaternionCoeffOrder.XYZW)
     assert_close(quaternion_hat, quaternion, atol=atol, rtol=rtol)
示例#9
0
 def test_small_angle_xyzw(self, axis, device, dtype, atol, rtol):
     theta = 1.0e-2
     array = [0.0, 0.0, 0.0, np.cos(theta / 2)]
     array[axis] = np.sin(theta / 2.0)
     quaternion = torch.tensor(array, device=device, dtype=dtype)
     with pytest.warns(UserWarning):
         angle_axis = kornia.quaternion_to_angle_axis(quaternion, order=QuaternionCoeffOrder.XYZW)
     with pytest.warns(UserWarning):
         quaternion_hat = kornia.angle_axis_to_quaternion(angle_axis, order=QuaternionCoeffOrder.XYZW)
     assert_close(quaternion_hat, quaternion, atol=atol, rtol=rtol)
示例#10
0
    def test_rotation(self, axis, device, dtype, atol, rtol):
        array = [0.0, 0.0, 0.0, 0.0]
        array[1 + axis] = 1.0
        quaternion = torch.tensor(array, device=device, dtype=dtype)
        angle_axis = kornia.quaternion_to_angle_axis(quaternion, order=QuaternionCoeffOrder.WXYZ)
        quaternion_hat = kornia.angle_axis_to_quaternion(angle_axis, order=QuaternionCoeffOrder.WXYZ)
        assert_close(quaternion_hat, quaternion, atol=atol, rtol=rtol)

        # just to be sure, check that mixing orders fails
        with pytest.warns(UserWarning):
            quaternion_hat_wrong = kornia.angle_axis_to_quaternion(angle_axis, order=QuaternionCoeffOrder.XYZW)
        assert not torch.allclose(quaternion_hat_wrong, quaternion, atol=atol, rtol=rtol)
示例#11
0
    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

        rot_m = kornia.angle_axis_to_rotation_matrix(angle_axis)
        assert rot_m.shape[-1] == 3
        assert rot_m.shape[-2] == 3

        quaternion = kornia.rotation_matrix_to_quaternion(rot_m, order=QuaternionCoeffOrder.WXYZ)
        assert quaternion.shape[-1] == 4

        angle_axis_hat = kornia.quaternion_to_angle_axis(quaternion, order=QuaternionCoeffOrder.WXYZ)
        assert_close(angle_axis_hat, angle_axis, atol=atol, rtol=rtol)
示例#12
0
    def test_small_angle(self, axis, device, dtype, atol, rtol):
        theta = 1.e-2
        array = [np.cos(theta / 2), 0., 0., 0.]
        array[1 + axis] = np.sin(theta / 2.)
        quaternion = torch.tensor(array, device=device, dtype=dtype)
        angle_axis = kornia.quaternion_to_angle_axis(
            quaternion, order=QuaternionCoeffOrder.WXYZ)
        quaternion_hat = kornia.angle_axis_to_quaternion(
            angle_axis, order=QuaternionCoeffOrder.WXYZ)
        assert_allclose(quaternion_hat, quaternion, atol=atol, rtol=rtol)

        # just to be sure, check that mixing orders fails
        with pytest.warns(UserWarning):
            quaternion_hat_wrong = kornia.angle_axis_to_quaternion(
                angle_axis, order=QuaternionCoeffOrder.XYZW)
        assert not torch.allclose(
            quaternion_hat_wrong, quaternion, atol=atol, rtol=rtol)
示例#13
0
    def test_triplet_qam_xyzw(self, axis, device, dtype, atol, rtol):
        array = [[0.0, 0.0, 0.0, 0.0]]
        array[0][axis] = 1.0
        quaternion = torch.tensor(array, device=device, dtype=dtype)
        assert quaternion.shape[-1] == 4

        with pytest.warns(UserWarning):
            angle_axis = kornia.quaternion_to_angle_axis(quaternion, order=QuaternionCoeffOrder.XYZW)
        assert angle_axis.shape[-1] == 3

        rot_m = kornia.angle_axis_to_rotation_matrix(angle_axis)
        assert rot_m.shape[-1] == 3
        assert rot_m.shape[-2] == 3

        with pytest.warns(UserWarning):
            quaternion_hat = kornia.rotation_matrix_to_quaternion(rot_m, order=QuaternionCoeffOrder.XYZW)
        assert_close(quaternion_hat, quaternion, atol=atol, rtol=rtol)
示例#14
0
 def test_smoke_batch(self, batch_size, device, dtype):
     quaternion = torch.zeros(batch_size, 4, device=device, dtype=dtype)
     angle_axis = kornia.quaternion_to_angle_axis(quaternion)
     assert angle_axis.shape == (batch_size, 3)
示例#15
0
 def test_y_rotation(self, device):
     quaternion = torch.tensor([0., 0., 1., 0.]).to(device)
     expected = torch.tensor([0., kornia.pi, 0.]).to(device)
     angle_axis = kornia.quaternion_to_angle_axis(quaternion)
     assert_allclose(angle_axis, expected)
示例#16
0
 def test_small_angle(self):
     theta = 1e-2
     quaternion = torch.Tensor([np.cos(theta / 2), np.sin(theta / 2), 0, 0])
     expected = torch.Tensor([theta, 0, 0])
     angle_axis = kornia.quaternion_to_angle_axis(quaternion)
     assert utils.check_equal_torch(angle_axis, expected)
示例#17
0
 def test_smoke(self, device, dtype):
     quaternion = torch.zeros(4, device=device, dtype=dtype)
     angle_axis = kornia.quaternion_to_angle_axis(quaternion)
     assert angle_axis.shape == (3, )
示例#18
0
 def test_z_rotation(self):
     quaternion = torch.Tensor([np.sqrt(3) / 2, 0, 0, 0.5])
     expected = torch.Tensor([0, 0, kornia.pi / 3])
     angle_axis = kornia.quaternion_to_angle_axis(quaternion)
     assert utils.check_equal_torch(angle_axis, expected)
示例#19
0
 def test_y_rotation(self):
     quaternion = torch.Tensor([0, 0, 1, 0])
     expected = torch.Tensor([0, kornia.pi, 0])
     angle_axis = kornia.quaternion_to_angle_axis(quaternion)
     assert utils.check_equal_torch(angle_axis, expected)
示例#20
0
 def test_smoke(self):
     quaternion = torch.zeros(4)
     angle_axis = kornia.quaternion_to_angle_axis(quaternion)
     assert angle_axis.shape == (3,)
示例#21
0
 def test_y_rotation(self):
     quaternion = torch.Tensor([0, 0, 1, 0])
     expected = torch.Tensor([0, kornia.pi, 0])
     angle_axis = kornia.quaternion_to_angle_axis(quaternion)
     assert_allclose(angle_axis, expected)
示例#22
0
 def test_z_rotation(self, device, dtype):
     quaternion = torch.tensor([np.sqrt(3) / 2, 0., 0.,
                                0.5]).to(device, dtype)
     expected = torch.tensor([0., 0., kornia.pi / 3]).to(device, dtype)
     angle_axis = kornia.quaternion_to_angle_axis(quaternion)
     assert_allclose(angle_axis, expected)