[Rcpp-devel] problem with sample() implemented in Rcpp/RcppArmadillo
Dirk Eddelbuettel
edd at debian.org
Sat Oct 27 16:50:23 CEST 2012
On 27 October 2012 at 05:13, Christian Gunning wrote:
| > I am very new to c++ so I apologize in advance if this is a stupid question:
|
| I ran into this myself when I started using Rcpp -- it's a good
| question. The R API is extensive, but it's vanilla C and doesn't
| handle vectors (and you already know how to sample() a scalar,
| right?).
Someone should sit down and write a C++ variant of sample for Rcpp. Having a
starting point would help, others can then tune.
Personally, I don't have a need for one so no itch to scratch...
| > For a larger analysis I am trying to implement the R function sample() in c++ via RcppArmadillo.
|
| There's a non-trivial penalty for reaching back into R for functions
| that aren't exported via the API (e.g. "Rcpp::Function sample =
| base["sample"];").
Correct.
| Rcpp Vectors are STL containers,
Incorrect.
We make them look like STL containers by giving them begin(),
end(), ... member functions but they are still R objects ("SEXP") underneath.
That means in particular that the carefully crafted STL algos with their
performance guarantees will NOT have these guarantees.
That said, we can easily wrap genuine STL vectors so the rest of you argument
is good :)
| and many folk have asked the same questions wrt the STL. There's some good
| background reading here:
| http://stackoverflow.com/questions/6942273/get-random-element-from-container-c-stl
Nice reference, and "+1" for going back to standard STL functions and
behaviour which (in my not so humble opinions) is one of the best approaches
one can undertake when writing C++.
Dirk
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel
mailing list