Including autodifferentiation c++ code in Rstan

Hi,
following the thread, it seems you are a novice in C++ development (this can be hard to distinguish from people not putting much work into their questions, which is probably why @bgoodri 's tone was less than friendly). While learning C++ can be hugely empowering and lets you do cool stuff you can’t do otherwise, it is also very challenging. And Stan C++ code is currently optimized for maintainability and speed, not for friendliness to beginners. If you plan to undertake this journey, keep in mind that we are mostly unable to provide support to C++ learners here (there are other sites better suited for that). As well as basic syntax, you would need at least a basic knowledge of templates and template specializations.

An example where I do some custom gradient computations that might get you started faster can be found at

It is way more complex than you need but I don’t have a better example at hand.

But I would suggest you think twice whether you really need to delve into C++. You seem to be trying to invoke the autodiff library. But this library is already used when you write your functions in Stan, so unless you have a better formula for the derivative, no improvement will happen.

Are you sure the derivatives are what is slowing down your model? I also have the experience that in some cases custom derivatives were slower than the autodiff derivatives. Or do you have other concerns than speed that motivate you to write your own derivatives?