π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
fix(tests): run the polynomial-solver gradchecks instead of shadowing BaseTester.gradcheck (#4188)
Tai Anb3014f1fda8f
diff --git a/tests/geometry/solvers/test_polynomial_solver.py b/tests/geometry/solvers/test_polynomial_solver.pyindex 899920fae..53bb38643 100644--- a/tests/geometry/solvers/test_polynomial_solver.py+++ b/tests/geometry/solvers/test_polynomial_solver.py@@ -48,9 +48,14 @@ class TestQuadraticSolver(BaseTester):roots = solver.solve_quadratic(coeffs)self.assert_close(roots[0], expected_solutions[0])- def gradcheck(self, device):- coeffs = torch.rand(1, 3, device=device, dtype=torch.float64, requires_grad=True)- assert self.gradcheck(solver.solve_quadratic, (coeffs), raise_exception=True, fast_mode=True)+ def test_gradcheck(self, device):+ # Deterministic, strictly positive discriminant (b^2 - 4ac = 1): `torch.rand` draws+ # all-positive coefficients, whose discriminant is usually negative, and the no-real-root+ # branch returns zeros with an identically zero gradient -- so a random draw checks+ # nothing roughly three times out of four. The zero-discriminant triple is excluded on+ # purpose: `sqrt` is not differentiable at 0.+ coeffs = torch.tensor([[1.0, -5.0, 6.0]], device=device, dtype=torch.float64, requires_grad=True)+ self.gradcheck(solver.solve_quadratic, (coeffs,))class TestCubicSolver(BaseTester):@@ -80,9 +85,11 @@ class TestCubicSolver(BaseTester):roots = solver.solve_cubic(coeffs)self.assert_close(roots[0], expected_solutions[0], rtol=1e-3, atol=1e-3)- def gradcheck(self, device):- coeffs = torch.rand(1, 4, device=device, dtype=torch.float64, requires_grad=True)- assert self.gradcheck(solver.solve_cubic, (coeffs), raise_exception=True, fast_mode=True)+ def test_gradcheck(self, device):+ # Deterministic three-distinct-real-roots case (roots 2, -3, -1/2), so the check does not+ # depend on an unseeded draw. Repeated roots are excluded: they sit on the `sqrt` kink.+ coeffs = torch.tensor([[2.0, 3.0, -11.0, -6.0]], device=device, dtype=torch.float64, requires_grad=True)+ self.gradcheck(solver.solve_cubic, (coeffs,))class TestMultiplyDegOnePoly(BaseTester):