[Rcpp-devel] arma::mat and Rcpp::NumericMatrix
Jeffrey Pollock
jeffpollock9 at gmail.com
Sat Sep 17 15:18:53 CEST 2011
Hey Christian,
Thanks very much for the great reply! Will do some more testing and post my
results hopefully sometime next week.
Jeff
On Fri, Sep 16, 2011 at 11:18 PM, Christian Gunning <xian at unm.edu> wrote:
> Jeff,
>
> A few random comments in addition to Dirk's sound advice:
>
> 1. I recommend using bigger matrices for testing just to get a feel.
> For testing loop speed, you want the proportion of loop time to be
> *very high* compared to the R interpreter overhead, resolution of your
> timer, etc. Here, the extra as<arma::mat> and wrap() in armaSrc may
> add appreciable execution time relative to the loop work -- only
> testing will tell :)
>
> 2. Another advantage of big matrices is testing the relative impact
> of memory copying versus in-place modification. Both Rcpp and
> RcppArmadillo allow for both -- for the former, search the quickref
> for "clone" for an intro. With RcppArmadillo, in-place is a little
> more involved, but look for this line:
> "However, if copy_aux_mem is set to false, the matrix will instead
> directly use the auxiliary memory (ie. no copying). This is faster,
> but can be dangerous unless you know what you're doing!"
> http://arma.sourceforge.net/docs.html#Mat
>
> 3. I've modified the below to move the +op from the conditional
> evaluation to the definition. For small thetaEndIndex or simple ops,
> this won't matter, but for theatEndIndex = 1e12 and something like a
> vec.size() accessor, it can make a noticeable difference. In general,
> it's a good habit not to put ops in the conditional unless you really
> need them.
>
> > armaSrc <- '
> ...
> > int thetaEndIndex = as<int>(sthetaEndIndex) - 1;
> ...
> > for (int i = thetaStartIndex + 1; i <= thetaEndIndex; i++) {
>
> best,
> Christian
>
> --
> A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110917/755b7f9e/attachment.htm>
More information about the Rcpp-devel
mailing list