Hello, I am looking for a way to do fast matrix operations (multiplication, Inversion) for large matrices (n=8000) in R. I know R is not that fast in linear algebra than other software. So I wanted to write some code in C++ and incorporate this code in R. I have used the package RcppArmadillo, because a lot of people write that it is really fast in doing matrix algebra. So I have run a short example. See the code below. I was wondering that I got almost the same CPU time for the matrix algebra in my example. I expect that using C++ Code in R is faster than using the standard matrix operations in R.
Is there a way to do matrix algebra in R faster as the standard command (e.g. %*%) using the Rcpp or RcppArmadillo packages? I would be happy about any idea or advice. Thanks in advance > library(Rcpp) > library(RcppArmadillo) > library(inline) > library(RcppEigen) > library(devtools) > > # Generation of the matrix > n=2000 > A<-matrix(rnorm(n^2,0,1), n,n) > > # Code in R > system.time( + D<-A%*%A%*%A+A) user system elapsed 12.29 0.01 12.33 > > # Code using RcppArmadillo > src <- + ' + arma::mat X = Rcpp::as<arma::mat>(X_); + arma::mat ans = X * X * X + X; + return(wrap(ans)); + ' > mprod6_inline_RcppArma <- cxxfunction(signature(X_="numeric"), + body = src, plugin="RcppArmadillo") > > system.time( + C<-mprod6_inline_RcppArma(X=A)) user system elapsed 12.30 0.08 12.40 [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.