Skip to content

Commit

Permalink
Merge branch 'master' into torfjelde/initial-state
Browse files Browse the repository at this point in the history
  • Loading branch information
torfjelde committed Oct 1, 2023
2 parents 117598b + d7c549f commit debf3ac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
4 changes: 2 additions & 2 deletions 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 All @@ -24,7 +24,7 @@ ConsoleProgressMonitor = "0.1"
LogDensityProblems = "2"
LoggingExtras = "0.4, 0.5, 1"
ProgressLogging = "0.1"
StatsBase = "0.32, 0.33"
StatsBase = "0.32, 0.33, 0.34"
TerminalLoggers = "0.1"
Transducers = "0.4.30"
julia = "1.6"
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

0 comments on commit debf3ac

Please sign in to comment.