[Rcpp-devel] How much speedup for matrix operations?

Romain Francois romain at r-enthusiasts.com
Wed Nov 6 18:38:23 CET 2013


Le 06/11/2013 18:35, Xavier Robin a écrit :
> Hi,
>
> I have a pure-R code that spends most of the time performing vector and
> matrix operations, as shown by the summary of Rprof:
>>                    self.time self.pct total.time total.pct
>> "%*%"                 903.24    77.67     903.24 77.67
>> "t.default"            76.26     6.56      76.26 6.56
>> "-"                    36.60     3.15      36.60 3.15
>> "+"                    24.44     2.10      24.44 2.10
>> "/"                    24.22     2.08      24.22 2.08
>> "exp"                  20.26     1.74      20.26 1.74
>> "predict.myClass"      17.68     1.52     503.82 43.32
>> "*"                    11.90     1.02      11.90 1.02
>> "t"                     9.38     0.81     811.94 69.82
>> "update.batch"          8.04     0.69     654.68     56.30
>> ...
> So mostly matrix %*% matrix multiplications, transpositions, vector +-/*
> matrix operations and exponentiations, representing >95% of the
> computation time.
> I have very few loops and if/else blocks.
>
> I want to speed up this code, and I am considering reimplementing it (or
> part of it) with RcppEigen or RcppArmadillo.
>
> However, I read that both Eigen and Amarillo use the underlying BLAS,
> like R.
> My question is, can I expect any significant speed-up from an Rcpp
> re-implementation in this case, given it is already mostly matrix
> algebra (which are supposed to be pretty efficient in R)?
>
> Thanks,
> Xavier

This very much depends on the code but there is a good chance that 
RcppArmadillo will generate code making less data copies, etc ...

Hard to say without seeing the code.

Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30



More information about the Rcpp-devel mailing list