From dea62bbda0f0d732a22faba1702fef3922a8b4b5 Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Sat, 21 Dec 2024 20:18:48 +0000 Subject: [PATCH] Add a test for `values_as_in_model(rng, model, ...)` --- test/model.jl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/model.jl b/test/model.jl index 52380898e..96c0f1560 100644 --- a/test/model.jl +++ b/test/model.jl @@ -396,6 +396,22 @@ const GDEMO_DEFAULT = DynamicPPL.TestUtils.demo_assume_observe_literal() end end end + + @testset "check that sampling obeys rng if passed" begin + @model function f() + x ~ Normal(0) + return y ~ Normal(x) + end + model = f() + # Call values_as_in_model with the rng + values = values_as_in_model(Random.Xoshiro(43), model, false) + # Check that they match the values that would be used if vi was seeded + # with that seed instead + expected_vi = VarInfo(Random.Xoshiro(43), model) + for vn in keys(values) + @test values[vn] == expected_vi[vn] + end + end end @testset "Erroneous model call" begin