-
Notifications
You must be signed in to change notification settings - Fork 22
Tips for avoiding errors in nimbleFunction programming and compilation (DSL)
Christopher Paciorek edited this page Sep 4, 2018
·
12 revisions
Chapters 11-15 of the NIMBLE manual describe how to program in NIMBLE: how to write nimbleFunctions using the NIMBLE language (NIMBLE DSL).
Writing nimbleFunction run code is similar to programming in R, but because nimbleFunctions are compiled to C++, there are some limitations on what can be done in run code.
Here we document some of the syntax that does NOT work in nimbleFunction run code and work-arounds in each case.
Syntax that doesn't work | Alternative syntax to accomplish this |
---|---|
Use of distribution parameterizations other than those in Section 11.2.4 of the manual | Manually reparameterize to one of the parameterizations in Section 11.2.4 |
Reverse indexing such as 2:1
|
Manually write a loop such as for(i in 1:L) { index[i] <- L+1-i }
|
is.na() and is.nan() are not vectorized |
Write a for loop |
is.na() does not work with logical or integer type NA values passed pasfrom R |
use as.numeric in R to convert to numeric type |
model[[nodes]] and model[[nodes[i]]] do not work when 'nodes' indicates one or more nodes or variables |
use values(model, nodes) or values(model, nodes[i])
|