Skip to content

Commit 90f7d6b

Browse files
committed
feat: warn on ±Inf values in check_model observe statements
1 parent 03079d5 commit 90f7d6b

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

src/debug_utils.jl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,15 @@ Check if `x` is `NaN`, or contains any `NaN` values.
7171
_has_nans(x::NamedTuple) = any(_has_nans, x)
7272
_has_nans(x::AbstractArray) = any(_has_nans, x)
7373
_has_nans(x) = isnan(x)
74-
_has_nans(::Missing) = false
74+
"""
75+
_has_infs(x)
76+
77+
Check if `x` is `Inf` or `-Inf`, or contains any such values.
78+
"""
79+
_has_infs(x::NamedTuple) = any(_has_infs, x)
80+
_has_infs(x::AbstractArray) = any(_has_infs, x)
81+
_has_infs(x) = isinf(x)
82+
_has_infs(::Missing) = false
7583

7684
function DynamicPPL.accumulate_assume!!(
7785
acc::DebugAccumulator, val, tval, logjac, vn::VarName, right::Distribution, template
@@ -98,12 +106,13 @@ function DynamicPPL.accumulate_observe!!(
98106
@warn full_msg
99107
failed = true
100108
end
101-
# Check for NaN's as well
102-
if _has_nans(val)
109+
# Check for Inf values, but only warn if the logpdf at that value is -Inf
110+
# (i.e., Inf is not in the support of the distribution)
111+
if _has_infs(val) && isinf(logpdf(right, val))
103112
msg =
104-
"Encountered a NaN value on the left-hand side of an" *
113+
"Encountered an infinite value on the left-hand side of an" *
105114
" observe statement; this may indicate that your data" *
106-
" contain NaN values."
115+
" contain Inf or -Inf values."
107116
@warn msg
108117
failed = true
109118
end

0 commit comments

Comments
 (0)