Update `R.nzval` instead of `R[i,j]=...`
Currently, we use R[indices[i], j] = submatrix_result[i, idx]
to write the submatrix result into the result matrix R
. This is suboptimal because we know that only R.nzval
will actually change eventually (the sparsity pattern is preserved) and, more importantly, because setindex!
doesn't seem to be thread-safe for SparseMatrixCSC
.
(To temporarily circumvent this issue, we currently allocate R
as a dense matrix only to make it sparse before returning it...)
At least in the non-serial case, we want to update (the respective part of) R.nzval
directly. This should be
- a bit more efficient (how much?)
- thread-safe (if different threads only operate on non-overlapping regions)
It is also what Michael did it his original work (see values_inv
).
Edited by Carsten Bauer