Apologies for not providing the full example code. Adding the sin namespace didn't help,
error: invalid initialization of reference of type ‘const stan::math::var&’ from expression of type ‘stan::math::fvar<stan::math::var>’
---
#include <cmath>
#include <stan/math.hpp>
#include <iostream>
#include <Eigen/Dense>
#include <stan/math/mix/mat/functor/hessian.hpp>
#include <stan/math/prim/mat/functor/finite_diff_hessian.hpp>
struct test_functor {
};
int main() {
Eigen::Matrix<double, Eigen::Dynamic, 1> theta = Eigen::Matrix<double,
Eigen::Dynamic, 1>::Constant(6, 0), G = Eigen::Matrix<double,
Eigen::Dynamic, 1>::Zero(6);
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> H = Eigen::Matrix<
double, Eigen::Dynamic, Eigen::Dynamic>::Zero(6, 6);
test_functor f;
double cost;
stan::math::hessian(f, theta, cost, G, H); // <-- This fails
std::cout << "Gradient computed is \n" << G << "\n and Hessian is \n" << H;
return 0;
}