Skip to content

Commit 278a82a

Browse files
authored
Fix for check_model on arrays with undef (#608)
* fixes for debugtils * bump patch version
1 parent 9098747 commit 278a82a

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DynamicPPL"
22
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
3-
version = "0.27.0"
3+
version = "0.27.1"
44

55

66
[deps]

src/debug_utils.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,15 @@ end
287287

288288
# tilde
289289
_has_missings(x) = ismissing(x)
290-
_has_missings(x::AbstractArray) = any(ismissing, x)
290+
function _has_missings(x::AbstractArray)
291+
# Can't just use `any` because `x` might contain `undef`.
292+
for i in eachindex(x)
293+
if isassigned(x, i) && _has_missings(x[i])
294+
return true
295+
end
296+
end
297+
return false
298+
end
291299

292300
# assume
293301
function record_pre_tilde_assume!(context::DebugContext, vn, dist, varinfo)

test/debug_utils.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,16 @@
174174

175175
@test !DynamicPPL.has_static_constraints(model)
176176
end
177+
178+
@testset "vector with `undef`" begin
179+
# Source: https://github.com/TuringLang/Turing.jl/pull/2218
180+
@model function demo_undef(ns...)
181+
x = Array{Real}(undef, ns...)
182+
@. x ~ Normal(0, 2)
183+
end
184+
for ns in [(2,), (2, 2), (2, 2, 2)]
185+
model = demo_undef(ns...)
186+
@test check_model(model; error_on_failure=true)
187+
end
188+
end
177189
end

0 commit comments

Comments
 (0)