Take the 2-minute tour ×
Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. It's 100% free, no registration required.

How can a sparse matrix - matrix product be calculated? I know the 'classic' / mathematical way of doing it, but it seems pretty inefficient.

I thought about storing the first matrix in CSR form and the second one in CSC form, so since the row and column vectors are sorted I won't have to search for a specific row / column I need, but I guess that doesn't help much.

share|improve this question
1  
Note that $\mathrm{CSR}\times\mathrm{CSC}$ is not generally a very good idea and actually $\mathrm{CSR}\times\mathrm{CRS}$ performs much better. As far as I know, there's a whole chapter in this book related to sparse matrix-matrix products. –  Algebraic Pavel Apr 4 at 16:51

1 Answer 1

up vote 3 down vote accepted

It is almost always inefficient to do a sparse-sparse matrix product $C=AB$. It is almost always more efficient to simply think of $C$ as an operator that you can apply to vectors, i.e., to compute $y=Cx$. Whenever such an operation is required, you compute it in two steps: $y=A(Bx)$, i.e., you simply do two matrix-vector products in a row to get the result. For this, it is not necessary to actually form the product matrix $AB$.

If you absolutely must form the product, take a look at https://svn.dealii.org/trunk/deal.II/include/deal.II/lac/sparse_matrix.templates.h and search for the mmult() function.

share|improve this answer
1  
Downvoting because of the last paragraph: simply saying "look at this code" does not seem very helpful for the reader. –  Federico Poloni Mar 29 at 23:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.