157157# Utility functions #
158158# ####################
159159
160+ # TODO (DPPL0.37/penelopeysm): This function should no longer be needed
161+ # once InitContext is merged.
160162"""
161163 set_namedtuple!(vi::VarInfo, nt::NamedTuple)
162164
@@ -181,17 +183,15 @@ function set_namedtuple!(vi::DynamicPPL.VarInfoOrThreadSafeVarInfo, nt::NamedTup
181183 end
182184end
183185
184- """
185- MHLogDensityFunction
186-
187- A log density function for the MH sampler.
188-
189- This variant uses the `set_namedtuple!` function to update the `VarInfo`.
190- """
191- const MHLogDensityFunction{M<: Model ,S<: Sampler{<:MH} ,V<: AbstractVarInfo } =
192- DynamicPPL. LogDensityFunction{M,V,AD} where {AD}
193-
194- function LogDensityProblems. logdensity (f:: MHLogDensityFunction , x:: NamedTuple )
186+ # NOTE(penelopeysm): MH does not conform to the usual LogDensityProblems
187+ # interface in that it gets evaluated with a NamedTuple. Hence we need this
188+ # method just to deal with MH.
189+ # TODO (DPPL0.37/penelopeysm): Check the extent to which this method is actually
190+ # needed. If it's still needed, replace this with `init!!(f.model, f.varinfo,
191+ # ParamsInit(x))`. Much less hacky than `set_namedtuple!` (hopefully...).
192+ # In general, we should much prefer to either (1) conform to the
193+ # LogDensityProblems interface or (2) use VarNames anyway.
194+ function LogDensityProblems. logdensity (f:: LogDensityFunction , x:: NamedTuple )
195195 vi = deepcopy (f. varinfo)
196196 set_namedtuple! (vi, x)
197197 vi_new = last (DynamicPPL. evaluate!! (f. model, vi, f. context))
0 commit comments