1 #ifndef STAN_MATH_REV_MAT_FUN_ORDERED_CONSTRAIN_HPP 2 #define STAN_MATH_REV_MAT_FUN_ORDERED_CONSTRAIN_HPP 30 template <std::
size_t size>
31 Eigen::VectorXd
operator()(
const std::array<bool, size>& needs_adj,
32 const Eigen::VectorXd& x) {
35 Eigen::Matrix<double, Eigen::Dynamic, 1> y(N_);
42 for (
int n = 1; n < N_; ++n) {
43 exp_x_[n - 1] =
exp(x[n]);
44 y[n] = y[n - 1] + exp_x_[n - 1];
59 template <std::
size_t size>
61 const Eigen::VectorXd& adj)
const {
62 Eigen::VectorXd adj_times_jac(N_);
63 double rolling_adjoint_sum = 0.0;
66 for (
int n = N_ - 1; n > 0; --n) {
67 rolling_adjoint_sum += adj(n);
68 adj_times_jac(n) = exp_x_[n - 1] * rolling_adjoint_sum;
70 adj_times_jac(0) = rolling_adjoint_sum + adj(0);
73 return std::make_tuple(adj_times_jac);
87 const Eigen::Matrix<var, Eigen::Dynamic, 1>& x) {
88 return adj_jac_apply<internal::ordered_constrain_op>(x);
Eigen::Matrix< T, Eigen::Dynamic, 1 > ordered_constrain(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x)
Return an increasing ordered vector derived from the specified free vector.
static STAN_THREADS_DEF AutodiffStackStorage * instance_
fvar< T > exp(const fvar< T > &x)
Eigen::VectorXd operator()(const std::array< bool, size > &needs_adj, const Eigen::VectorXd &x)
Return an increasing ordered vector derived from the specified free vector.
auto multiply_adjoint_jacobian(const std::array< bool, size > &needs_adj, const Eigen::VectorXd &adj) const
T * alloc_array(size_t n)
Allocate an array on the arena of the specified size to hold values of the specified template paramet...