Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

test: keep the #5031 geometry tests off float64 on MPS (fixes red tests-mps on main) (#5080)

Dmytro Mishkinefed254b9f8e
diff --git a/tests/geometry/epipolar/test_epipolar_metrics.py b/tests/geometry/epipolar/test_epipolar_metrics.py
index b5ddf59e6..771f09f9f 100644
--- a/tests/geometry/epipolar/test_epipolar_metrics.py
+++ b/tests/geometry/epipolar/test_epipolar_metrics.py
@@ -435,6 +435,8 @@ class TestSampsonSharedPoints(BaseTester):
self.assert_close(out, expected.to(dtype))
def test_non_contiguous_and_mixed_dtype_models(self, device, dtype):
+ if device.type == "mps":
+ pytest.skip("MPS does not support float64")
pts1 = torch.rand(1, 11, 2, device=device, dtype=torch.float64)
pts2 = torch.rand(1, 11, 2, device=device, dtype=torch.float64)
Fm = create_random_fundamental_matrix(4, dtype=dtype, device=device)
@@ -458,9 +460,11 @@ class TestSampsonSharedPoints(BaseTester):
x1 = torch.tensor([[[1000.1, 1000.2]]], device=device, dtype=dtype)
x2 = torch.tensor([[[1000.3, 1000.4]]], device=device, dtype=dtype)
models = F.expand(64, 3, 3)
- shared = _sampson_epipolar_distance_shared_impl_(x1, x2, models, True, 0.0, 0.0)[:, 0].double().cpu()
- manual = _sampson_epipolar_distance_manual_impl_(x1, x2, F[None], True, 0.0)[0, 0].double().cpu()
- reference = _sampson_epipolar_distance_manual_impl_(x1.double(), x2.double(), F[None].double(), True, 0.0)
+ shared = _sampson_epipolar_distance_shared_impl_(x1, x2, models, True, 0.0, 0.0)[:, 0].cpu().double()
+ manual = _sampson_epipolar_distance_manual_impl_(x1, x2, F[None], True, 0.0)[0, 0].cpu().double()
+ reference = _sampson_epipolar_distance_manual_impl_(
+ x1.cpu().double(), x2.cpu().double(), F[None].cpu().double(), True, 0.0
+ )
reference = reference[0, 0].cpu()
self.assert_close(shared, manual.expand_as(shared), rtol=1e-4, atol=0.0)
assert (shared - reference).abs().max() <= 2 * (manual - reference).abs()
@@ -476,7 +480,7 @@ class TestSampsonSharedPoints(BaseTester):
cast = lambda t: t.to(device, dtype) # noqa: E731
shared = _sampson_epipolar_distance_shared_impl_(cast(x1[None]), cast(x2[None]), cast(models), True, 0.0, 0.0)
manual = _sampson_epipolar_distance_manual_impl_(cast(x1[None]), cast(x2[None]), cast(models), True, 0.0)
- shared, manual = shared.double().cpu(), manual.double().cpu()
+ shared, manual = shared.cpu().double(), manual.cpu().double()
assert torch.isfinite(shared).all()
assert (shared >= 0).all()
# Within 0.1 px of an epipole both float32 computations are rounding noise (the maximum error of either is
@@ -504,7 +508,7 @@ class TestSampsonSharedPoints(BaseTester):
reference = _sampson_errors(models, h1, h2, 0.0)
cast = lambda t: t.to(device, torch.float32) # noqa: E731
errors = _sampson_from_quadratic_basis(cast(models), _sampson_quadratic_basis(cast(h1), cast(h2)))
- errors = errors.double().cpu()
+ errors = errors.cpu().double()
assert not errors.isnan().any()
assert (errors >= 0).all()
scale = float(t2[0, 0, 0])
diff --git a/tests/geometry/epipolar/test_fundamental.py b/tests/geometry/epipolar/test_fundamental.py
index 516d87d35..914facbdb 100644
--- a/tests/geometry/epipolar/test_fundamental.py
+++ b/tests/geometry/epipolar/test_fundamental.py
@@ -902,6 +902,8 @@ class TestEpipolarDesignRows(BaseTester):
class TestRankTwoProjection(BaseTester):
def test_matches_svd(self, device):
+ if device.type == "mps":
+ pytest.skip("MPS does not support float64")
F = torch.randn(128, 3, 3, generator=torch.Generator().manual_seed(0), dtype=torch.float64).to(device)
U, S, Vh = torch.linalg.svd(F)
expected = U @ torch.diag_embed(S * torch.tensor([1.0, 1.0, 0.0], device=device, dtype=torch.float64)) @ Vh
@@ -924,6 +926,8 @@ class TestRankTwoProjection(BaseTester):
def test_repeated_singular_values(self, device, values, rotate):
# At a repeated smallest singular value the nearest rank-2 matrix is not unique, so compare what every one of
# them shares with the SVD's: the two largest singular values, a zero third one, and the distance sigma_3.
+ if device.type == "mps":
+ pytest.skip("MPS does not support float64")
F = _with_singular_values(values, rotate).to(device)[None]
P = _rank2_projection(F)
s = torch.linalg.svdvals(F)[0]
@@ -946,6 +950,8 @@ class TestRankTwoProjection(BaseTester):
assert (P - expected).abs().max() < 1e-5
def test_backward_is_finite_at_a_repeated_spectrum(self, device):
+ if device.type == "mps":
+ pytest.skip("MPS does not support float64")
F = torch.eye(3, device=device, dtype=torch.float64)[None].requires_grad_()
_rank2_projection(F).sum().backward()
assert torch.isfinite(F.grad).all()
@@ -1072,6 +1078,8 @@ class TestSevenPoint(BaseTester):
def test_backward_is_finite(self, device, idx):
# The second sample has one real root (#4862): masking candidates built from NaN roots used to leave NaN in
# the backward pass although the output was finite.
+ if device.type == "mps":
+ pytest.skip("MPS does not support float64")
two_view = two_view_scene(device, torch.float64)
x1 = two_view["x1"][:, idx].clone().requires_grad_()
F = epi.find_fundamental(x1, two_view["x2"][:, idx], method="7POINT")
diff --git a/tests/geometry/test_homography.py b/tests/geometry/test_homography.py
index 1207e8da4..93c792b53 100644
--- a/tests/geometry/test_homography.py
+++ b/tests/geometry/test_homography.py
@@ -1245,11 +1245,11 @@ class TestHomographySharedKernels(BaseTester):
dst = convert_points_from_homogeneous(_hom(src) @ H.T) + torch.randn(1, 2000, 2, generator=generator, dtype=f64)
reference = torch.cat([oneway_transfer_error(src, dst, models[i : i + 1], eps=0.0) for i in range(8)])
cast = lambda t: t.to(device, dtype) # noqa: E731
- shared = oneway_transfer_error(cast(src), cast(dst), cast(models), eps=0.0).double().cpu()
+ shared = oneway_transfer_error(cast(src), cast(dst), cast(models), eps=0.0).cpu().double()
per_model = (
torch.cat([oneway_transfer_error(cast(src), cast(dst), cast(models[i : i + 1]), eps=0.0) for i in range(8)])
- .double()
.cpu()
+ .double()
)
small = reference < 100
assert (shared - reference)[small].abs().max() <= 2 * (per_model - reference)[small].abs().max() + 1e-6