@@ -231,20 +231,17 @@ function record_varname!(context::DebugContext, varname::VarName, dist)
231
231
end
232
232
end
233
233
234
- # tilde
235
- _isassigned (x:: AbstractArray , i) = isassigned (x, i)
236
- # HACK(torfjelde): Julia v1.7 only supports `isassigned(::AbstractArray, ::Int...)`.
237
- # TODO (torfjelde): Determine exactly in which version this change was introduced.
238
- if VERSION < v " v1.9.0-alpha1"
239
- _isassigned (x:: AbstractArray , inds:: Tuple ) = isassigned (x, inds... )
240
- _isassigned (x:: AbstractArray , idx:: CartesianIndex ) = _isassigned (x, Tuple (idx))
234
+ function _check_nan (logp)
235
+ if isnan (logp)
236
+ @warn " Encountered a NaN logp value; this may indicate that your data contains NaN values"
237
+ end
241
238
end
242
239
243
240
_has_missings (x) = ismissing (x)
244
241
function _has_missings (x:: AbstractArray )
245
242
# Can't just use `any` because `x` might contain `undef`.
246
243
for i in eachindex (x)
247
- if _isassigned (x, i) && _has_missings (x[i])
244
+ if isassigned (x, i) && _has_missings (x[i])
248
245
return true
249
246
end
250
247
end
274
271
function DynamicPPL. tilde_assume (context:: DebugContext , right, vn, vi)
275
272
record_pre_tilde_assume! (context, vn, right, vi)
276
273
value, logp, vi = DynamicPPL. tilde_assume (childcontext (context), right, vn, vi)
274
+ _check_nan (logp)
277
275
record_post_tilde_assume! (context, vn, right, value, logp, vi)
278
276
return value, logp, vi
279
277
end
@@ -284,6 +282,7 @@ function DynamicPPL.tilde_assume(
284
282
value, logp, vi = DynamicPPL. tilde_assume (
285
283
rng, childcontext (context), sampler, right, vn, vi
286
284
)
285
+ _check_nan (logp)
287
286
record_post_tilde_assume! (context, vn, right, value, logp, vi)
288
287
return value, logp, vi
289
288
end
@@ -316,12 +315,14 @@ end
316
315
function DynamicPPL. tilde_observe (context:: DebugContext , right, left, vi)
317
316
record_pre_tilde_observe! (context, left, right, vi)
318
317
logp, vi = DynamicPPL. tilde_observe (childcontext (context), right, left, vi)
318
+ _check_nan (logp)
319
319
record_post_tilde_observe! (context, left, right, logp, vi)
320
320
return logp, vi
321
321
end
322
322
function DynamicPPL. tilde_observe (context:: DebugContext , sampler, right, left, vi)
323
323
record_pre_tilde_observe! (context, left, right, vi)
324
324
logp, vi = DynamicPPL. tilde_observe (childcontext (context), sampler, right, left, vi)
325
+ _check_nan (logp)
325
326
record_post_tilde_observe! (context, left, right, logp, vi)
326
327
return logp, vi
327
328
end
474
475
475
476
Check that `model` is valid, warning about any potential issues.
476
477
477
- See [`check_model_and_trace`](@ref) for more details on supported keword arguments
478
+ See [`check_model_and_trace`](@ref) for more details on supported keyword arguments
478
479
and details of which types of checks are performed.
479
480
480
481
# Returns
0 commit comments