Skip to content

Commit

Permalink
[MAINT] update parameters for scipy.sparse.linalg.cg (#4394)
Browse files Browse the repository at this point in the history
* changed cg parameters

* fix compat support scipy < 1.12 [test nightly]
  • Loading branch information
Remi-Gau committed Apr 24, 2024
1 parent 9552896 commit 3559d80
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions nilearn/_utils/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
import warnings

import numpy as np
from scipy import ndimage as ndi, sparse
from scipy import __version__, ndimage as ndi, sparse
from scipy.sparse.linalg import cg
from sklearn.utils import as_float_array

from nilearn._utils.helpers import compare_version


def _make_graph_edges_3d(n_x, n_y, n_z):
"""Return a list of edges for a 3D image.
Expand Down Expand Up @@ -355,7 +357,14 @@ def _solve_cg(lap_sparse, B, tol):
lap_sparse = lap_sparse.tocsc()
X = []
for i in range(len(B)):
x0 = cg(lap_sparse, -B[i].todense(), tol=tol, atol="legacy")[0]
# TODO Python 3.8
# consider remove if/else block when dropping support for 3.8
# would require pinning scipy to >= 1.12
# See https://github.com/nilearn/nilearn/pull/4394
if compare_version(__version__, ">=", "1.12"):
x0 = cg(lap_sparse, -B[i].todense(), rtol=tol, atol=0)[0]
else:
x0 = cg(lap_sparse, -B[i].todense(), tol=tol, atol="legacy")[0]
X.append(x0)

X = np.array(X)
Expand Down

0 comments on commit 3559d80

Please sign in to comment.