Skip to content

Commit

Permalink
fix scipy v1.13 sparse monkey patch bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmgray committed Apr 4, 2024
1 parent 7141a73 commit 6bc0064
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ Release notes for `quimb`.
[`TN2D_rand_symmetric`](quimb.tensor.tensor_builder.TN2D_rand_symmetric)
for generating random symmetric arrays, tensors and 2D tensor networks.

**Bug fixes:**

- fix scipy sparse monkey patch for scipy>=1.13 ({issue}`222`)


(whats-new-1-7-3)=
Expand Down
31 changes: 22 additions & 9 deletions quimb/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2183,12 +2183,25 @@ def qarrayed_fn(self, other):
return qarrayed_fn


sp.csr_matrix._mul_vector = csr_mulvec_wrap(sp.csr_matrix._mul_vector)
sp.csc_matrix._mul_vector = sp_mulvec_wrap(sp.csc_matrix._mul_vector)
sp.coo_matrix._mul_vector = sp_mulvec_wrap(sp.coo_matrix._mul_vector)
sp.bsr_matrix._mul_vector = sp_mulvec_wrap(sp.bsr_matrix._mul_vector)

sp.csr_matrix._mul_multivector = sp_mulvec_wrap(sp.csr_matrix._mul_multivector)
sp.csc_matrix._mul_multivector = sp_mulvec_wrap(sp.csc_matrix._mul_multivector)
sp.coo_matrix._mul_multivector = sp_mulvec_wrap(sp.coo_matrix._mul_multivector)
sp.bsr_matrix._mul_multivector = sp_mulvec_wrap(sp.bsr_matrix._mul_multivector)
try:
# scipy>=1.13
sp.csr_matrix._matmul_vector = csr_mulvec_wrap(sp.csr_matrix._matmul_vector)
sp.csc_matrix._matmul_vector = sp_mulvec_wrap(sp.csc_matrix._matmul_vector)
sp.coo_matrix._matmul_vector = sp_mulvec_wrap(sp.coo_matrix._matmul_vector)
sp.bsr_matrix._matmul_vector = sp_mulvec_wrap(sp.bsr_matrix._matmul_vector)

sp.csr_matrix._matmul_multivector = sp_mulvec_wrap(sp.csr_matrix._matmul_multivector)
sp.csc_matrix._matmul_multivector = sp_mulvec_wrap(sp.csc_matrix._matmul_multivector)
sp.coo_matrix._matmul_multivector = sp_mulvec_wrap(sp.coo_matrix._matmul_multivector)
sp.bsr_matrix._matmul_multivector = sp_mulvec_wrap(sp.bsr_matrix._matmul_multivector)
except AttributeError:
# scipy <=1.12"
sp.csr_matrix._mul_vector = csr_mulvec_wrap(sp.csr_matrix._mul_vector)
sp.csc_matrix._mul_vector = sp_mulvec_wrap(sp.csc_matrix._mul_vector)
sp.coo_matrix._mul_vector = sp_mulvec_wrap(sp.coo_matrix._mul_vector)
sp.bsr_matrix._mul_vector = sp_mulvec_wrap(sp.bsr_matrix._mul_vector)

sp.csr_matrix._mul_multivector = sp_mulvec_wrap(sp.csr_matrix._mul_multivector)
sp.csc_matrix._mul_multivector = sp_mulvec_wrap(sp.csc_matrix._mul_multivector)
sp.coo_matrix._mul_multivector = sp_mulvec_wrap(sp.coo_matrix._mul_multivector)
sp.bsr_matrix._mul_multivector = sp_mulvec_wrap(sp.bsr_matrix._mul_multivector)

0 comments on commit 6bc0064

Please sign in to comment.