Skip to content

Commit

Permalink
Seed set location
Browse files Browse the repository at this point in the history
  • Loading branch information
andrjohns committed May 17, 2024
1 parent 1d76ca7 commit 707c1fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
1 change: 0 additions & 1 deletion inst/include/stan_rng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <boost/random/additive_combine.hpp>
#include <stan/version.hpp>
#include <Rcpp.h>

// A consistent rng_t is defined from 2.35 onwards
// so add a fallback for older versions
Expand Down
24 changes: 21 additions & 3 deletions tests/testthat/test-model-expose-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -346,17 +346,35 @@ test_that("rng functions can be exposed", {
mod <- cmdstan_model(model, force_recompile = TRUE)
fit <- mod$sample(data = data_list)

set.seed(10)
fit$expose_functions(verbose = TRUE)
set.seed(10)
res <- fit$functions$wrap_normal_rng(5,10)

expect_equal(
res,
# Stan RNG changed in 2.35
ifelse(cmdstan_version() < "2.35.0", 1.217251562, 20.49842178)
)
res <- fit$functions$wrap_normal_rng(5,10)

expect_equal(
res,
ifelse(cmdstan_version() < "2.35.0", -0.1426366567, 12.93498553)
)

# Test that the RNG function respects set.seed
set.seed(10)
res <- fit$functions$wrap_normal_rng(5,10)

expect_equal(
fit$functions$wrap_normal_rng(5,10),
res,
# Stan RNG changed in 2.35
ifelse(cmdstan_version() < "2.35.0", 1.217251562, 20.49842178)
)
res <- fit$functions$wrap_normal_rng(5,10)

expect_equal(
fit$functions$wrap_normal_rng(5,10),
res,
ifelse(cmdstan_version() < "2.35.0", -0.1426366567, 12.93498553)
)
})
Expand Down

0 comments on commit 707c1fb

Please sign in to comment.