Fix least_squares xtol result

This commit is contained in:
winklemad
2026-07-22 08:17:25 +05:30
parent 91bb075108
commit 72c9f2af63
2 changed files with 13 additions and 0 deletions
+2
View File
@@ -416,6 +416,8 @@ def least_squares(
# Check termination condition on step norm.
if dx_norm < xtol * (xtol + np.linalg.norm(x)):
x = xnew
r = rnew
status = Status.DX_TOL
break
+11
View File
@@ -45,6 +45,17 @@ class MinimizeTest(absltest.TestCase):
self.assertIn('norm(gradient) < tol', out.getvalue())
self.assertIn('exact minimum found', out.getvalue())
def test_xtol_returns_accepted_candidate(self) -> None:
def residual(x):
return x - 1.0
out = io.StringIO()
x, _ = minimize.least_squares(
np.array([0.0]), residual, xtol=2.0, gtol=0.0, output=out
)
np.testing.assert_array_equal(x, np.array([1.0]))
self.assertIn('norm(dx) < tol', out.getvalue())
def test_jac_callback(self) -> None:
def residual(x):
return np.stack([1 - x[0, :], 10 * (x[1, :] - x[0, :] ** 2)])