Unit test for differentiation

The compilation error above is fixed by replacing value_of with value_of_rec, see this post.

(Code compiles and runs, though the unit tests seem to fail for the hessians.)

EDIT: The code doesn’t compute Hessians, because all the adjoint calculations are done using Eigen. Stan functions usually incur an overhead that slows down computation, and since the primary use of the function is gradient-based algorithms, I’m not keen to get a slow down.

We could add a knob to only test first-order derivatives. Something like that (in test_ad.hpp, specifically expect_ad_derivatives):

template <typename G>
void expect_ad_derivatives(const ad_tolerances& tols, const G& g,
                           const Eigen::VectorXd& x, bool test_ad_hessian = 1) {
  double gx = g(x);
  test_gradient(tols, g, x, gx);
  test_gradient_fvar(tols, g, x, gx);
  if (test_ad_hessian) {
    test_hessian(tols, g, x, gx);
    test_hessian_fvar(tols, g, x, gx);
    test_grad_hessian(tols, g, x, gx);
  }
}