From e8493346e19bfaac67bb4e2928802a5c38b4bdae Mon Sep 17 00:00:00 2001 From: Steven Diamond Date: Mon, 26 Jun 2023 08:58:10 -0700 Subject: [PATCH 1/2] update spwrapper --- cvxpy/interface/scipy_wrapper.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/cvxpy/interface/scipy_wrapper.py b/cvxpy/interface/scipy_wrapper.py index da88e9fe1a..655df958d7 100644 --- a/cvxpy/interface/scipy_wrapper.py +++ b/cvxpy/interface/scipy_wrapper.py @@ -14,10 +14,18 @@ limitations under the License. """ -from scipy.sparse 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 +] BIN_OPS = ["__div__", "__mul__", "__add__", "__sub__", "__le__", "__eq__", "__lt__", "__gt__"] @@ -32,8 +40,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) From 4ad1883908c2c487ce41fb3518363a6685af7f07 Mon Sep 17 00:00:00 2001 From: Philipp Schiele <44360364+phschiele@users.noreply.github.com> Date: Mon, 26 Jun 2023 19:41:54 +0200 Subject: [PATCH 2/2] Update cvxpy/interface/scipy_wrapper.py Co-authored-by: Isaac Virshup --- cvxpy/interface/scipy_wrapper.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cvxpy/interface/scipy_wrapper.py b/cvxpy/interface/scipy_wrapper.py index 655df958d7..6762289ae5 100644 --- a/cvxpy/interface/scipy_wrapper.py +++ b/cvxpy/interface/scipy_wrapper.py @@ -24,7 +24,8 @@ sparse.coo_matrix, sparse.bsr_matrix, sparse.lil_matrix, - sparse.dia_matrix + sparse.dia_matrix, + sparse.dok_matrix, ] BIN_OPS = ["__div__", "__mul__", "__add__", "__sub__", "__le__", "__eq__", "__lt__", "__gt__"]