Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scipy_wrapper #2159

Merged
merged 2 commits into from Jun 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions cvxpy/interface/scipy_wrapper.py
Expand Up @@ -14,10 +14,19 @@
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,
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)