1 #ifndef STAN_MATH_REV_FUN_GRAD_HPP
2 #define STAN_MATH_REV_FUN_GRAD_HPP
3 
4 #include <stan/math/rev/meta.hpp>
5 #include <stan/math/rev/core.hpp>
6 #include <stan/math/prim/fun/Eigen.hpp>
7 
8 namespace stan {
9 namespace math {
10 
11 /**
12  * Propagate chain rule to calculate gradients starting from
13  * the specified variable.  Resizes the input vector to be the
14  * correct size.
15  *
16  * The grad() function does not itself recover any memory.  use
17  * <code>recover_memory()</code> or
18  * <code>recover_memory_nested()</code> to recover memory.
19  *
20  * @param[in] v Value of function being differentiated
21  * @param[in] x Variables being differentiated with respect to
22  * @param[out] g Gradient, d/dx v, evaluated at x.
23  */
grad(var & v,Eigen::Matrix<var,Eigen::Dynamic,1> & x,Eigen::VectorXd & g)24 inline void grad(var& v, Eigen::Matrix<var, Eigen::Dynamic, 1>& x,
25                  Eigen::VectorXd& g) {
26   grad(v.vi_);
27   g = x.adj();
28 }
29 
30 }  // namespace math
31 }  // namespace stan
32 #endif
33