π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
test(geometry): fill the empty exception and cardinality stubs in the So3 and Se3 tests (#6292)
Adarsh Mishrac17c2e26deec
diff --git a/tests/geometry/liegroup/test_se3.py b/tests/geometry/liegroup/test_se3.pyindex 829db2b1a..5113aec83 100644--- a/tests/geometry/liegroup/test_se3.py+++ b/tests/geometry/liegroup/test_se3.py@@ -20,7 +20,7 @@ import mathimport pytestimport torch-from kornia.core.exceptions import DeviceError, TypeCheckError+from kornia.core.exceptions import DeviceError, ShapeError, TypeCheckErrorfrom kornia.geometry.conversions import euler_from_quaternion, rotation_matrix_to_quaternionfrom kornia.geometry.liegroup import Se3, So3from kornia.geometry.pose import NamedPose@@ -79,9 +79,18 @@ class TestSe3(BaseTester):se: Se3 = self._make_rand_se3d(device, dtype, batch_size)assert se.r.q.shape[0] == batch_size- # TODO: implement medef test_exception(self, device, dtype):- pass+ with pytest.raises(ShapeError, match=r"Shape mismatch at dimension 1: expected 3, got 2"):+ Se3(So3.identity(1, device, dtype), torch.zeros(1, 2, device=device, dtype=dtype))++ with pytest.raises(ShapeError, match=r"Shape mismatch at dimension 1: expected 6, got 5"):+ Se3.exp(torch.zeros(1, 5, device=device, dtype=dtype))++ with pytest.raises(ShapeError, match=r"Shape mismatch at dimension 1: expected 4, got 3"):+ Se3.from_matrix(torch.eye(3, device=device, dtype=dtype).repeat(1, 1, 1))++ with pytest.raises(TypeError, match=r"Unsupported type"):+ Se3(So3.identity(1, device, dtype), torch.zeros(1, 3, device=device, dtype=dtype)) * 4def test_gradcheck(self, device):v = torch.tensor([[1.0, 2.0, 3.0, 0.3, -0.4, 0.5]], device=device, dtype=torch.float64)diff --git a/tests/geometry/liegroup/test_so2.py b/tests/geometry/liegroup/test_so2.pyindex e44464aa3..90a1a2686 100644--- a/tests/geometry/liegroup/test_so2.py+++ b/tests/geometry/liegroup/test_so2.py@@ -166,9 +166,10 @@ class TestSo2(BaseTester):with pytest.raises(BaseError):assert So2.identity(batch_size=0)- # TODO: implement medef test_gradcheck(self, device):- pass+ theta = torch.tensor([[0.4], [-0.3]], device=device, dtype=torch.float64)+ self.gradcheck(lambda x: So2.exp(x).matrix(), (theta,))+ self.gradcheck(lambda x: So2.exp(x).log(), (theta,))# TODO: implement medef test_jit(self, device, dtype):diff --git a/tests/geometry/liegroup/test_so3.py b/tests/geometry/liegroup/test_so3.pyindex 05d51ef80..e32f4935d 100644--- a/tests/geometry/liegroup/test_so3.py+++ b/tests/geometry/liegroup/test_so3.py@@ -21,6 +21,7 @@ import pytestimport torchfrom torch import nn+from kornia.core.exceptions import ShapeError, TypeCheckErrorfrom kornia.geometry.conversions import euler_from_quaternionfrom kornia.geometry.liegroup import So3from kornia.geometry.liegroup.so3 import _so3_small_angle_coefficients@@ -42,13 +43,29 @@ class TestSo3(BaseTester):assert isinstance(s, So3)self.assert_close(s.q.data, q.data)- # TODO: implement me- def test_cardinality(self, device, dtype):- pass+ @pytest.mark.parametrize("batch_size", [1, 2, 5])+ def test_cardinality(self, device, dtype, batch_size):+ so: So3 = So3.random(batch_size, device, dtype)+ assert so.q.shape[0] == batch_size- # TODO: implement medef test_exception(self, device, dtype):- pass+ with pytest.raises(ValueError, match=r"Quaternion input must have last dimension == 4"):+ So3(Quaternion(torch.zeros(1, 3, device=device, dtype=dtype)))++ with pytest.raises(TypeCheckError, match=r"Type mismatch: expected Quaternion"):+ So3(torch.zeros(1, 4, device=device, dtype=dtype))++ with pytest.raises(ShapeError, match=r"Shape mismatch at dimension 1: expected 3, got 2"):+ So3.exp(torch.zeros(1, 2, device=device, dtype=dtype))++ with pytest.raises(ShapeError, match=r"Shape mismatch at dimension 1: expected 4, got 3"):+ So3.from_wxyz(torch.zeros(1, 3, device=device, dtype=dtype))++ with pytest.raises(ValueError, match=r"Input size must be a \(\*, 3, 3\) tensor"):+ So3.from_matrix(torch.zeros(3, device=device, dtype=dtype))++ with pytest.raises(TypeError, match=r"Not So3 or torch.Tensor type"):+ So3.identity(1, device, dtype) * [1.0, 2.0, 3.0]def test_gradcheck(self, device):v = torch.tensor([[0.3, -0.4, 0.5]], device=device, dtype=torch.float64)