1 #ifndef STAN_MATH_REV_MAT_FUNCTOR_JACOBIAN_HPP
2 #define STAN_MATH_REV_MAT_FUNCTOR_JACOBIAN_HPP
16 const Eigen::Matrix<double, Dynamic, 1>& x,
17 Eigen::Matrix<double, Dynamic, 1>& fx,
18 Eigen::Matrix<double, Dynamic, Dynamic>& J) {
23 Matrix<var, Dynamic, 1> x_var(x.size());
24 for (
int k = 0; k < x.size(); ++k)
26 Matrix<var, Dynamic, 1> fx_var = f(x_var);
27 fx.resize(fx_var.size());
28 for (
int i = 0; i < fx_var.size(); ++i)
29 fx(i) = fx_var(i).val();
30 J.resize(x.size(), fx_var.size());
31 for (
int i = 0; i < fx_var.size(); ++i) {
35 for (
int k = 0; k < x.size(); ++k)
36 J(k, i) = x_var(k).adj();
38 }
catch (
const std::exception&
e) {
static void set_zero_all_adjoints()
Reset all adjoint values in the stack to zero.
static void grad(chainable *vi)
Compute the gradient for all variables starting from the specified root variable implementation.
Independent (input) and dependent (output) variables for gradients.
double e()
Return the base of the natural logarithm.
static void recover_memory_nested()
Recover only the memory used for the top nested call.
void jacobian(const F &f, const Eigen::Matrix< T, Dynamic, 1 > &x, Eigen::Matrix< T, Dynamic, 1 > &fx, Eigen::Matrix< T, Dynamic, Dynamic > &J)
static void start_nested()
Record the current position so that recover_memory_nested() can find it.