I'm having trouble compiling a model which I think has something with how I'm declaring something. The idea is that observations by various persons and time points are coming from different distributions, so I've set up an array `tasks[i,it]` (passed as a constant) saying which one to use at each time point. I've also set up a function list to do the indirection:
```
Irt <- nimbleFunctionVirtual(
run = function(theta=double(0)) {returnType(double(1,3))}
)
IrtItemPool <- nimbleFunction(
setup = function (irtmod,plist) {
J <- length(plist)
itemfuns <- nimbleFunctionList(Irt)
for (task in 1:J)
itemfuns[[task]] <- do.call(irtmod,plist[task])
setupOutputs(J,itemfuns)
},
run = function(task=integer(0),theta=double(0)) {
returnType(double(1,3))
return(itemfuns[[task]]$run(theta))
})
```
So the idea is that `theta` is the critical parameter, and the `ItemPool` function selects the `ItemFunction` according to the discrete task argument.
Here is the model code:
```
constGrowthCode <- nimbleCode({
for (i in 1L:N) {
theta[i,1L] ~ dnorm(mu0,sig0)
for (it in 2L:(NT)) {
theta[i,it] ~dnorm(theta[i,it-1L] + growthRate, growthSD)
}
}
for (i in 1L:N) {
for (it in 1L:NT) {
p[i,it,1L:3L] <- itempool$run(tasks[i,it],theta[i,it])
y[i,it] ~dcat(p[i,it,])
}
}
# Priors omitted
)
```
However, this gives me an error:
```
P_16_constGrowt_MID_27_nfCode.cpp:1092:42: error: cannot convert ‘TYPE_’ {aka ‘CppAD::AD<double>’} to ‘double’
1092 | Interm_690 = (*itempool).run(Interm_688, Interm_689);
| ^~~~~~~~~~
| |
| TYPE_ {aka CppAD::AD<double>}
```
I don't understand how the compiler is deciding whether to map a variable to a double or an AD<double>. Does this have something to do with the automatic differentiation?