68
68
69
69
Return a default varinfo object for the given `model` and `sampler`.
70
70
71
- The default method for this returns an empty NTVarInfo (i.e. 'typed varinfo').
71
+ The default method for this returns a NTVarInfo (i.e. 'typed varinfo').
72
72
73
73
# Arguments
74
74
- `rng::Random.AbstractRNG`: Random number generator.
@@ -78,10 +78,14 @@ The default method for this returns an empty NTVarInfo (i.e. 'typed varinfo').
78
78
# Returns
79
79
- `AbstractVarInfo`: Default varinfo object for the given `model` and `sampler`.
80
80
"""
81
- function default_varinfo (:: Random.AbstractRNG , :: Model , :: AbstractSampler )
82
- # Note that variable values are unconditionally initialized later, so no
83
- # point putting them in now.
84
- return typed_varinfo (VarInfo ())
81
+ function default_varinfo (rng:: Random.AbstractRNG , model:: Model , :: AbstractSampler )
82
+ # Note that in `AbstractMCMC.step`, the values in the varinfo returned here are
83
+ # immediately overwritten by a subsequent call to `init!!`. The reason why we
84
+ # _do_ create a varinfo with parameters here (as opposed to simply returning
85
+ # an empty `typed_varinfo(VarInfo())`) is to avoid issues where pushing to an empty
86
+ # typed VarInfo would fail. This can happen if two VarNames have different types
87
+ # but share the same symbol (e.g. `x.a` and `x.b`).
88
+ return typed_varinfo (VarInfo (rng, model))
85
89
end
86
90
87
91
"""
@@ -131,8 +135,8 @@ function AbstractMCMC.step(
131
135
initial_params:: AbstractInitStrategy = init_strategy (spl),
132
136
kwargs... ,
133
137
)
134
- # Generate the default varinfo (usually this just makes an empty VarInfo
135
- # with NamedTuple of Metadata) .
138
+ # Generate the default varinfo. Note that any parameters inside this varinfo
139
+ # will be immediately overwritten by the next call to `init!!` .
136
140
vi = default_varinfo (rng, model, spl)
137
141
138
142
# Fill it with initial parameters. Note that, if `InitFromParams` is used, the
0 commit comments