Skip to content

Commit

Permalink
Fix method ambiguity issues (#123)
Browse files Browse the repository at this point in the history
* Fix method ambiguity issues

* Fix format

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update tolerances

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
devmotion and github-actions[bot] authored Jun 20, 2023
1 parent e149f9f commit d7c549f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
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

2 comments on commit d7c549f

@devmotion
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/85939

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v4.4.2 -m "<description of version>" d7c549fe41a80c1f164423c7ac458425535f624b
git push origin v4.4.2

Please sign in to comment.