Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix method ambiguity issues #123

Merged
merged 3 commits into from
Jun 20, 2023
Merged
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 21 additions & 4 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down