Skip to content

Commit 96cf6ef

Browse files
committed
Remove eltype, matchingvalue, get_matching_type
1 parent ea6b6de commit 96cf6ef

File tree

5 files changed

+9
-78
lines changed

5 files changed

+9
-78
lines changed

src/abstract_varinfo.jl

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -611,29 +611,6 @@ julia> values_as(vi, Vector)
611611
"""
612612
function values_as end
613613

614-
"""
615-
eltype(vi::AbstractVarInfo)
616-
617-
Return the `eltype` of the values returned by `vi[:]`.
618-
619-
!!! warning
620-
This should generally not be called explicitly, as it's only used in
621-
[`matchingvalue`](@ref) to determine the default type to use in place of
622-
type-parameters passed to the model.
623-
624-
This method is considered legacy, and is likely to be deprecated in the future.
625-
"""
626-
function Base.eltype(vi::AbstractVarInfo)
627-
T = Base.promote_op(getindex, typeof(vi), Colon)
628-
if T === Union{}
629-
# In this case `getindex(vi, :)` errors
630-
# Let us throw a more descriptive error message
631-
# Ref https://github.com/TuringLang/Turing.jl/issues/2151
632-
return eltype(vi[:])
633-
end
634-
return eltype(T)
635-
end
636-
637614
"""
638615
has_varnamedvector(varinfo::VarInfo)
639616

src/compiler.jl

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -707,53 +707,3 @@ function warn_empty(body)
707707
end
708708
return nothing
709709
end
710-
711-
# TODO(mhauru) matchingvalue has methods that can accept both types and values. Why?
712-
# TODO(mhauru) This function needs a more comprehensive docstring.
713-
"""
714-
matchingvalue(vi, value)
715-
716-
Convert the `value` to the correct type for the `vi` object.
717-
"""
718-
function matchingvalue(vi, value)
719-
T = typeof(value)
720-
if hasmissing(T)
721-
_value = convert(get_matching_type(vi, T), value)
722-
# TODO(mhauru) Why do we make a deepcopy, even though in the !hasmissing branch we
723-
# are happy to return `value` as-is?
724-
if _value === value
725-
return deepcopy(_value)
726-
else
727-
return _value
728-
end
729-
else
730-
return value
731-
end
732-
end
733-
734-
function matchingvalue(vi, value::FloatOrArrayType)
735-
return get_matching_type(vi, value)
736-
end
737-
function matchingvalue(vi, ::TypeWrap{T}) where {T}
738-
return TypeWrap{get_matching_type(vi, T)}()
739-
end
740-
741-
# TODO(mhauru) This function needs a more comprehensive docstring. What is it for?
742-
"""
743-
get_matching_type(vi, ::TypeWrap{T}) where {T}
744-
745-
Get the specialized version of type `T` for `vi`.
746-
"""
747-
get_matching_type(_, ::Type{T}) where {T} = T
748-
function get_matching_type(vi, ::Type{<:Union{Missing,AbstractFloat}})
749-
return Union{Missing,float_type_with_fallback(eltype(vi))}
750-
end
751-
function get_matching_type(vi, ::Type{<:AbstractFloat})
752-
return float_type_with_fallback(eltype(vi))
753-
end
754-
function get_matching_type(vi, ::Type{<:Array{T,N}}) where {T,N}
755-
return Array{get_matching_type(vi, T),N}
756-
end
757-
function get_matching_type(vi, ::Type{<:Array{T}}) where {T}
758-
return Array{get_matching_type(vi, T)}
759-
end

src/model.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,9 +933,9 @@ Return the arguments and keyword arguments to be passed to the evaluator of the
933933
) where {_F,argnames}
934934
unwrap_args = [
935935
if is_splat_symbol(var)
936-
:($matchingvalue(varinfo, model.args.$var)...)
936+
:(deepcopy(model.args.$var)...)
937937
else
938-
:($matchingvalue(varinfo, model.args.$var))
938+
:(deepcopy(model.args.$var))
939939
end for var in argnames
940940
]
941941
return quote

src/simple_varinfo.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,6 @@ const SimpleOrThreadSafeSimple{T,V,C} = Union{
412412
SimpleVarInfo{T,V,C},ThreadSafeVarInfo{<:SimpleVarInfo{T,V,C}}
413413
}
414414

415-
# Necessary for `matchingvalue` to work properly.
416-
Base.eltype(::SimpleOrThreadSafeSimple{<:Any,V}) where {V} = V
417-
418415
# `subset`
419416
function subset(varinfo::SimpleVarInfo, vns::AbstractVector{<:VarName})
420417
return SimpleVarInfo(

test/compiler.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
module DynamicPPLCompilerTests
2+
3+
using DynamicPPL, Distributions, Random, Test
4+
using LinearAlgebra: I
5+
16
macro custom(expr)
27
(Meta.isexpr(expr, :call, 3) && expr.args[1] === :~) || error("incorrect macro usage")
38
quote
@@ -794,3 +799,5 @@ module Issue537 end
794799
@test res == (a=1, b=1, c=2, d=2, t=DynamicPPL.TypeWrap{Int}())
795800
end
796801
end
802+
803+
end # module DynamicPPLCompilerTests

0 commit comments

Comments
 (0)