1 #ifndef STAN_MATH_REV_MAT_FUNCTOR_GRADIENT_HPP
2 #define STAN_MATH_REV_MAT_FUNCTOR_GRADIENT_HPP
43 const Eigen::Matrix<double, Eigen::Dynamic, 1>& x,
45 Eigen::Matrix<double, Eigen::Dynamic, 1>& grad_fx) {
48 Eigen::Matrix<var, Eigen::Dynamic, 1> x_var(x.size());
49 for (
int i = 0; i < x.size(); ++i)
51 var fx_var = f(x_var);
53 grad_fx.resize(x.size());
55 for (
int i = 0; i < x.size(); ++i)
56 grad_fx(i) = x_var(i).adj();
57 }
catch (
const std::exception& ) {
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.
vari * vi_
Pointer to the implementation of this variable.
static void recover_memory_nested()
Recover only the memory used for the top nested call.
double val() const
Return the value of this variable.
void gradient(const F &f, const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, T &fx, Eigen::Matrix< T, Eigen::Dynamic, 1 > &grad_fx)
Calculate the value and the gradient of the specified function at the specified argument.
static void start_nested()
Record the current position so that recover_memory_nested() can find it.