Closed eschnett closed 3 years ago
Another way to avoid this slowdown is to replace -E1
by sparse(-E1)
.
Maybe the type signature of the sparse array hvcat
method isn't generic enough?
The problem is a missing constructor for SparseMatrixCSC{Float}(::Diagonal{Int})
, which then treats the diagonal matrix as AbstractMatrix
, and loops over all its indices checking for zeros. I'm working on a pull request.
I find that
hvcat
with sparse matrices is orders of magnitude slower than expected when adjoints of sparse matrices are involved. Here is an example:When I replace the definition of
δ
by the one that does not involve an adjoint, the calculation is much faster:I aborted one such very slow calculation, and found that
typed_hvcat
callssetindex!
. If this is indeed the case, then this explains why this is very slow. Sparse matrices need to be constructed by callingsparse
for efficiency.