Skip to content

Change default Metadata value type to Any #1003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/varinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
# VarInfo metadata #
####################

abstract type DynamicPPLAny end
Base.convert(::Type{DynamicPPLAny}, x) = x
Base.zero(::Type{DynamicPPLAny}) = zero(LogProbType)

"""
The `Metadata` struct stores some metadata about the parameters of the model. This helps
query certain information about a variable, such as its distribution, which samplers
Expand Down Expand Up @@ -37,7 +41,7 @@ struct Metadata{
TIdcs<:Dict{<:VarName,Int},
TDists<:AbstractVector{<:Distribution},
TVN<:AbstractVector{<:VarName},
TVal<:AbstractVector{<:Real},
TVal<:AbstractVector{<:DynamicPPLAny},
}
# Mapping from the `VarName` to its integer index in `vns`, `ranges` and `dists`
idcs::TIdcs # Dict{<:VarName,Int}
Expand All @@ -51,7 +55,7 @@ struct Metadata{

# Vector of values of all the univariate, multivariate and matrix variables
# The value(s) of `vn` is/are `vals[ranges[idcs[vn]]]`
vals::TVal # AbstractVector{<:Real}
vals::TVal # AbstractVector{<:DynamicPPLAny}

# Vector of distributions correpsonding to `vns`
dists::TDists # AbstractVector{<:Distribution}
Expand Down Expand Up @@ -409,7 +413,7 @@ unflatten_metadata(vnv::VarNamedVector, x::AbstractVector) = unflatten(vnv, x)
Construct an empty type unstable instance of `Metadata`.
"""
function Metadata()
vals = Vector{Real}()
vals = Vector{DynamicPPLAny}()
flags = Dict{String,BitVector}()
flags["del"] = BitVector()
flags["trans"] = BitVector()
Expand Down Expand Up @@ -576,8 +580,8 @@ function merge_metadata(metadata_left::Metadata, metadata_right::Metadata)
T_right = eltype(metadata_right.vals)
T = promote_type(T_left, T_right)
# TODO: Is this necessary?
if !(T <: Real)
T = Real
if !(T <: DynamicPPLAny)
T = DynamicPPLAny
end

# Determine `eltype` of `dists`.
Expand Down Expand Up @@ -766,8 +770,8 @@ getindex_internal(vi::VarInfo, ::Colon) = getindex_internal(vi.metadata, Colon()
function getindex_internal(vi::NTVarInfo, ::Colon)
return reduce(vcat, map(Base.Fix2(getindex_internal, Colon()), vi.metadata))
end
function getindex_internal(vi::VarInfo{NamedTuple{(),Tuple{}}}, ::Colon)
return float(Real)[]
function getindex_internal(::VarInfo{NamedTuple{(),Tuple{}}}, ::Colon)
return DynamicPPLAny[]
end
function getindex_internal(md::Metadata, ::Colon)
return mapreduce(
Expand Down
Loading