I want to add a new function that deals with infinite sums. What is the Stan procedure in dealing with the precision?

Shall I fix it to a specific value? Is there a “Stan-precision-value” commonly used? Or should I give the precision to the parameters such that the user of my function can set an individual precision?

Hi, @Franzi. Although we don’t have a standard per se, we’ve leaned toward high precision over high speed in all of our implementations.

For iterative algorithms like ODE solvers, we have versions that allow user-defined control of precision through tolerance arguments.

So I guess the question is whether the max precision you can get is going to be a lot slower than more modest precision, and if so, are there situations where the reduced precision is worth the tradeoff? If so, I’d suggest adding a precision parameter to the function if that’s possible and overloading it with a second implementation that just choose a relatively high precision.

Hi @Bob, now I tried for a few days to adapt my function in the way that I can allow a precision parameter with a default value for the case the user does not provide an own precision value. But I have not yet found a way that works.

Is prec, which i assume to be precision, intended to be of a var type? In other words how is prec's gradient intended to be used? The signature should work if prec is just a simple double, otherwise the type T_prec needs to be specified when the function is called.

Also related, to avoid loss of precision in sum, use something like Kahan’s algorithm instead of naive implementation.

It’s worth noting that if you’re interested in playing with the details of ODE solvers to get a specified precision, it might be worth it to try out Turing.jl, a PPL very similar to Stan that’s embedded in Julia. Not sure which will work better for your particular use case, but Turing gives you more flexibility since it lets you include any Julia package when you’re running your model.

Ok. Thanks for all the input! From all the comments, I conclude for my case to set the precision internally and don’t give the user the chance to vary it on his own wish.