nimble-dev / nimble

The base NIMBLE package for R
http://R-nimble.org
BSD 3-Clause "New" or "Revised" License
158 stars 24 forks source link

`as.list` fails on single-sample compiled modelValues of non-scalar parameter #1476

Closed danielturek closed 3 months ago

danielturek commented 4 months ago

The title says it all.

Minimal reproducible example below:


library(nimble)

code <- nimbleCode({
    for(i in 1:3) {
        x[i] ~ dnorm(0, 1)
    }
})

Rmodel <- nimbleModel(code, inits = list(x=1:3))
Rmcmc <- buildMCMC(Rmodel)
compiledList <- compileNimble(list(model=Rmodel, mcmc=Rmcmc))
Cmcmc <- compiledList$mcmc

set.seed(0)
Rmcmc$run(1)
as.list(Rmcmc$mvSamples)

## $x
##          [,1]       [,2]     [,3]
## [1,] 1.262954 -0.3262334 1.329799

set.seed(0)
Cmcmc$run(1)
as.list(Cmcmc$mvSamples)    ## INCORRECT

## $x
##          [,1]
## [1,] 1.262954
paciorek commented 3 months ago

Trivial issue with as.list.CmodelValues getting the wrong length because the one-element modelValues is ending up as a vector rather than a one-element list. Fixing directly on devel.