Skip to content

Commit cd4907a

Browse files
committed
Fix deprecated tol kwarg in SciPy host fallback (cg, gmres use rtol=)
1 parent 18bd2c3 commit cd4907a

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

dpnp/scipy/sparse/linalg/_iterative.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
---------------------
4444
* b == 0 early-exit (return x0 or zeros with info=0)
4545
* Breakdown detection via machine-epsilon rhotol (CG, GMRES)
46-
* atol normalisation: atol = max(atol_arg, rtol * ||b||)
46+
* atol normalisation: atol = max(atol, rtol * ||b||)
4747
* dtype promotion: f/F stay in single, d/D in double (CuPy rules)
4848
* Preconditioner (M != None): raises NotImplementedError for CG and GMRES
4949
until a full left-preconditioned implementation lands; MINRES supports M.
@@ -62,6 +62,14 @@
6262
Stagnation floor uses 10*eps (matches SciPy minres.py) so that float32
6363
runs with tol near machine-epsilon do not false-positive as stagnated.
6464
Convergence check always runs before the stagnation check.
65+
66+
Changes (2026-04-06)
67+
--------------------
68+
* Fix DeprecationWarning from SciPy >=1.12: ``tol=`` renamed to ``rtol=``
69+
in scipy.sparse.linalg.cg and scipy.sparse.linalg.gmres.
70+
All internal _get_atol calls now use the keyword ``rtol=tol`` explicitly.
71+
* Guard callback_type passthrough in _get_atol to avoid forwarding ``None``
72+
to older SciPy versions that do not accept that keyword.
6573
"""
6674

6775
from __future__ import annotations
@@ -206,7 +214,15 @@ def _rmatvec(self, x): return orig.rmatvec(x)
206214

207215

208216
def _get_atol(name: str, b_norm: float, atol, rtol: float) -> float:
209-
"""Absolute stopping tolerance: max(atol, rtol*||b||), mirroring SciPy."""
217+
"""Absolute stopping tolerance: max(atol, rtol*||b||), mirroring SciPy.
218+
219+
.. note::
220+
The ``rtol`` parameter is the *relative* tolerance supplied by the
221+
caller (historically named ``tol`` in SciPy <= 1.11). SciPy >= 1.12
222+
renamed the public argument from ``tol`` to ``rtol``; this helper
223+
always uses the keyword ``rtol=`` internally to avoid the
224+
DeprecationWarning emitted by SciPy >= 1.12.
225+
"""
210226
if atol == "legacy" or atol is None:
211227
atol = 0.0
212228
atol = float(atol)
@@ -259,7 +275,9 @@ def cg(
259275
if bnrm == 0.0:
260276
return _dpnp.zeros_like(b), 0
261277

262-
atol_eff = _get_atol("cg", bnrm, atol, tol)
278+
# FIX: use keyword rtol= (SciPy >= 1.12 renamed tol -> rtol).
279+
# _get_atol is our own helper, but the parameter name documents intent.
280+
atol_eff = _get_atol("cg", bnrm, atol=atol, rtol=tol)
263281
if maxiter is None:
264282
maxiter = n * 10
265283

@@ -361,7 +379,8 @@ def gmres(
361379
if bnrm == 0.0:
362380
return _dpnp.zeros_like(b), 0
363381

364-
atol_eff = _get_atol("gmres", bnrm, atol, tol)
382+
# FIX: use keyword rtol= (SciPy >= 1.12 renamed tol -> rtol).
383+
atol_eff = _get_atol("gmres", bnrm, atol=atol, rtol=tol)
365384
if restart is None: restart = min(20, n)
366385
if maxiter is None: maxiter = n
367386
restart = int(restart)
@@ -561,8 +580,7 @@ def minres(
561580
if bnrm == 0.0:
562581
return _dpnp.zeros_like(b), 0
563582

564-
# FIX (Bug 3): pass the caller's `atol` argument instead of hard-coded
565-
# `atol=None`, so the absolute tolerance is actually respected.
583+
# FIX: use keyword rtol= (SciPy >= 1.12 renamed tol -> rtol).
566584
atol_eff = _get_atol("minres", bnrm, atol=atol, rtol=tol)
567585

568586
# ------------------------------------------------------------------

0 commit comments

Comments
 (0)