Skip to content

Commit

Permalink
Update scipy_wrapper (cvxpy#2159)
Browse files Browse the repository at this point in the history
* update spwrapper

* Update cvxpy/interface/scipy_wrapper.py

Co-authored-by: Isaac Virshup <ivirshup@gmail.com>

---------

Co-authored-by: Philipp Schiele <44360364+phschiele@users.noreply.github.com>
Co-authored-by: Isaac Virshup <ivirshup@gmail.com>
  • Loading branch information
3 people authored and Paulnkk committed Aug 1, 2023
1 parent 3f706fe commit 8dd93e8
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions cvxpy/interface/scipy_wrapper.py
Expand Up @@ -14,10 +14,19 @@
limitations under the License.
"""

from scipy.sparse.base import spmatrix
from scipy import sparse

from cvxpy.expressions import expression as exp

SPARSE_MATRIX_CLASSES = [
sparse.csc_matrix,
sparse.csr_matrix,
sparse.coo_matrix,
sparse.bsr_matrix,
sparse.lil_matrix,
sparse.dia_matrix,
sparse.dok_matrix,
]
BIN_OPS = ["__div__", "__mul__", "__add__", "__sub__",
"__le__", "__eq__", "__lt__", "__gt__"]

Expand All @@ -32,8 +41,8 @@ def new_method(self, other):
return method(self, other)
return new_method


for method_name in BIN_OPS:
method = getattr(spmatrix, method_name)
new_method = wrap_bin_op(method)
setattr(spmatrix, method_name, new_method)
for cls in SPARSE_MATRIX_CLASSES:
for method_name in BIN_OPS:
method = getattr(cls, method_name)
new_method = wrap_bin_op(method)
setattr(cls, method_name, new_method)

0 comments on commit 8dd93e8

Please sign in to comment.