<div dir="ltr">it seems to me that every single call to t() can be avoided.<div><br></div><div>Kasper</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Nov 6, 2013 at 1:19 PM, Simon Zehnder <span dir="ltr"><<a href="mailto:szehnder@uni-bonn.de" target="_blank">szehnder@uni-bonn.de</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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?<br>


<br>
Best<br>
<span class="HOEnZb"><font color="#888888">Simon<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On 06 Nov 2013, at 19:04, Xavier Robin <<a href="mailto:xavier@cbs.dtu.dk">xavier@cbs.dtu.dk</a>> wrote:<br>
<br>
> On 11/6/13 6:38 PM, Romain Francois wrote:<br>
>> This very much depends on the code but there is a good chance that RcppArmadillo will generate code making less data copies, etc ...<br>
>><br>
>> Hard to say without seeing the code.<br>
>><br>
>> Romain<br>
>><br>
> Most of the code (or at least the slow, highly repeated parts) look like:<br>
><br>
>>    A <- t(c + t(W) %*% X)<br>
>>    E <- (exp(A) * (1 - 1 / A) + 1 / A) / (exp(A) - 1)<br>
>>    E[abs(A) < sqrt(.Machine$double.eps) * 2 ] <- 0.5<br>
>><br>
>>    B <- t(b + W %*% t(E))<br>
>>    X2 <- 1 / (1 + exp(-B))<br>
>><br>
>>    A2 <- t(c + t(W) %*% X2)<br>
>>    E2 <- (exp(A2) * (1 - 1 / A2) + 1 / A2) / (exp(A2) - 1)<br>
>>    E2[abs(A2) < sqrt(.Machine$double.eps) * 2 ] <- 0.5<br>
>><br>
>>    delta <- (t(X) %*% E - t(X2) %*% E2)<br>
>>    W <- W + delta<br>
><br>
> 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).<br>


><br>
> Thanks,<br>
> Xavier<br>
><br>
> --<br>
> Xavier Robin, PhD<br>
> Cellular Signal Integration Group (C-SIG) - <a href="http://www.lindinglab.org" target="_blank">http://www.lindinglab.org</a><br>
> Center for Biological Sequence Analysis (CBS) - <a href="http://www.cbs.dtu.dk" target="_blank">http://www.cbs.dtu.dk</a><br>
> Department of Systems Biology - Technical University of Denmark (DTU)<br>
> Anker Engelundsvej, Building 301, DK-2800 Lyngby, DENMARK.<br>
><br>
> _______________________________________________<br>
> Rcpp-devel mailing list<br>
> <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
<br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</div></div></blockquote></div><br></div>