@@ -727,7 +727,7 @@ get_cmdstan_flags <- function(flag_name) {
727727 paste(flags , collapse = " " )
728728}
729729
730- rcpp_source_stan <- function (code , env , verbose = FALSE ) {
730+ rcpp_source_stan <- function (code , env , verbose = FALSE , ... ) {
731731 cxxflags <- get_cmdstan_flags(" CXXFLAGS" )
732732 cmdstanr_includes <- system.file(" include" , package = " cmdstanr" , mustWork = TRUE )
733733 cmdstanr_includes <- paste0(" -I\" " , cmdstanr_includes ," \" " )
@@ -746,7 +746,7 @@ rcpp_source_stan <- function(code, env, verbose = FALSE) {
746746 PKG_CXXFLAGS = paste0(cxxflags , cmdstanr_includes , collapse = " " ),
747747 PKG_LIBS = libs
748748 ),
749- Rcpp :: sourceCpp(code = code , env = env , verbose = verbose )
749+ Rcpp :: sourceCpp(code = code , env = env , verbose = verbose , ... )
750750 )
751751 )
752752 invisible (NULL )
@@ -887,8 +887,12 @@ prep_fun_cpp <- function(fun_start, fun_end, model_lines) {
887887 }
888888 fun_body <- gsub(" // [[stan::function]]" , " // [[Rcpp::export]]\n " , fun_body , fixed = TRUE )
889889 fun_body <- gsub(" std::ostream\\ *\\ s*pstream__\\ s*=\\ s*nullptr" , " " , fun_body )
890- fun_body <- gsub(" boost::ecuyer1988&\\ s*base_rng__" , " SEXP base_rng_ptr" , fun_body )
891- fun_body <- gsub(" base_rng__," , " *(Rcpp::XPtr<boost::ecuyer1988>(base_rng_ptr).get())," , fun_body , fixed = TRUE )
890+ if (cmdstan_version() < " 2.35.0" ) {
891+ fun_body <- gsub(" boost::ecuyer1988&\\ s*base_rng__" , " SEXP base_rng_ptr" , fun_body )
892+ } else {
893+ fun_body <- gsub(" stan::rng_t&\\ s*base_rng__" , " SEXP base_rng_ptr" , fun_body )
894+ }
895+ fun_body <- gsub(" base_rng__," , " *(Rcpp::XPtr<stan::rng_t>(base_rng_ptr).get())," , fun_body , fixed = TRUE )
892896 fun_body <- gsub(" pstream__" , " &Rcpp::Rcout" , fun_body , fixed = TRUE )
893897 fun_body <- paste(fun_body , collapse = " \n " )
894898 gsub(pattern = " ,\\ s*)" , replacement = " )" , fun_body )
@@ -921,6 +925,7 @@ compile_functions <- function(env, verbose = FALSE, global = FALSE) {
921925 env $ hpp_code [1 : (funs [1 ] - 1 )],
922926 " #include <rcpp_tuple_interop.hpp>" ,
923927 " #include <rcpp_eigen_interop.hpp>" ,
928+ " #include <stan_rng.hpp>" ,
924929 stan_funs ),
925930 collapse = " \n " )
926931 if (global ) {
@@ -935,7 +940,7 @@ compile_functions <- function(env, verbose = FALSE, global = FALSE) {
935940 if (length(rng_funs ) > 0 ) {
936941 rng_cpp <- system.file(" include" , " base_rng.cpp" , package = " cmdstanr" , mustWork = TRUE )
937942 rcpp_source_stan(paste0(readLines(rng_cpp ), collapse = " \n " ), env , verbose )
938- env $ rng_ptr <- env $ base_rng(seed = 0 )
943+ env $ rng_ptr <- env $ base_rng(seed = 1 )
939944 }
940945
941946 # For all RNG functions, pass the initialised Boost RNG by default
0 commit comments