1 #ifndef STAN_MATH_REV_MAT_FUN_POSITIVE_ORDERED_CONSTRAIN_HPP 2 #define STAN_MATH_REV_MAT_FUN_POSITIVE_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_);
41 exp_x_[0] =
exp(x[0]);
43 for (
int n = 1; n < N_; ++n) {
44 exp_x_[n] =
exp(x[n]);
45 y[n] = y[n - 1] + exp_x_[n];
60 template <std::
size_t size>
62 const Eigen::VectorXd& adj)
const {
63 Eigen::VectorXd adj_times_jac(N_);
64 double rolling_adjoint_sum = 0.0;
66 for (
int n = N_; --n >= 0;) {
67 rolling_adjoint_sum += adj(n);
68 adj_times_jac(n) = exp_x_[n] * rolling_adjoint_sum;
71 return std::make_tuple(adj_times_jac);
85 const Eigen::Matrix<var, Eigen::Dynamic, 1>& x) {
86 return adj_jac_apply<internal::positive_ordered_constrain_op>(x);
Eigen::VectorXd operator()(const std::array< bool, size > &needs_adj, const Eigen::VectorXd &x)
Return an increasing positive ordered vector derived from the specified free vector.
static STAN_THREADS_DEF AutodiffStackStorage * instance_
auto multiply_adjoint_jacobian(const std::array< bool, size > &needs_adj, const Eigen::VectorXd &adj) const
Eigen::Matrix< T, Eigen::Dynamic, 1 > positive_ordered_constrain(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x)
Return an increasing positive ordered vector derived from the specified free vector.
fvar< T > exp(const fvar< T > &x)
T * alloc_array(size_t n)
Allocate an array on the arena of the specified size to hold values of the specified template paramet...