Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

test(geometry): rename TestNamedPose.transform_points to test_transform_points (#4940) (#4949)

yi1118e736307c398
diff --git a/tests/geometry/test_pose.py b/tests/geometry/test_pose.py
index 6cc4e9edf..b185d8683 100644
--- a/tests/geometry/test_pose.py
+++ b/tests/geometry/test_pose.py
@@ -15,6 +15,8 @@
# limitations under the License.
#
+import math
+
import pytest
import torch
@@ -117,15 +119,26 @@ class TestNamedPose(BaseTester):
assert a_from_b.frame_dst == "frame_a"
@pytest.mark.parametrize("batch_size", (None, 1, 2, 5))
- def transform_points(self, device, dtype, batch_size):
+ def test_transform_points(self, device, dtype, batch_size):
if batch_size is None:
points_in_a = torch.randn(3, device=device, dtype=dtype)
- b_from_a_se3 = Se3.trans_x(torch.tensor(1.0, device=device, dtype=dtype))
+ b_from_a_se3 = Se3.rot_z(torch.tensor(0.5, device=device, dtype=dtype)) * Se3.trans_x(
+ torch.tensor(1.0, device=device, dtype=dtype)
+ )
else:
points_in_a = torch.randn(batch_size, 3, device=device, dtype=dtype)
- b_from_a_se3 = Se3.trans_x(torch.tensor([1.0], device=device, dtype=dtype))
+ b_from_a_se3 = Se3.rot_z(torch.tensor([0.5] * batch_size, device=device, dtype=dtype)) * Se3.trans_x(
+ torch.tensor([1.0] * batch_size, device=device, dtype=dtype)
+ )
b_from_a = NamedPose(b_from_a_se3, frame_src="frame_a", frame_dst="frame_b")
a_from_b = b_from_a.inverse()
points_in_b = b_from_a.transform_points(points_in_a)
assert points_in_b.shape == points_in_a.shape
- self.assert_close(a_from_b.transform_points(points_in_b), points_in_a)
+ # b_from_a = Rz(0.5) * Tx(1): translate by +1 along x, then rotate 0.5 rad about z. In half precision the
+ # rotation is rounded, and the round trip applies two rounded rotations: about one ulp at |p| ~ 2.
+ low_tolerance = dtype in (torch.float16, torch.bfloat16)
+ c, s = math.cos(0.5), math.sin(0.5)
+ rot_z = torch.tensor([[c, -s, 0.0], [s, c, 0.0], [0.0, 0.0, 1.0]], device=device, dtype=dtype)
+ shift_x = torch.tensor([1.0, 0.0, 0.0], device=device, dtype=dtype)
+ self.assert_close(points_in_b, (points_in_a + shift_x) @ rot_z.T, low_tolerance=low_tolerance)
+ self.assert_close(a_from_b.transform_points(points_in_b), points_in_a, low_tolerance=low_tolerance)