Skip to content

Commit 7fb88b6

Browse files
committed
Differentiate model and function rng
1 parent c6be00d commit 7fb88b6

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

R/utils.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,9 @@ expose_model_methods <- function(env, verbose = FALSE, hessian = FALSE) {
760760
}
761761

762762
initialize_model_pointer <- function(env, datafile_path, seed = 0) {
763-
env$model_ptr_ <- env$model_ptr(ifelse(is.null(datafile_path), "", datafile_path), seed)
763+
ptr_and_rng <- env$model_ptr(ifelse(is.null(datafile_path), "", datafile_path), seed)
764+
env$model_ptr_ <- ptr_and_rng$model_ptr
765+
env$model_rng_ <- ptr_and_rng$base_rng
764766
env$num_upars_ <- env$get_num_upars(env$model_ptr_)
765767
env$param_metadata_ <- env$get_param_metadata(env$model_ptr_)
766768
invisible(NULL)

inst/include/model_methods.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <Rcpp.h>
22
#include <stan/model/log_prob_grad.hpp>
33
#include <stan/model/log_prob_propto.hpp>
4+
#include <boost/random/additive_combine.hpp>
45
#ifdef CMDSTAN_JSON
56
#include <cmdstan/io/json/json_data.hpp>
67
#else
@@ -25,12 +26,15 @@ using json_data_t = stan::json::json_data;
2526
}
2627

2728
// [[Rcpp::export]]
28-
SEXP model_ptr(std::string data_path, boost::uint32_t seed) {
29+
Rcpp::List model_ptr(std::string data_path, boost::uint32_t seed) {
2930
Rcpp::XPtr<stan_model> ptr(
30-
new stan_model(*var_context(data_path), seed, &Rcpp::Rcout),
31-
true
31+
new stan_model(*var_context(data_path), seed, &Rcpp::Rcout)
32+
);
33+
Rcpp::XPtr<boost::ecuyer1988> base_rng(new boost::ecuyer1988(seed));
34+
return Rcpp::List::create(
35+
Rcpp::Named("model_ptr") = ptr,
36+
Rcpp::Named("base_rng") = base_rng
3237
);
33-
return ptr;
3438
}
3539

3640
// [[Rcpp::export]]

0 commit comments

Comments
 (0)