Skip to content

Commit

Permalink
Move has_varnamedvector(varinfo::VarInfo) to abstract_varinfo.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
mhauru committed Sep 17, 2024
1 parent 5bbba91 commit 851630f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 9 additions & 2 deletions src/abstract_varinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,13 @@ function Base.eltype(vi::AbstractVarInfo, spl::Union{AbstractSampler,SampleFromP
return eltype(T)
end

"""
has_varnamedvector(varinfo::VarInfo)
Returns `true` if `varinfo` uses `VarNamedVector` as metadata.
"""
has_varnamedvector(vi::AbstractVarInfo) = false

# TODO: Should relax constraints on `vns` to be `AbstractVector{<:Any}` and just try to convert
# the `eltype` to `VarName`? This might be useful when someone does `[@varname(x[1]), @varname(m)]` which
# might result in a `Vector{Any}`.
Expand Down Expand Up @@ -554,7 +561,7 @@ end
link([t::AbstractTransformation, ]vi::AbstractVarInfo, model::Model)
link([t::AbstractTransformation, ]vi::AbstractVarInfo, spl::AbstractSampler, model::Model)
Transform the variables in `vi` to their linked space without mutating `vi`, using the transformation `t`.
Transform the variables in `vi` to their linked space without mutating `vi`, using the transformation `t`.
If `t` is not provided, `default_transformation(model, vi)` will be used.
Expand All @@ -573,7 +580,7 @@ end
invlink!!([t::AbstractTransformation, ]vi::AbstractVarInfo, model::Model)
invlink!!([t::AbstractTransformation, ]vi::AbstractVarInfo, spl::AbstractSampler, model::Model)
Transform the variables in `vi` to their constrained space, using the (inverse of)
Transform the variables in `vi` to their constrained space, using the (inverse of)
transformation `t`, mutating `vi` if possible.
If `t` is not provided, `default_transformation(model, vi)` will be used.
Expand Down
6 changes: 0 additions & 6 deletions src/varinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,6 @@ function VectorVarInfo(vi::TypedVarInfo)
return VarInfo(md, Base.RefValue{eltype(lp)}(lp), Ref(get_num_produce(vi)))
end

"""
has_varnamedvector(varinfo::VarInfo)
Returns `true` if `varinfo` uses `VarNamedVector` as metadata.
"""
has_varnamedvector(vi::AbstractVarInfo) = false
function has_varnamedvector(vi::VarInfo)
return vi.metadata isa VarNamedVector ||
(vi isa TypedVarInfo && any(Base.Fix2(isa, VarNamedVector), values(vi.metadata)))
Expand Down

0 comments on commit 851630f

Please sign in to comment.