Skip to content

Commit

Permalink
use determine_suitable_varinfo in LogDensityFunction when not con…
Browse files Browse the repository at this point in the history
…structed
  • Loading branch information
torfjelde committed Nov 29, 2024
1 parent d7d785a commit dda56ec
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/logdensityfunction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,22 @@ end

function LogDensityFunction(
model::Model,
varinfo::AbstractVarInfo=VarInfo(model),
context::Union{Nothing,AbstractContext}=nothing,
)
# Determine the suitable varinfo for the given model and context.
varinfo = determine_suitable_varinfo(model, context === nothing ? leafcontext(model.context) : context)
return LogDensityFunction(varinfo, model, context)
end

function LogDensityFunction(
model::Model,
varinfo::AbstractVarInfo,
context::Union{Nothing,AbstractContext}=nothing,
)
return LogDensityFunction(varinfo, model, context)
end


# If a `context` has been specified, we use that. Otherwise we just use the leaf context of `model`.
function getcontext(f::LogDensityFunction)
return f.context === nothing ? leafcontext(f.model.context) : f.context
Expand Down

0 comments on commit dda56ec

Please sign in to comment.