Skip to content

matrix.csr %*% matrix --> matrix

3 messages · Sam Steingold, Martin Maechler

#
The question is even more pressing for me now given that I no longer can
convert some csr matrices to the regular ones for scaling.
(http://article.gmane.org/gmane.comp.lang.r.general:279305)
Any suggestions? (the original csr matrix is too large to be converted
to a regular one, but the product is small enough).

  
    
#
Sam> The question is even more pressing for me now given that I no longer can
    Sam> convert some csr matrices to the regular ones for scaling.
    Sam> (http://article.gmane.org/gmane.comp.lang.r.general:279305)
    Sam> Any suggestions? (the original csr matrix is too large to be converted
    Sam> to a regular one, but the product is small enough).

    >> * Sam Steingold <fqf at tah.bet> [2012-08-27 14:58:47 -0400]:
    >> 
    >> When a sparse matrix is multiplied by a regular one, the result is
    >> usually not sparse. However, when matrix.csr is multiplied by a regular
    >> matrix in R, a matrix.csr is produced.
    >> Is there a way to avoid this?
    >> Thanks!

Why don't you use the sparse matrix classes from the Matrix
package .. which is part of every R distribution ?
"SparseM" has been written as very first package to support
sparse matrices, and is to be applauded for that,
but it does lack many features nowadays (and also uses less
modern algorithm for e.g. the sparse Cholesky decomposition).

Martin Maechler
the (biased!) Co-author of the Matrix package.
#
Thank you very much for your advice.

I do not think I use SparseM directly.
I use e1071::read.matrix.csr and e1071::write.matrix.csr which use SparseM.
I.e., I need to be able to do i/o on files which are palatable to
libsvm/liblinear, specifically, read/write files like
--8<---------------cut here---------------start------------->8---
1.2 2:3.5 6:5.1
2 4:6.7
8 7:6.6
--8<---------------cut here---------------end--------------->8---

As you can see from my other messages
(e.g., http://article.gmane.org/gmane.comp.lang.r.general:279387),
I am not happy with my current setup.
I would be delighted to learn that there is an alternative, but so far
the only matrix i/o I could find is Matrix::readHB and it does not
handle the libsvm/liblinear format.