hi Richard,
I'm not really following your question, but let me make a few comments that might be relevant and we can go from there.
- When a nimble model is built (even before getting to compilation to a C++ version of the model), we must be able to fully resolve the extent of indexing in for loops so as to set up the (static model) graph structure. And if we determine that there is backward indexing, we should produce a warning and generally a subsequent error caused by the backward indexing.
- In your code specifically, when you use `nrparents[k]` as a index itself or as part of an index sequence it should never be 0 for any value of `k`.
- You can only use `if` in nimble model code as described
here in the manual to be able to define multiple different models from the same code. You can't use `if` for internal logic in a nimble model, so I think you'll need to rework your model structure to remove that `if`.
- Your block of code in lines 88-103 modifies `parentnodes` AFTER it has been used to create `CDMInits`, which is then used as an input to `nimbleModel()`. So I don't see how that block of code could affect what nimble is doing. There might be something weird going on with variable scoping, as we've had some cases in the past where we weren't as careful as we should have been in preventing nimble processing from using variables from the R global environment.
-chris