Skip to content

Commit

Permalink
Fix scipy 1.14 incompatibilities (cvxpy#2508)
Browse files Browse the repository at this point in the history
- 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()
  • Loading branch information
GaetanLepage authored Jul 21, 2024
1 parent eec1d0f commit 19bd785
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cvxpy/atoms/condition_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion cvxpy/atoms/gen_lambda_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion cvxpy/atoms/lambda_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion cvxpy/tests/test_conic_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 19bd785

Please sign in to comment.