diff --git a/Project.toml b/Project.toml index b92f6578..7960600c 100644 --- a/Project.toml +++ b/Project.toml @@ -3,7 +3,7 @@ uuid = "80f14c24-f653-4e6a-9b94-39d6b0f70001" keywords = ["markov chain monte carlo", "probablistic programming"] license = "MIT" desc = "A lightweight interface for common MCMC methods." -version = "4.4.1" +version = "4.4.2" [deps] BangBang = "198e06fe-97b7-11e9-32a5-e1d131e6ad66" diff --git a/src/interface.jl b/src/interface.jl index eaecb492..928a933d 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -30,13 +30,30 @@ be specified with the `chain_type` argument. By default, this method returns `samples`. """ function bundle_samples( - samples, ::AbstractModel, ::AbstractSampler, ::Any, ::Type; kwargs... + samples, model::AbstractModel, sampler::AbstractSampler, state, ::Type{T}; kwargs... +) where {T} + # dispatch to internal method for default implementations to fix + # method ambiguity issues (see #120) + return _bundle_samples(samples, model, sampler, state, T; kwargs...) +end + +function _bundle_samples( + samples, + @nospecialize(::AbstractModel), + @nospecialize(::AbstractSampler), + @nospecialize(::Any), + ::Type; + kwargs..., ) return samples end - -function bundle_samples( - samples::Vector, ::AbstractModel, ::AbstractSampler, ::Any, ::Type{Vector{T}}; kwargs... +function _bundle_samples( + samples::Vector, + @nospecialize(::AbstractModel), + @nospecialize(::AbstractSampler), + @nospecialize(::Any), + ::Type{Vector{T}}; + kwargs..., ) where {T} return map(samples) do sample convert(T, sample) diff --git a/test/sample.jl b/test/sample.jl index fcd3ab13..261cc1ef 100644 --- a/test/sample.jl +++ b/test/sample.jl @@ -564,7 +564,7 @@ @test ismissing(chain[1].a) @test mean(x.a for x in view(chain, 2:1_000)) ≈ 0.5 atol = 6e-2 @test var(x.a for x in view(chain, 2:1_000)) ≈ 1 / 12 atol = 1e-2 - @test mean(x.b for x in chain) ≈ 0 atol = 0.1 + @test mean(x.b for x in chain) ≈ 0 atol = 0.11 @test var(x.b for x in chain) ≈ 1 atol = 0.15 end