1 #ifndef STAN_MATH_REV_MAT_FUNCTOR_JACOBIAN_HPP
2 #define STAN_MATH_REV_MAT_FUNCTOR_JACOBIAN_HPP
16 const Eigen::Matrix<double, Eigen::Dynamic, 1>& x,
17 Eigen::Matrix<double, Eigen::Dynamic, 1>& fx,
18 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>& J) {
24 Matrix<var, Dynamic, 1> x_var(x.size());
25 for (
int k = 0; k < x.size(); ++k)
27 Matrix<var, Dynamic, 1> fx_var = f(x_var);
28 fx.resize(fx_var.size());
29 for (
int i = 0; i < fx_var.size(); ++i)
30 fx(i) = fx_var(i).val();
31 J.resize(fx_var.size(), x.size());
32 for (
int i = 0; i < fx_var.size(); ++i) {
36 for (
int k = 0; k < x.size(); ++k)
37 J(i, k) = x_var(k).adj();
39 }
catch (
const std::exception&
e) {
static void set_zero_all_adjoints_nested()
Reset all adjoint values in the top nested portion of the stack to zero.
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.
void jacobian(const F &f, const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, Eigen::Matrix< T, Eigen::Dynamic, 1 > &fx, Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &J)
double e()
Return the base of the natural logarithm.
static void recover_memory_nested()
Recover only the memory used for the top nested call.
static void start_nested()
Record the current position so that recover_memory_nested() can find it.