Hello Stanimaniacs,
Now I’d like to use associated legendre function of the first kind in Stan.
As well as this topic(Legendre polynomials), I tried to import C++ function to Stan. Checked the milestone in PyStan, I used version 2.18.0 released one weeks ago because it looks that introduce utility is now available,
First I tested import from Stan file checking this issue(https://github.com/stan-dev/pystan/issues/365), and it goes well. Next I tried importing besselK function from C++ file as this article(https://cran.r-project.org/web/packages/rstan/vignettes/external.html) explained, but it failed. Then, I noticed that PyStan disallow the undefined function and cannot be changed(Line 141 in https://github.com/stan-dev/pystan/blob/v2.18.0.0/pystan/api.py). Above example doesn’t have the example about including hpp file with include declaration. Is there any method to use C++ function in PyStan?
The Stan file I tried is
functions {
#include besselK.hpp
real besselK(real v, real z);
}
model {}
, hpp file is
template <typename T0__, typename T1__>
auto
besselK(const T0__& v, const T1__& z, std::ostream* pstream__) -> decltype(v + z) {
return boost::math::cyl_bessel_k(v, z);
}
, and Python command is
from pystan import StanModel
model = StanModel(file="besselK.stan")