Skip to content

Commit

Permalink
fixes for debugtils
Browse files Browse the repository at this point in the history
  • Loading branch information
torfjelde committed May 17, 2024
1 parent 9098747 commit e72e003
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/debug_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions test/debug_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e72e003

Please sign in to comment.