π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
fix(tests): remove hardcoded tolerance overrides in morphology tests (#4088)
Khushal Patil94d0284c44ea
diff --git a/tests/morphology/test_bottom_hat.py b/tests/morphology/test_bottom_hat.pyindex 66b958376..dc9985c36 100644--- a/tests/morphology/test_bottom_hat.py+++ b/tests/morphology/test_bottom_hat.py@@ -76,7 +76,7 @@ class TestBottomHat(BaseTester):expected = torch.tensor([[0.2, 0.0, 0.5], [0.0, 0.4, 0.0], [0.3, 0.0, 0.6]], device=device, dtype=dtype)[None, None, :, :]- assert_close(bottom_hat(tensor, kernel), expected, atol=1e-3, rtol=1e-3)+ assert_close(bottom_hat(tensor, kernel), expected)def test_structural_element(self, device, dtype):tensor = torch.tensor([[0.5, 1.0, 0.3], [0.7, 0.3, 0.8], [0.4, 0.9, 0.2]], device=device, dtype=dtype)[@@ -91,8 +91,6 @@ class TestBottomHat(BaseTester):assert_close(bottom_hat(tensor, torch.ones_like(structural_element), structuring_element=structural_element),expected,- atol=1e-3,- rtol=1e-3,)def test_exception(self, device, dtype):diff --git a/tests/morphology/test_closing.py b/tests/morphology/test_closing.pyindex 69abd024b..946738f74 100644--- a/tests/morphology/test_closing.py+++ b/tests/morphology/test_closing.py@@ -91,8 +91,6 @@ class TestClosing(BaseTester):assert_close(closing(tensor, torch.ones_like(structural_element), structuring_element=structural_element),expected,- atol=1e-3,- rtol=1e-3,)def test_exception(self, device, dtype):diff --git a/tests/morphology/test_dilation.py b/tests/morphology/test_dilation.pyindex 24cc89470..997eec8f4 100644--- a/tests/morphology/test_dilation.py+++ b/tests/morphology/test_dilation.py@@ -77,6 +77,9 @@ class TestDilate(BaseTester):None, None, :, :]assert_close(dilation(tensor, kernel, engine="unfold"), expected, atol=1e-4, rtol=1e-4)+ # The convolution engine measures ~3.9e-4 absolute / ~1.5e-3 relative error on macOS's+ # Apple-backend float32 conv path, above the harness's generic float32 default+ # (atol=1e-5, rtol=1e-4). This explicit tolerance is scoped to this backend-specific case.assert_close(dilation(tensor, kernel, engine="convolution"), expected, atol=1e-3, rtol=1e-3)def test_structural_element(self, device, dtype):@@ -94,9 +97,9 @@ class TestDilate(BaseTester):tensor, torch.ones_like(structural_element), structuring_element=structural_element, engine="unfold"),expected,- atol=1e-3,- rtol=1e-3,)+ # See test_kernel: convolution engine needs an explicit tolerance for macOS's+ # Apple-backend float32 numerical error, above the harness's generic float32 default.assert_close(dilation(tensor,@@ -117,7 +120,7 @@ class TestDilate(BaseTester):expected = torch.tensor([[0.7, 1.0, 1.0], [0.7, 1.0, 1.0], [0.7, 0.9, 0.9]], device=device, dtype=dtype)[None, None, :, :]- assert_close(dilation(tensor, kernel), expected, atol=1e-3, rtol=1e-3)+ assert_close(dilation(tensor, kernel), expected)def test_exception(self, device, dtype):tensor = torch.ones(1, 1, 3, 4, device=device, dtype=dtype)diff --git a/tests/morphology/test_erosion.py b/tests/morphology/test_erosion.pyindex a2254659c..67d44ac26 100644--- a/tests/morphology/test_erosion.py+++ b/tests/morphology/test_erosion.py@@ -77,6 +77,9 @@ class TestErode(BaseTester):None, None, :, :]assert_close(erosion(tensor, kernel), expected, atol=1e-4, rtol=1e-4)+ # The convolution engine measures ~3.9e-4 absolute / ~1.5e-3 relative error on macOS's+ # Apple-backend float32 conv path, above the harness's generic float32 default+ # (atol=1e-5, rtol=1e-4). This explicit tolerance is scoped to this backend-specific case.assert_close(erosion(tensor, kernel, engine="convolution"), expected, atol=1e-3, rtol=1e-3)def test_structural_element(self, device, dtype):@@ -95,6 +98,8 @@ class TestErode(BaseTester):atol=1e-4,rtol=1e-4,)+ # See test_kernel: convolution engine needs an explicit tolerance for macOS's+ # Apple-backend float32 numerical error, above the harness's generic float32 default.assert_close(erosion(tensor,@@ -116,6 +121,8 @@ class TestErode(BaseTester):None, None, :, :]assert_close(erosion(tensor, kernel, engine="unfold"), expected, atol=1e-4, rtol=1e-4)+ # See test_kernel: convolution engine needs an explicit tolerance for macOS's+ # Apple-backend float32 numerical error, above the harness's generic float32 default.assert_close(erosion(tensor, kernel, engine="convolution"), expected, atol=1e-3, rtol=1e-3)def test_exception(self, device, dtype):diff --git a/tests/morphology/test_gradient.py b/tests/morphology/test_gradient.pyindex 001ac29c4..1fcf9124b 100644--- a/tests/morphology/test_gradient.py+++ b/tests/morphology/test_gradient.py@@ -76,7 +76,7 @@ class TestGradient(BaseTester):expected = torch.tensor([[0.5, 0.7, 0.7], [0.4, 0.7, 0.6], [0.5, 0.7, 0.7]], device=device, dtype=dtype)[None, None, :, :]- assert_close(gradient(tensor, kernel), expected, atol=1e-3, rtol=1e-3)+ assert_close(gradient(tensor, kernel), expected)def test_structural_element(self, device, dtype):tensor = torch.tensor([[0.5, 1.0, 0.3], [0.7, 0.3, 0.8], [0.4, 0.9, 0.2]], device=device, dtype=dtype)[@@ -91,8 +91,6 @@ class TestGradient(BaseTester):assert_close(gradient(tensor, torch.ones_like(structural_element), structuring_element=structural_element),expected,- atol=1e-3,- rtol=1e-3,)def test_exception(self, device, dtype):diff --git a/tests/morphology/test_opening.py b/tests/morphology/test_opening.pyindex bc079e1fb..c0c723e82 100644--- a/tests/morphology/test_opening.py+++ b/tests/morphology/test_opening.py@@ -91,8 +91,6 @@ class TestOpening(BaseTester):assert_close(opening(tensor, torch.ones_like(structural_element), structuring_element=structural_element),expected,- atol=1e-3,- rtol=1e-3,)def test_exception(self, device, dtype):diff --git a/tests/morphology/test_top_hat.py b/tests/morphology/test_top_hat.pyindex 950964763..186dab980 100644--- a/tests/morphology/test_top_hat.py+++ b/tests/morphology/test_top_hat.py@@ -76,7 +76,7 @@ class TestTopHat(BaseTester):expected = torch.tensor([[0.0, 0.5, 0.0], [0.2, 0.0, 0.5], [0.0, 0.5, 0.0]], device=device, dtype=dtype)[None, None, :, :]- assert_close(top_hat(tensor, kernel), expected, atol=1e-3, rtol=1e-3)+ assert_close(top_hat(tensor, kernel), expected)def test_structural_element(self, device, dtype):tensor = torch.tensor([[0.5, 1.0, 0.3], [0.7, 0.3, 0.8], [0.4, 0.9, 0.2]], device=device, dtype=dtype)[@@ -91,8 +91,6 @@ class TestTopHat(BaseTester):assert_close(top_hat(tensor, torch.ones_like(structural_element), structuring_element=structural_element),expected,- atol=1e-3,- rtol=1e-3,)def test_exception(self, device, dtype):