Catch more cases of sparse matmul involving adjoints #60
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a bit hacky, but it fixes ITensor/BlockSparseArrays.jl#24.
It was caused by a subtle confluence of issues:
blocks(A)'whereAis aBlockSparseMatrixisn't a subtype ofAnyAbstractSparseArray, since the element type of theAdjointwrapper is theAdjointof the element type ofblocks(a), i.e. the type is something likeAdjoint{Adjoint{Float64,Matrix{Float64}},SparseMatrixDOK{Matrix{Float64}}}. That's true of adjoints of matrices of matrices in general, so is a limitation of theAnyAbstractSparseArrayunion type, which is based on theAdapt.WrappedArraywrapper union.AnyAbstractSparseArrayis used to catch objects that act as sparse arrays to give them a sparse array memory layout and interface, so they get forwarded to sparse implementations of matrix multiplication. Because of 1., that wasn't happening for adjoints of sparse matrices of matrices.This is a hacky solution to catch a few cases that are missed by the current design, but ideally we would have a more systematic fix. One would be to make
AnyAbstractSparseArraymore general so that it doesn't have that type constraint between the wrapper element type and parent element type, since that's probably an issue for other wrapper types as well. Refactors like ITensor/DerivableInterfaces.jl#28 and #39 would also help make it easier to catch and fix this kind of issue since it was a bit tough to hunt down, since some of these definitions are implicitly derived usingDerivableInterfaces.jl.