Skip to content

Commit c68f1bb

Browse files
committed
Merge remote-tracking branch 'origin/main' into breaking
2 parents ff5f2cb + cb4ea95 commit c68f1bb

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ The reason for this change is that there were several flavours of VarInfo.
134134
Some, like `typed_varinfo`, were easy to construct because we had convenience methods for them; however, the others were more difficult.
135135
This change makes it easier to access different VarInfo types, and also makes it more explicit which one you are constructing.
136136

137+
## 0.35.9
138+
139+
Fixed the `isnan` check introduced in 0.35.7 for distributions which returned NamedTuple.
140+
137141
## 0.35.8
138142

139143
Added the `DynamicPPL.TestUtils.AD.run_ad` function to test the correctness and/or benchmark the performance of an automatic differentiation backend on DynamicPPL models.

src/debug_utils.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ function _has_missings(x::AbstractArray)
242242
return false
243243
end
244244

245+
_has_nans(x::NamedTuple) = any(_has_nans, x)
246+
_has_nans(x::AbstractArray) = any(_has_nans, x)
247+
_has_nans(x) = isnan(x)
248+
245249
# assume
246250
function record_pre_tilde_assume!(context::DebugContext, vn, dist, varinfo)
247251
record_varname!(context, vn, dist)
@@ -291,7 +295,7 @@ function record_pre_tilde_observe!(context::DebugContext, left, dist, varinfo)
291295
)
292296
end
293297
# Check for NaN's as well
294-
if any(isnan, left)
298+
if _has_nans(left)
295299
error(
296300
"Encountered a NaN value on the left-hand side of an" *
297301
" observe statement; this may indicate that your data" *

test/debug_utils.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,15 @@
130130
x[i] ~ Normal(a)
131131
end
132132
end
133-
model = demo_nan_in_data([1.0, NaN])
134-
@test_throws ErrorException check_model(model; error_on_failure=true)
133+
m = demo_nan_in_data([1.0, NaN])
134+
@test_throws ErrorException check_model(m; error_on_failure=true)
135+
# Test NamedTuples with nested arrays, see #898
136+
@model function demo_nan_complicated(nt)
137+
nt ~ product_distribution((x=Normal(), y=Dirichlet([2, 4])))
138+
return x ~ Normal()
139+
end
140+
m = demo_nan_complicated((x=1.0, y=[NaN, 0.5]))
141+
@test_throws ErrorException check_model(m; error_on_failure=true)
135142
end
136143

137144
@testset "incorrect use of condition" begin

0 commit comments

Comments
 (0)