Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork219
Description
With Rcpp 0.12.16, mysimcross package started throwing errors in the tests. I don't fully understand what's going on, but it seems related to me callingrunif(n,0,L) withn==0.
Consider the following code (alsoavailable as a gist). This simulates a Poisson process on the interval (0,L) by drawing a Poisson number of points and then drawing their positions from a uniform distribution. There are two versions of the function; in the first, I don't try to trap then==0 cases; in the latter I callrunif() only withn>0.
#include<Rcpp.h>usingnamespaceRcpp;// [[Rcpp::export]]NumericVectorsim_crossovers_orig(constdouble L){int n_xo; n_xo =R::rpois(L/100.0); NumericVector tmp =runif(n_xo,0.0, L);return tmp.sort();}// [[Rcpp::export]]NumericVectorsim_crossovers_new(constdouble L){int n_xo; n_xo =R::rpois(L/100.0); NumericVectortmp(0);if(n_xo >0) tmp =runif(n_xo,0.0, L);return tmp.sort();}
With Rcpp ver 0.12.15, these two functions give the same results.
Rcpp::sourceCpp("sim_crossovers.cpp")set.seed(20180318)z <- replicate(10000, sim_crossovers_orig(100))table(sapply(z, length))## 0 1 2 3 4 5 6## 3661 3681 1837 631 151 35 4set.seed(20180318)z <- replicate(10000, sim_crossovers_new(100))table(sapply(z, length))## 0 1 2 3 4 5 6## 3661 3681 1837 631 151 35 4But with Rcpp ver 0.12.16, the former gives a ton of 0-length vectors, while the latter works fine, though it gives somewhat different results from ver 0.12.15. (The tables being printed should be 10,000 draws from a Poisson distribution with mean 1.)
Rcpp::sourceCpp("sim_crossovers.cpp")set.seed(20180318)z <- replicate(10000, sim_crossovers_orig(100))table(sapply(z, length))## 0 1 3## 9994 5 1set.seed(20180318)z <- replicate(10000, sim_crossovers_new(100))table(sapply(z, length))## 0 1 2 3 4 5 6## 3637 3698 1846 621 152 41 5I've tried this in both Linux and MacOS (High Sierra), and with R 3.4.3 and 3.4.4, with the same results in all cases. (Just the version of Rcpp matters.)
Here's my session info in the Rcpp 0.12.16 case on my Mac:
R version 3.4.4 (2018-03-15)Platform: x86_64-apple-darwin15.6.0 (64-bit)Running under: macOS High Sierra 10.13.3Matrix products: defaultBLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylibLAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dyliblocale:[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8attached base packages:[1] stats graphics grDevices utils datasets methods baseother attached packages:[1] Rcpp_0.12.16 devtools_1.13.5loaded via a namespace (and not attached):[1] compiler_3.4.4 tools_3.4.4 withr_2.1.1.9000 memoise_1.1.0 digest_0.6.15