Skip to content

chains methods claim to be generic but only work on MCMCChains #1072

@penelopeysm

Description

@penelopeysm

function pointwise_logdensities(
model::Model, chain, ::Type{KeyType}=VarName, ::Val{whichlogprob}=Val(:both)
) where {KeyType,whichlogprob}

DynamicPPL.jl/src/varinfo.jl

Lines 1837 to 1839 in 9bd8f16

function setval!(vi::VarInfo, chains::AbstractChains, sample_idx::Int, chain_idx::Int)
return setval!(vi, chains.value[sample_idx, :, chain_idx], keys(chains))
end

These functions claim to work either on chain::Any or chain::AbstractMCMC.AbstractChains. In practice the first one calls the second, so the first should only work on AbstractChains. However there is no guarantee that an AbstractChains type can be indexed into using chains.value[iter, :, chain]. This makes assumptions about the internal structure of chains which are only true of MCMCChains.Chains.

niters = size(chain, 1)
nchains = size(chain, 3)

There is also no guarantee that size(chain, 1) or size(chain, 3) return the number of iterations or chains respectively. Again this is only true for MCMCChains.

All these functions' signatures should be restricted to MCMCChains and moved to MCMCChainsExt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions