[Rcpp-devel] copying or not when convering to arma

Gabor Grothendieck ggrothendieck at gmail.com
Wed Jul 10 17:58:00 CEST 2013


Suppose we have this program where we have started and ended with SEXP
and written out the as and wrap conversions to make them explicit.

How many times is the data copied?
Does as copy the underlying data?
Does wrap?
Is it copied elsewhere?
Which file in the source code would one look to determine this?
If it does copy the data is there some way to tell as and wrap to just
point to it to avoid copying?

#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
SEXP test(SEXP v) {
   arma::vec va = Rcpp::as<arma::vec>(v);
   SEXP vs = Rcpp::wrap(va);
   return vs;
}


# run it from R
sourceCpp("test.cpp")
test(c(1.2, 1.3, 1.4))


--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com


More information about the Rcpp-devel mailing list