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

Simon Zehnder szehnder at uni-bonn.de
Wed Nov 6 19:19:21 CET 2013


As Romain already mentioned, there could be rather a memory issue - copying is one issue. Very often time gets lost in loads and writes with cache misses. How large are your matrices? Have you done a memory-profiling? 

Best
Simon

On 06 Nov 2013, at 19:04, Xavier Robin <xavier at cbs.dtu.dk> wrote:

> 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.
> 
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel



More information about the Rcpp-devel mailing list