Skip to content
Closed
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -777,11 +777,15 @@ end
"""
float_type_with_fallback(T::DataType)

Return `float(T)` if possible; otherwise return `float(Real)`.
Return `T` if it is a non-integer Real, `float(T)` for integer types, and `float(Real)` otherwise.
"""
float_type_with_fallback(::Type) = float(Real)
float_type_with_fallback(::Type{Union{}}) = float(Real)
float_type_with_fallback(::Type{T}) where {T<:Real} = float(T)
float_type_with_fallback(::Type{Real}) = float(Real)
float_type_with_fallback(::Type{T}) where {T<:Integer} = float(T)
# This final case is responsible not only for plain old Float64, but also things like
# ForwardDiff.Dual, etc. See https://github.com/TuringLang/DynamicPPL.jl/pull/1088.
float_type_with_fallback(::Type{T}) where {T<:Real} = T

"""
infer_nested_eltype(x::Type)
Expand Down
44 changes: 21 additions & 23 deletions test/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,29 +370,27 @@ const GDEMO_DEFAULT = DynamicPPL.TestUtils.demo_assume_observe_literal()
end
end

Comment on lines 370 to 372
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change to the code here, just removing the redundant VERSION check since our min bound is 1.10.

if VERSION >= v"1.8"
@testset "Type stability of models" begin
models_to_test = [
DynamicPPL.TestUtils.DEMO_MODELS..., DynamicPPL.TestUtils.demo_lkjchol(2)
]
@testset "$(model.f)" for model in models_to_test
vns = DynamicPPL.TestUtils.varnames(model)
example_values = DynamicPPL.TestUtils.rand_prior_true(model)
varinfos = filter(
is_type_stable_varinfo,
DynamicPPL.TestUtils.setup_varinfos(model, example_values, vns),
)
@testset "$(short_varinfo_name(varinfo))" for varinfo in varinfos
@test begin
@inferred(DynamicPPL.evaluate!!(model, varinfo))
true
end

varinfo_linked = DynamicPPL.link(varinfo, model)
@test begin
@inferred(DynamicPPL.evaluate!!(model, varinfo_linked))
true
end
@testset "Type stability of models" begin
models_to_test = [
DynamicPPL.TestUtils.DEMO_MODELS..., DynamicPPL.TestUtils.demo_lkjchol(2)
]
@testset "$(model.f)" for model in models_to_test
vns = DynamicPPL.TestUtils.varnames(model)
example_values = DynamicPPL.TestUtils.rand_prior_true(model)
varinfos = filter(
is_type_stable_varinfo,
DynamicPPL.TestUtils.setup_varinfos(model, example_values, vns),
)
@testset "$(short_varinfo_name(varinfo))" for varinfo in varinfos
@test begin
@inferred(DynamicPPL.evaluate!!(model, varinfo))
true
end

varinfo_linked = DynamicPPL.link(varinfo, model)
@test begin
@inferred(DynamicPPL.evaluate!!(model, varinfo_linked))
true
end
end
end
Expand Down