[Rcpp-devel] Sample function(s) for inclusion in RcppArmadillo
Christian Gunning
xian at unm.edu
Fri Sep 26 12:41:15 CEST 2014
Dear all,
The Walker Alias method is now (finally) implemented, along with unit
tests. To my knowledge, the only thing not implemented is R's sample2
- a special version of sample.int for (!replace && is.null(prob) && n
> 1e+07 && size <= n/2).
I also added rmultinom, which behaves how an R API C function call
might, providing a single draw. E.g., in R, rmultinom(1, size, prob).
It's the user's responsibility to normalize probabilities with the
provided function Fixup, which I moved from sample.h to a separate
file, fixup.h.
rmultinom does throw a range_error in probs don't sum to ~1.
Pull request is here:
https://github.com/RcppCore/RcppArmadillo/pull/22
Best,
Christian
On Thu, Mar 28, 2013 at 11:18 PM, Christian Gunning <xian at unm.edu> wrote:
> Dirk,
>
> See attached for minor edits related to Walker Alias method. Based on
> the timing tests from the gallery draft and discussion with Johnathan,
> we decided it was a bad idea to include code that deviates from R's
> behavior, and is slower than R to boot. Thus, the C++ sample now
> throws an informative error under the appropriate conditions. I
> updated the unitTests accordingly (and cleaned them up a bit).
>
> Incidentally, there's now a stub in place for Walker Alias method
> sample function, as well as an associated unitTest that's now
> commented out.
> -Christian
--
A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!
More information about the Rcpp-devel
mailing list