nimble-dev / nimble

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

inconsistent uncompiled model handling of initialization #1446

Open paciorek opened 4 months ago

paciorek commented 4 months ago

Depending on whether project is provided, we can get an R error related to whether project is an array (resulting in a nonconformable array error or not (in which case uncompiled behavior is fine).

## here `m$project` is an array
code<- nimbleCode({
        p3[1:3,1:2] <- project[1:3]  + yday[1:3,1:2]
})
m <- nimbleModel(code)
# Error in model$project[1:3] + model$yday[1:3, 1:2] : 
#  non-conformable arrays

## here `m$project` is numeric
code<- nimbleCode({
        p3[1:3,1:2] <- project[1:3]  + yday[1:3,1:2]
})
m <- nimbleModel(code, inits = list(project = rnorm(3)))

I think this has to do with the fact that we initialize variables as arrays with a given dimension when no inits/data/constants info is provided.

paciorek commented 4 months ago

Note that after compilation, these result in run-time size errors (also seen in issue #1425), so this may to some degree by subsumed by that issue.