Skip to content

Commit ca06c8b

Browse files
committed
fix Transition for empty model
1 parent a605900 commit ca06c8b

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/mcmc/Inference.jl

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,23 @@ struct Transition{T,F<:AbstractFloat,N<:NamedTuple} <: AbstractTransition
166166
logprior = DynamicPPL.getlogprior(vi)
167167
loglikelihood = DynamicPPL.getloglikelihood(vi)
168168

169-
# Convert values to the format needed (with individual VarNames split up).
170-
# TODO(penelopeysm): This wouldn't be necessary if not for MCMCChains's poor
171-
# representation...
172-
iters = map(
173-
DynamicPPL.varname_and_value_leaves,
174-
keys(vals_as_in_model),
175-
values(vals_as_in_model),
176-
)
177-
values_split = mapreduce(collect, vcat, iters)
169+
# Convert values to the format needed (i.e. a Vector of (varname,
170+
# value) tuples, where value isa Real: all vector-valued varnames must
171+
# be split up.)
172+
# TODO(penelopeysm): This wouldn't be necessary if not for MCMCChains's
173+
# poor representation...
174+
values_split = if isempty(vals_as_in_model)
175+
# If there are no values, we return an empty vector.
176+
# This is the case for models with no parameters.
177+
Vector{Tuple{VarName,Any}}()
178+
else
179+
iters = map(
180+
DynamicPPL.varname_and_value_leaves,
181+
keys(vals_as_in_model),
182+
values(vals_as_in_model),
183+
)
184+
mapreduce(collect, vcat, iters)
185+
end
178186

179187
# Get additional statistics
180188
stats = getstats(sampler_transition)

0 commit comments

Comments
 (0)