Sparse matrix-matrix calculation only within specified sparsity?

question

#1

I need to preform some sparse matrix-matrix calculations, but I only need a few of the non-zeros. Specifically, for A*B=C I only need the resulting C nonzeros where A has nonzeros. Forming all of C and then dropping the values I don’t need is prohibitively memory expensive.

It is my understanding that Julia makes use of cholmod_ssmult for this computation. What I’m asking is not implemented in cholmod_ssmult as far as I can tell. Are there any other libraries that can accomplish this? Is there a Julia way to accomplish this?


#2

You may have to write your own; it shouldn’t be too hard if you understand sparse-matrix data structures.


#3

I don’t know of any standard function that does this. But if you want to implement it in Julia, one way would be to convert A to CSR format, then take the old CSC A and let that be C. You can then traverse the non-zeros of C, taking dot products of the i^{th} row of A, and the j^{th} column of B and storing it in the non-zero C[i,j], which can be done efficiently as A is CSR and B is CSC. For how to convert from CSC to CSR, check this outdated file https://github.com/JuliaSparse/SparseMatrices.jl/blob/master/src/csr.jl which needs a revamp. And for dot product of sparse vectors, check https://github.com/JuliaSparse/SparseVectors.jl/blob/30a3c3e80893c7fa4c16464b518a10975a82815d/src/linalg.jl#L103.