Skip to content

Commit 2a0fbf2

Browse files
committed
let's try with DynamicPPLAny
1 parent 8a91ab7 commit 2a0fbf2

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/varinfo.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
# VarInfo metadata #
77
####################
88

9+
abstract type DynamicPPLAny end
10+
Base.convert(::Type{DynamicPPLAny}, x) = x
11+
Base.zero(::Type{DynamicPPLAny}) = zero(LogProbType)
12+
913
"""
1014
The `Metadata` struct stores some metadata about the parameters of the model. This helps
1115
query certain information about a variable, such as its distribution, which samplers
@@ -37,7 +41,7 @@ struct Metadata{
3741
TIdcs<:Dict{<:VarName,Int},
3842
TDists<:AbstractVector{<:Distribution},
3943
TVN<:AbstractVector{<:VarName},
40-
TVal<:AbstractVector{<:Any},
44+
TVal<:AbstractVector{<:DynamicPPLAny},
4145
}
4246
# Mapping from the `VarName` to its integer index in `vns`, `ranges` and `dists`
4347
idcs::TIdcs # Dict{<:VarName,Int}
@@ -51,7 +55,7 @@ struct Metadata{
5155

5256
# Vector of values of all the univariate, multivariate and matrix variables
5357
# The value(s) of `vn` is/are `vals[ranges[idcs[vn]]]`
54-
vals::TVal # AbstractVector{<:Any}
58+
vals::TVal # AbstractVector{<:DynamicPPLAny}
5559

5660
# Vector of distributions correpsonding to `vns`
5761
dists::TDists # AbstractVector{<:Distribution}
@@ -409,7 +413,7 @@ unflatten_metadata(vnv::VarNamedVector, x::AbstractVector) = unflatten(vnv, x)
409413
Construct an empty type unstable instance of `Metadata`.
410414
"""
411415
function Metadata()
412-
vals = Vector{Any}()
416+
vals = Vector{DynamicPPLAny}()
413417
flags = Dict{String,BitVector}()
414418
flags["del"] = BitVector()
415419
flags["trans"] = BitVector()
@@ -576,8 +580,8 @@ function merge_metadata(metadata_left::Metadata, metadata_right::Metadata)
576580
T_right = eltype(metadata_right.vals)
577581
T = promote_type(T_left, T_right)
578582
# TODO: Is this necessary?
579-
if !(T <: Any)
580-
T = Any
583+
if !(T <: DynamicPPLAny)
584+
T = DynamicPPLAny
581585
end
582586

583587
# Determine `eltype` of `dists`.
@@ -766,8 +770,8 @@ getindex_internal(vi::VarInfo, ::Colon) = getindex_internal(vi.metadata, Colon()
766770
function getindex_internal(vi::NTVarInfo, ::Colon)
767771
return reduce(vcat, map(Base.Fix2(getindex_internal, Colon()), vi.metadata))
768772
end
769-
function getindex_internal(vi::VarInfo{NamedTuple{(),Tuple{}}}, ::Colon)
770-
return Any[]
773+
function getindex_internal(::VarInfo{NamedTuple{(),Tuple{}}}, ::Colon)
774+
return DynamicPPLAny[]
771775
end
772776
function getindex_internal(md::Metadata, ::Colon)
773777
return mapreduce(

0 commit comments

Comments
 (0)