Skip to content

Commit

Permalink
Default float type to float(Real), not Real (#685)
Browse files Browse the repository at this point in the history
* Default float type to float(Real), not Real

Closes #684

* Trigger CI on backport branches/PRs

* Add integration test for #684

* Bump Turing version to 0.34 in test subfolder
  • Loading branch information
penelopeysm committed Oct 30, 2024
1 parent 18af48a commit f5e04e0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
push:
branches:
- master
- backport-*
pull_request:
branches:
- master
- backport-*
merge_group:
types: [checks_requested]

Expand Down
6 changes: 3 additions & 3 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -941,10 +941,10 @@ end
"""
float_type_with_fallback(x)
Return type corresponding to `float(typeof(x))` if possible; otherwise return `Real`.
Return type corresponding to `float(typeof(x))` if possible; otherwise return `float(Real)`.
"""
float_type_with_fallback(::Type) = Real
float_type_with_fallback(::Type{Union{}}) = Real
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)

"""
Expand Down
15 changes: 15 additions & 0 deletions test/turing/varinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,19 @@
model = state_space(y, length(t))
@test size(sample(model, NUTS(; adtype=AutoReverseDiff(true)), n), 1) == n
end

if Threads.nthreads() > 1
@testset "DynamicPPL#684: OrderedDict with multiple types when multithreaded" begin
@model function f(x)
ns ~ filldist(Normal(0, 2.0), 3)
m ~ Uniform(0, 1)
x ~ Normal(m, 1)
end
model = f(1)
chain = sample(model, NUTS(), MCMCThreads(), 10, 2);
loglikelihood(model, chain)
logprior(model, chain)
logjoint(model, chain)
end
end
end

0 comments on commit f5e04e0

Please sign in to comment.