1#ifndef STAN_MATH_REV_FUNCTOR_ODE_STORE_SENSITIVITIES_HPP
2#define STAN_MATH_REV_FUNCTOR_ODE_STORE_SENSITIVITIES_HPP
32template <
typename F,
typename T_y0_t0,
typename T_t0,
typename T_t,
35 scalar_type_t<Args>...>* =
nullptr>
37 const F& f,
const std::vector<double>& coupled_state,
38 const Eigen::Matrix<T_y0_t0, Eigen::Dynamic, 1>& y0,
const T_t0& t0,
39 const T_t& t, std::ostream* msgs,
const Args&... args) {
40 const size_t N = y0.size();
42 const size_t num_args_vars =
count_vars(args...);
45 Eigen::Matrix<var, Eigen::Dynamic, 1> yt(N);
48 for (
size_t n = 0; n < N; ++n) {
49 y.coeffRef(n) = coupled_state[n];
52 Eigen::VectorXd f_y_t;
56 Eigen::VectorXd f_y0_t0;
61 const size_t total_vars
62 = num_y0_vars + num_args_vars + num_t0_vars + num_t_vars;
74 Eigen::Map<Eigen::MatrixXd>
jacobian(jacobian_mem, total_vars, N);
76 for (
size_t j = 0; j < N; ++j) {
77 for (
size_t k = 0; k < num_y0_vars; ++k) {
78 jacobian.coeffRef(k, j) = coupled_state[N + num_y0_vars * k + j];
81 for (
size_t k = 0; k < num_args_vars; ++k) {
82 jacobian.coeffRef(num_y0_vars + k, j)
83 = coupled_state[N + N * num_y0_vars + N * k + j];
88 for (
size_t k = 0; k < num_y0_vars; ++k) {
89 dyt_dt0 -= f_y0_t0.coeffRef(k) * coupled_state[N + num_y0_vars * k + j];
91 jacobian.coeffRef(num_y0_vars + num_args_vars, j) = dyt_dt0;
95 jacobian.coeffRef(num_y0_vars + num_args_vars + num_t0_vars, j)
101 jacobian_mem + j * total_vars);
T * alloc_array(size_t n)
Allocate an array on the arena of the specified size to hold values of the specified template paramet...
require_any_t< is_autodiff< std::decay_t< Types > >... > require_any_autodiff_t
Require any of the types satisfy is_autodiff.
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)
T eval(T &&arg)
Inputs which have a plain_type equal to the own time are forwarded unmodified (for Eigen expressions ...
T value_of(const fvar< T > &v)
Return the value of the specified variable.
size_t count_vars(Pargs &&... args)
Count the number of vars in the input argument list.
vari ** save_varis(vari **dest, const var &x, Pargs &&... args)
Save the vari pointer in x into the memory pointed to by dest, increment the dest storage pointer,...
Eigen::VectorXd ode_store_sensitivities(const F &f, const std::vector< double > &coupled_state, const Eigen::Matrix< T_y0_t0, Eigen::Dynamic, 1 > &y0, T_t0 t0, T_t t, std::ostream *msgs, const Args &... args)
When all arguments are arithmetic, there are no sensitivities to store, so the function just returns ...
precomputed_gradients_vari_template< std::tuple<>, std::tuple<> > precomputed_gradients_vari
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Defines a static member named value which is defined to be false as the primitive scalar types cannot...
static thread_local AutodiffStackStorage * instance_