arviz-devs / ArviZ.jl
1 20
stack(x::AbstractParticles) = Array(x)
2
function stack(v::AbstractArray{<:AbstractParticles})
3 20
    m = reduce(hcat, stack.(v))
4 20
    return Array(reshape(m, size(m, 1), size(v)...))
5
end
6

7
"""
8
    convert_to_inference_data(obj::AbstractParticles; kwargs...) -> InferenceData
9
    convert_to_inference_data(
10
        obj::AbstractVector{<:AbstractParticles};
11
        kwargs...,
12
    ) -> InferenceData
13
    convert_to_inference_data(
14
        obj::AbstractVector{<:AbstractArray{<:AbstractParticles}};
15
        kwargs...,
16
    ) -> InferenceData
17

18
Convert `MonteCarloMeasurements.AbstractParticles` to an [`InferenceData`](@ref).
19

20
`obj` may have the following types:
21

22
  - `::AbstractParticles`: Univariate draws from a single chain.
23
  - `::AbstractVector{<:AbstractParticles}`: Univariate draws from a vector of chains.
24
  - `::AbstractVector{<:AbstractArray{<:AbstractParticles}}`: Multivariate draws from a vector
25
    of chains.
26
"""
27
function convert_to_inference_data(obj::AbstractParticles; kwargs...)
28 20
    return convert_to_inference_data([obj]; kwargs...)
29
end
30
function convert_to_inference_data(obj::AbstractVector{<:AbstractParticles}; kwargs...)
31 20
    return convert_to_inference_data(stack(stack.(obj)); kwargs...)
32
end
33
function convert_to_inference_data(
34
    obj::AbstractVector{<:AbstractArray{<:AbstractParticles}}; kwargs...
35
)
36 20
    return convert_to_inference_data(stack(stack.(obj)); kwargs...)
37
end

Read our documentation on viewing source code .

Loading