From 707c1fb2c1262e21fe5d830a56d584040275e083 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Fri, 17 May 2024 23:55:22 +0300 Subject: [PATCH] Seed set location --- inst/include/stan_rng.hpp | 1 - tests/testthat/test-model-expose-functions.R | 24 +++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/inst/include/stan_rng.hpp b/inst/include/stan_rng.hpp index 8dc55dde..834464f7 100644 --- a/inst/include/stan_rng.hpp +++ b/inst/include/stan_rng.hpp @@ -3,7 +3,6 @@ #include #include -#include // A consistent rng_t is defined from 2.35 onwards // so add a fallback for older versions diff --git a/tests/testthat/test-model-expose-functions.R b/tests/testthat/test-model-expose-functions.R index 50a5c372..863b7f29 100644 --- a/tests/testthat/test-model-expose-functions.R +++ b/tests/testthat/test-model-expose-functions.R @@ -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) ) })