Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

add exception test for se2 + small bug fix (#2160)

Christie Jacobb3921fe03734
diff --git a/kornia/geometry/liegroup/_utils.py b/kornia/geometry/liegroup/_utils.py
index 23c4420b0..9af19e934 100644
--- a/kornia/geometry/liegroup/_utils.py
+++ b/kornia/geometry/liegroup/_utils.py
@@ -9,7 +9,7 @@ def check_so2_z_shape(z):
def check_so2_t_shape(t):
t_shape = t.shape
len_t_shape = len(t_shape)
- if ((len_t_shape == 2) and (t_shape[1] > 2)) or ((len_t_shape == 1) and (t_shape[0] != 2)) or (len_t_shape > 2):
+ if ((len_t_shape == 2) and (t_shape[1] != 2)) or ((len_t_shape == 1) and (t_shape[0] != 2)) or (len_t_shape > 2):
raise ValueError(f"Invalid translation shape, we expect [B, 2], or [2] Got: {t_shape}")
diff --git a/test/geometry/liegroup/test_se2.py b/test/geometry/liegroup/test_se2.py
index ae2003c43..d58f21017 100644
--- a/test/geometry/liegroup/test_se2.py
+++ b/test/geometry/liegroup/test_se2.py
@@ -43,9 +43,36 @@ class TestSe2(BaseTester):
assert s.inverse().so2.z.shape == input_shape
assert s.inverse().t.shape == t_input_shape
- # TODO: implement me
- def test_exception(self, device, dtype):
- pass
+ @pytest.mark.parametrize("batch_size", (1, 2, 5))
+ def test_exception(self, device, dtype, batch_size):
+ with pytest.raises(ValueError):
+ r = So2.random(batch_size)
+ t1 = torch.randn((batch_size, 1), dtype=dtype, device=device)
+ t2 = torch.randn((batch_size, 3), dtype=dtype, device=device)
+ Se2(r, t1)
+ Se2(r, t2)
+ with pytest.raises(ValueError):
+ theta = torch.rand((batch_size, 2), dtype=dtype, device=device)
+ Se2.exp(theta)
+ with pytest.raises(ValueError):
+ v = torch.rand((batch_size, 2), dtype=dtype, device=device)
+ Se2.hat(v)
+ with pytest.raises(ValueError):
+ omega = torch.rand((4, 4), dtype=dtype, device=device)
+ Se2.vee(omega)
+ with pytest.raises(TypeError):
+ Se2.identity(1, device, dtype) * [1.0, 2.0, 1.0]
+ with pytest.raises(ValueError):
+ theta = torch.rand((batch_size, 2), dtype=dtype, device=device)
+ Se2.hat(theta)
+ with pytest.raises(Exception):
+ Se2.identity(batch_size=0)
+ with pytest.raises(Exception):
+ Se2.random(batch_size=0)
+ with pytest.raises(Exception):
+ x = torch.rand(5, dtype=dtype, device=device)
+ y = torch.rand(3, dtype=dtype, device=device)
+ Se2.trans(x, y)
# TODO: implement me
def test_gradcheck(self, device):