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

Xavier Robin xavier at cbs.dtu.dk
Wed Nov 6 19:04:24 CET 2013


On 11/6/13 6:38 PM, Romain Francois wrote:
> 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
>
Most of the code (or at least the slow, highly repeated parts) look like:

>     A <- t(c + t(W) %*% X)
>     E <- (exp(A) * (1 - 1 / A) + 1 / A) / (exp(A) - 1)
>     E[abs(A) < sqrt(.Machine$double.eps) * 2 ] <- 0.5
>
>     B <- t(b + W %*% t(E))
>     X2 <- 1 / (1 + exp(-B))
>
>     A2 <- t(c + t(W) %*% X2)
>     E2 <- (exp(A2) * (1 - 1 / A2) + 1 / A2) / (exp(A2) - 1)
>     E2[abs(A2) < sqrt(.Machine$double.eps) * 2 ] <- 0.5
>
>     delta <- (t(X) %*% E - t(X2) %*% E2)
>     W <- W + delta

Where b and c are vectors, W and X matrices. All this is encapsulated in 
a function, that is called a few thousand times in a for loop, with some 
sanity checks. (But it didn't appear to have much impact on the speed... 
if I remove the matrix operations so it does nothing, it executes nearly 
instantly). I understand from Dirk and Douglas that it probably isn't 
going to make a huge difference, though (not by orders).

Thanks,
Xavier

-- 
Xavier Robin, PhD
Cellular Signal Integration Group (C-SIG) - http://www.lindinglab.org
Center for Biological Sequence Analysis (CBS) - http://www.cbs.dtu.dk
Department of Systems Biology - Technical University of Denmark (DTU)
Anker Engelundsvej, Building 301, DK-2800 Lyngby, DENMARK.



More information about the Rcpp-devel mailing list