π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
apply autopep8 format
edgarriba45c18c10d723
diff --git a/test/test_transformations.py b/test/test_transformations.pyindex 80d146ef0..83b9ddddb 100644--- a/test/test_transformations.py+++ b/test/test_transformations.py@@ -7,12 +7,13 @@ from torch.autograd import gradcheckimport utils # test utilitiesfrom common import TEST_DEVICES+class TestTransformPose:def test_identity(self):pose_1 = torch.eye(4).unsqueeze(0)pose_2 = torch.eye(4).unsqueeze(0)pose_21 = tgm.relative_pose(pose_1, pose_2)- assert utils.check_equal_torch(pose_21, torch.eye(4).unsqueeze(0))+ assert utils.check_equal_torch(pose_21, torch.eye(4).unsqueeze(0))def test_translation(self):offset = 10.@@ -22,7 +23,7 @@ class TestTransformPose:# compute relative posepose_21 = tgm.relative_pose(pose_1, pose_2)- assert utils.check_equal_torch(pose_21[...,:3, -1:], offset)+ assert utils.check_equal_torch(pose_21[..., :3, -1:], offset)def test_rotation(self):pose_1 = torch.eye(4).unsqueeze(0)@@ -39,33 +40,33 @@ class TestTransformPose:@pytest.mark.parametrize("device_type", TEST_DEVICES)@pytest.mark.parametrize("batch_size", [1, 2, 5])def test_integration(self, batch_size, device_type):- pose_1 = torch.eye(4).repeat(batch_size, 1, 1)- pose_1 = pose_1.to(torch.device(device_type))+ pose_1 = torch.eye(4).repeat(batch_size, 1, 1)+ pose_1 = pose_1.to(torch.device(device_type))- pose_2 = torch.eye(4).repeat(batch_size, 1, 1)- pose_2[..., :3, :3] = torch.rand(batch_size, 3, 3)- pose_2[..., :3, -1:] = torch.rand(batch_size, 3, 1)- pose_2 = pose_2.to(torch.device(device_type))+ pose_2 = torch.eye(4).repeat(batch_size, 1, 1)+ pose_2[..., :3, :3] = torch.rand(batch_size, 3, 3)+ pose_2[..., :3, -1:] = torch.rand(batch_size, 3, 1)+ pose_2 = pose_2.to(torch.device(device_type))- pose_21 = tgm.relative_pose(pose_1, pose_2)- assert utils.check_equal_torch(- torch.matmul(pose_21, pose_1), pose_2)+ pose_21 = tgm.relative_pose(pose_1, pose_2)+ assert utils.check_equal_torch(+ torch.matmul(pose_21, pose_1), pose_2)@pytest.mark.skip("Converting a tensor to a Python boolean ...")def test_jit(self):- pose_1 = torch.eye(4).unsqueeze(0)- pose_2 = torch.eye(4).unsqueeze(0)+ pose_1 = torch.eye(4).unsqueeze(0)+ pose_2 = torch.eye(4).unsqueeze(0)- pose_21 = tgm.relative_pose(pose_1, pose_2)- pose_21_jit = torch.jit.trace(- tgm.relative_pose, (pose_1, pose_2,))(pose_1, pose_2)- assert utils.check_equal_torch(pose_21, pose_21_jit)+ pose_21 = tgm.relative_pose(pose_1, pose_2)+ pose_21_jit = torch.jit.trace(+ tgm.relative_pose, (pose_1, pose_2,))(pose_1, pose_2)+ assert utils.check_equal_torch(pose_21, pose_21_jit)def test_gradcheck(self):- pose_1 = torch.eye(4).unsqueeze(0)- pose_2 = torch.eye(4).unsqueeze(0)+ pose_1 = torch.eye(4).unsqueeze(0)+ pose_2 = torch.eye(4).unsqueeze(0)- pose_1 = utils.tensor_to_gradcheck_var(pose_1) # to var- pose_2 = utils.tensor_to_gradcheck_var(pose_2) # to var- assert gradcheck(tgm.relative_pose, (pose_1, pose_2,),- raise_exception=True)+ pose_1 = utils.tensor_to_gradcheck_var(pose_1) # to var+ pose_2 = utils.tensor_to_gradcheck_var(pose_2) # to var+ assert gradcheck(tgm.relative_pose, (pose_1, pose_2,),+ raise_exception=True)diff --git a/torchgeometry/transformations.py b/torchgeometry/transformations.pyindex 119898a22..6c46d9e45 100644--- a/torchgeometry/transformations.py+++ b/torchgeometry/transformations.py@@ -8,19 +8,25 @@ __all__ = []-def relative_pose(pose_1: torch.Tensor, pose_2: torch.Tensor, eps: Optional[float] = 1e-6) -> torch.Tensor:+def relative_pose(pose_1: torch.Tensor, pose_2: torch.Tensor,+ eps: Optional[float] = 1e-6) -> torch.Tensor:r"""Function that computes the relative transformation from a reference- pose :math:`P_1^{\{W\}} = \begin{bmatrix} R_1 & t_1 \\ \mathbf{0} & 1 \end{bmatrix}` to destination :math:`P_2^{\{W\}} = \begin{bmatrix} R_2 & t_2 \\ \mathbf{0} & 1 \end{bmatrix}`.+ pose :math:`P_1^{\{W\}} = \begin{bmatrix} R_1 & t_1 \\ \mathbf{0} & 1+ \end{bmatrix}` to destination :math:`P_2^{\{W\}} = \begin{bmatrix} R_2 &+ t_2 \\ \mathbf{0} & 1 \end{bmatrix}`.The relative transformation is computed as follows:.. math::- P_1^{2} = \begin{bmatrix} R_2 R_1^T & R_1^T (t_2 - t_1) \\ \mathbf{0} & 1\end{bmatrix}+ P_1^{2} = \begin{bmatrix} R_2 R_1^T & R_1^T (t_2 - t_1) \\ \mathbf{0} &+ 1\end{bmatrix}Arguments:- pose_1 (torch.Tensor): reference pose tensor of shape :math:`(N, 4, 4)`.- pose_2 (torch.Tensor): destination pose tensor of shape :math:`(N, 4, 4)`.+ pose_1 (torch.Tensor): reference pose tensor of shape+ :math:`(N, 4, 4)`.+ pose_2 (torch.Tensor): destination pose tensor of shape+ :math:`(N, 4, 4)`.Shape:- Output: :math:`(N, 4, 4)`