Stan Math Library  2.14.0
reverse mode automatic differentiation
gradient_dot_vector.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_MIX_MAT_FUNCTOR_GRADIENT_DOT_VECTOR_HPP
2 #define STAN_MATH_MIX_MAT_FUNCTOR_GRADIENT_DOT_VECTOR_HPP
3 
4 #include <stan/math/fwd/core.hpp>
6 #include <stan/math/rev/core.hpp>
7 #include <vector>
8 
9 namespace stan {
10  namespace math {
11 
12  template <typename T1, typename T2, typename F>
13  void
14  gradient_dot_vector(const F& f,
15  const Eigen::Matrix<T1, Eigen::Dynamic, 1>& x,
16  const Eigen::Matrix<T2, Eigen::Dynamic, 1>& v,
17  T1& fx,
18  T1& grad_fx_dot_v) {
19  using Eigen::Matrix;
20  Matrix<fvar<T1>, Eigen::Dynamic, 1> x_fvar(x.size());
21  for (int i = 0; i < x.size(); ++i)
22  x_fvar(i) = fvar<T1>(x(i), v(i));
23  fvar<T1> fx_fvar = f(x_fvar);
24  fx = fx_fvar.val_;
25  grad_fx_dot_v = fx_fvar.d_;
26  }
27 
28  }
29 }
30 #endif
void gradient_dot_vector(const F &f, const Eigen::Matrix< T1, Eigen::Dynamic, 1 > &x, const Eigen::Matrix< T2, Eigen::Dynamic, 1 > &v, T1 &fx, T1 &grad_fx_dot_v)

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