From 19bd785ae430d5e81aaf1cea3b52812edc21cc56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=A9tan=20Lepage?= <33058747+GaetanLepage@users.noreply.github.com> Date: Sun, 21 Jul 2024 23:54:24 +0200 Subject: [PATCH] Fix scipy 1.14 incompatibilities (#2508) - The eigvals named argument of the scipy.linalg.eigvalsh has been removed in favor of subset_by_index. - The .A attribute of sparse matrices has been removed in favor of .torray() --- cvxpy/atoms/condition_number.py | 4 ++-- cvxpy/atoms/gen_lambda_max.py | 2 +- cvxpy/atoms/lambda_max.py | 2 +- cvxpy/tests/test_conic_solvers.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cvxpy/atoms/condition_number.py b/cvxpy/atoms/condition_number.py index 9bb598249b..e30e0d515e 100644 --- a/cvxpy/atoms/condition_number.py +++ b/cvxpy/atoms/condition_number.py @@ -34,8 +34,8 @@ def numeric(self, values): Requires that A be a Positive Semidefinite Matrix. """ lo = hi = self.args[0].shape[0]-1 - max_eigen = LA.eigvalsh(values[0], eigvals=(lo, hi))[0] - min_eigen = -LA.eigvalsh(-values[0], eigvals=(lo, hi))[0] + max_eigen = LA.eigvalsh(values[0], subset_by_index=(lo, hi))[0] + min_eigen = -LA.eigvalsh(-values[0], subset_by_index=(lo, hi))[0] return max_eigen / min_eigen def _domain(self) -> List[Constraint]: diff --git a/cvxpy/atoms/gen_lambda_max.py b/cvxpy/atoms/gen_lambda_max.py index 9316a46c60..eff00748bb 100644 --- a/cvxpy/atoms/gen_lambda_max.py +++ b/cvxpy/atoms/gen_lambda_max.py @@ -37,7 +37,7 @@ def numeric(self, values): return LA.eigh(a=values[0], b=values[1], eigvals_only=True, - eigvals=(lo, hi))[0] + subset_by_index=(lo, hi))[0] def _domain(self) -> List[Constraint]: """Returns constraints describing the domain of the node. diff --git a/cvxpy/atoms/lambda_max.py b/cvxpy/atoms/lambda_max.py index 58da2185d3..b42f9a2fec 100644 --- a/cvxpy/atoms/lambda_max.py +++ b/cvxpy/atoms/lambda_max.py @@ -36,7 +36,7 @@ def numeric(self, values): Requires that A be symmetric. """ lo = hi = self.args[0].shape[0]-1 - return LA.eigvalsh(values[0], eigvals=(lo, hi))[0] + return LA.eigvalsh(values[0], subset_by_index=(lo, hi))[0] def _domain(self) -> List[Constraint]: """Returns constraints describing the domain of the node. diff --git a/cvxpy/tests/test_conic_solvers.py b/cvxpy/tests/test_conic_solvers.py index 6a0b95478f..e2efa7baf7 100644 --- a/cvxpy/tests/test_conic_solvers.py +++ b/cvxpy/tests/test_conic_solvers.py @@ -338,7 +338,7 @@ def test_quad_obj(self) -> None: constr = [x >= 1] prob = cp.Problem(cp.Minimize(expr), constr) data = prob.get_problem_data(solver=cp.SCS) - self.assertItemsAlmostEqual(data[0]["P"].A, 2*np.eye(2)) + self.assertItemsAlmostEqual(data[0]["P"].toarray(), 2*np.eye(2)) solution1 = prob.solve(solver=cp.SCS) # When use_quad_obj = False, the quadratic objective is