Stan Math Library  2.20.0
reverse mode automatic differentiation
grad.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_MAT_FUN_GRAD_HPP
2 #define STAN_MATH_REV_MAT_FUN_GRAD_HPP
3 
4 #include <stan/math/rev/meta.hpp>
7 #include <stan/math/rev/core.hpp>
8 
9 namespace stan {
10 namespace math {
11 
25 inline void grad(var& v, Eigen::Matrix<var, Eigen::Dynamic, 1>& x,
26  Eigen::VectorXd& g) {
27  grad(v.vi_);
28  g.resize(x.size());
29  for (int i = 0; i < x.size(); ++i)
30  g(i) = x(i).vi_->adj_;
31 }
32 
33 } // namespace math
34 } // namespace stan
35 #endif
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:33
static void grad(vari *vi)
Compute the gradient for all variables starting from the specified root variable implementation.
Definition: grad.hpp:30
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:45

     [ Stan Home Page ] © 2011–2018, Stan Development Team.