Hey Christian,<br><br>Thanks very much for the great reply! Will do some more testing and post my results hopefully sometime next week.<br><br>Jeff<br><br><div class="gmail_quote">On Fri, Sep 16, 2011 at 11:18 PM, Christian Gunning <span dir="ltr"><<a href="mailto:xian@unm.edu">xian@unm.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Jeff,<br>
<br>
A few random comments in addition to Dirk's sound advice:<br>
<br>
1. I recommend using bigger matrices for testing just to get a feel.<br>
For testing loop speed, you want the proportion of loop time to be<br>
*very high* compared to the R interpreter overhead, resolution of your<br>
timer, etc. Here, the extra as<arma::mat> and wrap() in armaSrc may<br>
add appreciable execution time relative to the loop work -- only<br>
testing will tell :)<br>
<br>
2. Another advantage of big matrices is testing the relative impact<br>
of memory copying versus in-place modification. Both Rcpp and<br>
RcppArmadillo allow for both -- for the former, search the quickref<br>
for "clone" for an intro. With RcppArmadillo, in-place is a little<br>
more involved, but look for this line:<br>
"However, if copy_aux_mem is set to false, the matrix will instead<br>
directly use the auxiliary memory (ie. no copying). This is faster,<br>
but can be dangerous unless you know what you're doing!"<br>
<a href="http://arma.sourceforge.net/docs.html#Mat" target="_blank">http://arma.sourceforge.net/docs.html#Mat</a><br>
<br>
3. I've modified the below to move the +op from the conditional<br>
evaluation to the definition. For small thetaEndIndex or simple ops,<br>
this won't matter, but for theatEndIndex = 1e12 and something like a<br>
vec.size() accessor, it can make a noticeable difference. In general,<br>
it's a good habit not to put ops in the conditional unless you really<br>
need them.<br>
<br>
> armaSrc <- '<br>
...<br>
> int thetaEndIndex = as<int>(sthetaEndIndex) - 1;<br>
...<br>
> for (int i = thetaStartIndex + 1; i <= thetaEndIndex; i++) {<br>
<br>
best,<br>
Christian<br>
<font color="#888888"><br>
--<br>
A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!<br>
</font></blockquote></div><br>