From fa08760d09ff3d561799aba3f62ed944e6bec12e Mon Sep 17 00:00:00 2001 From: Tor Erlend Fjelde Date: Fri, 17 May 2024 10:17:33 +0100 Subject: [PATCH 1/2] added `check_model` fix for arrays containing `undef` --- src/debug_utils.jl | 10 +++++++++- test/debug_utils.jl | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/debug_utils.jl b/src/debug_utils.jl index d35be3b7f..dd7f3d10c 100644 --- a/src/debug_utils.jl +++ b/src/debug_utils.jl @@ -287,7 +287,15 @@ end # tilde _has_missings(x) = ismissing(x) -_has_missings(x::AbstractArray) = any(ismissing, x) +function _has_missings(x::AbstractArray) + # Can't just use `any` because `x` might contain `undef`. + for i in eachindex(x) + if isassigned(x, i) && _has_missings(x[i]) + return true + end + end + return false +end # assume function record_pre_tilde_assume!(context::DebugContext, vn, dist, varinfo) diff --git a/test/debug_utils.jl b/test/debug_utils.jl index 2a5c900e1..b1897aa9b 100644 --- a/test/debug_utils.jl +++ b/test/debug_utils.jl @@ -174,4 +174,16 @@ @test !DynamicPPL.has_static_constraints(model) end + + @testset "vector with `undef`" begin + # Source: https://github.com/TuringLang/Turing.jl/pull/2218 + @model function demo_undef(ns...) + x = Array{Real}(undef, ns...) + @. x ~ Normal(0, 2) + end + for ns in [(2,), (2, 2), (2, 2, 2)] + model = demo_undef(ns...) + @test check_model(model; error_on_failure=true) + end + end end From 1a5bad3e54daf13d87d29ed96909ea9d29e5e0c8 Mon Sep 17 00:00:00 2001 From: Tor Erlend Fjelde Date: Fri, 17 May 2024 10:21:30 +0100 Subject: [PATCH 2/2] bump patch version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 551c9ceb4..7a2d2acb0 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "DynamicPPL" uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8" -version = "0.26.1" +version = "0.26.2" [deps]