nimble icon indicating copy to clipboard operation
nimble copied to clipboard

Suggestion to error-trap variable names rather than node names in values()

Open perrydv opened this issue 5 years ago • 2 comments

The code

values(model, nodes) <- x

won't work if nodes is not node names but rather a variable name. The names need to be expanded first. It could be helpful to issue an informative error in this case.

perrydv avatar Feb 26 '21 18:02 perrydv

@perrydv, I can't reproduce this.

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

m = nimbleModel(code)
values(m, 'y') <- 1:5
m$y  # returns 1:5
cm = compileNimble(m)
values(cm, 'y') <- 2:6
cm$y # returns 2:6

paciorek avatar Mar 06 '21 21:03 paciorek

@perrydv any thoughts here?

It also seems fine in a nimbleFunction:

mynf <- nimbleFunction(
    setup = function(model, nodes) {},
    run = function(x = double(1)) {
        values(model,nodes) <- x
        return(values(model,nodes))
        returnType(double(1))
    })

code <- nimbleCode({
    for(i in 1:5)
        y[i]~dnorm(0,1)
})
m <- nimbleModel(code)

cm <- compileNimble(m)

rmynf <- mynf(m, 'y')
cmynf <- compileNimble(rmynf,project=m)

cmynf$run(2:6)
cm$y

paciorek avatar Apr 10 '21 15:04 paciorek