I will be working in R with a quite large (7 e6 x 4.5 e3) but very sparse matrix. So I am trying to understand how to deal with sparse matrices efficiently. I have two related questions.
First: I have been given to understand that the Matrix
package links automatically to the LAPACK and SuiteSparse compiled dlls. (I am working in Windows.) It was my impression that use of the SuiteSparse routines would shorten execution time compared with use of dense matrices using the LAPACK suite. But the test run below suggests that the run-time for the sparse version of the matrix is much slower than the dense version.
> library(Matrix)
> sparse <- sparseMatrix(1:4, 1:4, x=rnorm(4))
> dense <- as.matrix(sparse)
> x <- 1:4
> system.time(for (i in 1:10000) sparse %*% x)
user system elapsed
0.23 0.00 0.23
> system.time(for (i in 1:10000) dense %*% x)
user system elapsed
0 0 0
> system.time(for (i in 1:1000) solve(sparse))
user system elapsed
3.94 0.00 3.94
> system.time(for (i in 1:1000) solve(dense))
user system elapsed
0.05 0.00 0.05
a) Am I correct that Matrix
connects automatically with the above two compiled libraries? If not, how do I link to these DLLs?
b) Is the use of sparse matrix algebra in general actually that much slower than use of dense matrix algebra?
Second: I have installed the RcppEigen
and RcppArmadillo
packages. I have been able to compile a test program with RcppArmadillo
(using the paper by Dirk Eddelbuettel and Conrad Sanderson). But I have not, for the life of me, been able to find a similar introduction to RcppEigen
that would give me some model code that I could use to get started. Can any of you point to a document similar to the Eddelbuettel and Sanderson paper that can help me get started with RcppEigen
?