Automatic Differentiation
 
Loading...
Searching...
No Matches
gradient_dot_vector.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_MIX_FUNCTOR_GRADIENT_DOT_VECTOR_HPP
2#define STAN_MATH_MIX_FUNCTOR_GRADIENT_DOT_VECTOR_HPP
3
7#include <vector>
8
9namespace stan {
10namespace math {
11
12template <typename T1, typename T2, typename F>
13void gradient_dot_vector(const F& f,
14 const Eigen::Matrix<T1, Eigen::Dynamic, 1>& x,
15 const Eigen::Matrix<T2, Eigen::Dynamic, 1>& v, T1& fx,
16 T1& grad_fx_dot_v) {
17 using Eigen::Matrix;
18 Matrix<fvar<T1>, Eigen::Dynamic, 1> x_fvar(x.size());
19 for (int i = 0; i < x.size(); ++i) {
20 x_fvar(i) = fvar<T1>(x(i), v(i));
21 }
22 fvar<T1> fx_fvar = f(x_fvar);
23 fx = fx_fvar.val_;
24 grad_fx_dot_v = fx_fvar.d_;
25}
26
27} // namespace math
28} // namespace stan
29#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)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Scalar val_
The value of this variable.
Definition fvar.hpp:49
Scalar d_
The tangent (derivative) of this variable.
Definition fvar.hpp:61
This template class represents scalars used in forward-mode automatic differentiation,...
Definition fvar.hpp:40