1 #ifndef STAN_MATH_MIX_MAT_FUNCTOR_GRAD_TR_MAT_TIMES_HESSIAN_HPP
2 #define STAN_MATH_MIX_MAT_FUNCTOR_GRAD_TR_MAT_TIMES_HESSIAN_HPP
21 const Eigen::Matrix<double, Eigen::Dynamic, 1>& x,
22 const Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>& M,
23 Eigen::Matrix<double, Eigen::Dynamic, 1>& grad_tr_MH
29 grad_tr_MH.resize(x.size());
31 Matrix<var, Dynamic, 1> x_var(x.size());
32 for (
int i = 0; i < x.size(); ++i)
35 Matrix<fvar<var>, Dynamic, 1> x_fvar(x.size());
38 Matrix<double, Dynamic, 1> M_n(x.size());
39 for (
int n = 0; n < x.size(); ++n) {
40 for (
int k = 0; k < x.size(); ++k)
42 for (
int k = 0; k < x.size(); ++k)
46 gradient_dot_vector<fvar<var>,
double>(f, x_fvar, M_n, fx,
48 sum += grad_fx_dot_v.
d_;
52 for (
int i = 0; i < x.size(); ++i)
53 grad_tr_MH(i) = x_var(i).adj();
54 }
catch (
const std::exception&
e) {
fvar< T > sum(const std::vector< fvar< T > > &m)
Return the sum of the entries of the specified standard vector.
void grad_tr_mat_times_hessian(const F &f, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &x, const Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > &M, Eigen::Matrix< double, Eigen::Dynamic, 1 > &grad_tr_MH)
Independent (input) and dependent (output) variables for gradients.
static void grad(vari *vi)
Compute the gradient for all variables starting from the specified root variable implementation.
double e()
Return the base of the natural logarithm.
static void recover_memory_nested()
Recover only the memory used for the top nested call.
static void start_nested()
Record the current position so that recover_memory_nested() can find it.