Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@pytest.mark.skip(reason="turn off all jit for a while")
def test_jit(self, device):
@torch.jit.script
def op_script(input):
return kornia.quaternion_to_rotation_matrix(input)
quaternion = torch.tensor([0., 0., 1., 0.]).to(device)
actual = op_script(quaternion)
expected = kornia.quaternion_to_rotation_matrix(quaternion)
assert_allclose(actual, expected)
def test_jit(self, device):
@torch.jit.script
def op_script(input):
return kornia.quaternion_to_rotation_matrix(input)
quaternion = torch.tensor([0., 0., 1., 0.]).to(device)
actual = op_script(quaternion)
expected = kornia.quaternion_to_rotation_matrix(quaternion)
assert_allclose(actual, expected)
def test_unit_quaternion(self, device):
quaternion = torch.tensor([0., 0., 0., 1.]).to(device)
expected = torch.tensor([
[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.],
]).to(device)
matrix = kornia.quaternion_to_rotation_matrix(quaternion)
assert_allclose(matrix, expected)
def test_gradcheck(self, device):
quaternion = torch.tensor([0., 0., 0., 1.]).to(device)
quaternion = tensor_to_gradcheck_var(quaternion)
# evaluate function gradient
assert gradcheck(kornia.quaternion_to_rotation_matrix, (quaternion,),
raise_exception=True)
def test_y_rotation(self, device):
quaternion = torch.tensor([0., 1., 0., 0.]).to(device)
expected = torch.tensor([
[-1., 0., 0.],
[0., 1., 0.],
[0., 0., -1.],
]).to(device)
matrix = kornia.quaternion_to_rotation_matrix(quaternion)
assert_allclose(matrix, expected)
def test_x_rotation(self, device):
quaternion = torch.tensor([1., 0., 0., 0.]).to(device)
expected = torch.tensor([
[1., 0., 0.],
[0., -1., 0.],
[0., 0., -1.],
]).to(device)
matrix = kornia.quaternion_to_rotation_matrix(quaternion)
assert_allclose(matrix, expected)
@torch.jit.script
def op_script(input):
return kornia.quaternion_to_rotation_matrix(input)
def op_script(input):
return kornia.quaternion_to_rotation_matrix(input)
def test_z_rotation(self, device):
quaternion = torch.tensor([0., 0., 1., 0.]).to(device)
expected = torch.tensor([
[-1., 0., 0.],
[0., -1., 0.],
[0., 0., 1.],
]).to(device)
matrix = kornia.quaternion_to_rotation_matrix(quaternion)
assert_allclose(matrix, expected)