From 40f9586f4234cc807a54c262d926c40604b7a108 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Sat, 17 Jun 2023 15:03:29 +0200 Subject: [PATCH 1/3] Fix method ambiguity issues --- Project.toml | 2 +- src/interface.jl | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) 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..c327ea62 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -30,19 +30,28 @@ 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) end end + """ step(rng, model, sampler[, state; kwargs...]) From 21d8634ace9898e6c16843b116ff533f64dbd72e Mon Sep 17 00:00:00 2001 From: David Widmann Date: Sat, 17 Jun 2023 15:12:37 +0200 Subject: [PATCH 2/3] Fix format Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/interface.jl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index c327ea62..928a933d 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -38,20 +38,28 @@ function bundle_samples( end function _bundle_samples( - samples, @nospecialize(::AbstractModel), @nospecialize(::AbstractSampler), @nospecialize(::Any), ::Type; kwargs... + samples, + @nospecialize(::AbstractModel), + @nospecialize(::AbstractSampler), + @nospecialize(::Any), + ::Type; + kwargs..., ) return samples end - function _bundle_samples( - samples::Vector, @nospecialize(::AbstractModel), @nospecialize(::AbstractSampler), @nospecialize(::Any), ::Type{Vector{T}}; kwargs... + samples::Vector, + @nospecialize(::AbstractModel), + @nospecialize(::AbstractSampler), + @nospecialize(::Any), + ::Type{Vector{T}}; + kwargs..., ) where {T} return map(samples) do sample convert(T, sample) end end - """ step(rng, model, sampler[, state; kwargs...]) From ffb7b43b4182eac97a610d725b6c6811c4b49a78 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Mon, 19 Jun 2023 20:55:04 +0200 Subject: [PATCH 3/3] Update tolerances --- test/sample.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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