@@ -29,7 +29,7 @@ Obtain new values by sampling from the prior distribution.
2929"""
3030struct InitFromPrior <: AbstractInitStrategy end
3131function init (rng:: Random.AbstractRNG , :: VarName , dist:: Distribution , :: InitFromPrior )
32- return rand (rng, dist), identity
32+ return rand (rng, dist), _typed_identity
3333end
3434
3535"""
@@ -69,7 +69,7 @@ function init(rng::Random.AbstractRNG, ::VarName, dist::Distribution, u::InitFro
6969 if x isa Array{<: Any ,0 }
7070 x = x[]
7171 end
72- return x, identity
72+ return x, _typed_identity
7373end
7474
7575"""
@@ -120,7 +120,7 @@ function init(
120120 else
121121 # TODO (penelopeysm): Since x is user-supplied, maybe we could also
122122 # check here that the type / size of x matches the dist?
123- x, identity
123+ x, _typed_identity
124124 end
125125 else
126126 p. fallback === nothing && error (" No value was provided for the variable `$(vn) `." )
@@ -238,19 +238,25 @@ function tilde_assume!!(
238238 y, fwd_logjac = with_logabsdet_jacobian (link_transform (dist), x)
239239 # Note that if we use VectorWithRanges with a full VarInfo, this double-Jacobian
240240 # calculation wastes a lot of time going from linked vectorised -> unlinked ->
241- # linked, and `inv_logjac` will also just be the negative of `fwd_logjac`. However,
242- # `VectorWithRanges` is only really used with `OnlyAccsVarInfo`, in which case this
243- # branch is never hit (since `in_varinfo` will always be false). So we can leave
244- # this branch in for full generality with other combinations of init strategies /
245- # VarInfo.
241+ # linked, and `inv_logjac` will also just be the negative of `fwd_logjac`.
242+ #
243+ # However, `VectorWithRanges` is only really used with `OnlyAccsVarInfo`, in which
244+ # case this branch is never hit (since `in_varinfo` will always be false). It does
245+ # mean that the combination of InitFromParams{<:VectorWithRanges} with a full,
246+ # linked, VarInfo will be very slow. That should never really be used, though. So
247+ # (at least for now) we can leave this branch in for full generality with other
248+ # combinations of init strategies / VarInfo.
246249 #
247250 # TODO (penelopeysm): Figure out one day how to refactor this. The crux of the issue
248251 # is that the transform used by `VectorWithRanges` is `from_linked_VEC_transform`,
249252 # which is NOT the same as `inverse(link_transform)` (because there is an additional
250253 # vectorisation step). We need `init` and `tilde_assume!!` to share this information
251254 # but it's not clear right now how to do this. In my opinion, the most productive
252- # way forward would be to standardise the behaviour of bijectors so that we can have
253- # a clean separation between the linking and vectorisation parts of it.
255+ # way forward would be to clean up the behaviour of bijectors so that we can have a
256+ # clean separation between the linking and vectorisation parts of it. That way, `x`
257+ # can either be unlinked, unlinked vectorised, linked, or linked vectorised, and
258+ # regardless of which it is, we should only need to apply at most one linking and
259+ # one vectorisation transform.
254260 y, - inv_logjac + fwd_logjac
255261 else
256262 x, - inv_logjac
0 commit comments