ordinary recursive functions are OK, ditto ordinary _lmpf functions:
recursive _lpdf, _lmpf incur problems:
any suggestions for what needs to be done to generate c++ code that will compile with proper type templates allowing functions to be called in transformed data, transformed parameters, model, and generated quantities blocks?
Here’s a more minimal functional and non-functional example:
functions {
real foo(real x);
real foo(real x) {
return x < 2 ? 1 : x * foo(x / 2);
}
}
model {
1 ~ normal(foo(3.2), 1);
}
functions {
real foo_lpdf(real x);
real foo_lpdf(real x) {
return x < 2 ? 1 : x * foo_lpdf(x / 2);
}
}
model {
3.2 ~ foo();
}
I think the problem is that the nested calls to foo_lpdf aren’t passing in the propto template parameter and there’s no way to infer it. It’s not a general problem with an extra bool template parameter, because this is OK C++:
#include <iostream>
template <bool a, typename T>
T foo(const T& x);
template <bool a, typename T>
T foo(const T& x) {
return x < 2 ? x : x * foo<a>(x / 2);
}
int main() {
std::cout << "foo<true>(5) = " << foo<true>(5) << std::endl;
}
But it won’t work if the template parameters aren’t instantiated.