1#ifndef STAN_MATH_REV_CONSTRAINT_ORDERED_CONSTRAIN_HPP
2#define STAN_MATH_REV_CONSTRAINT_ORDERED_CONSTRAIN_HPP
24template <
typename T, require_rev_col_vector_t<T>* =
nullptr>
35 Eigen::VectorXd y_val(N);
39 y_val.coeffRef(0) = arena_x.val().coeff(0);
40 for (Eigen::Index n = 1; n < N; ++n) {
41 exp_x.coeffRef(n - 1) =
exp(arena_x.val().coeff(n));
42 y_val.coeffRef(n) = y_val.coeff(n - 1) + exp_x.coeff(n - 1);
48 double rolling_adjoint_sum = 0.0;
50 for (
int n = arena_x.size() - 1; n > 0; --n) {
51 rolling_adjoint_sum += y.adj().coeff(n);
52 arena_x.adj().coeffRef(n) += exp_x.coeff(n - 1) * rolling_adjoint_sum;
54 arena_x.adj().coeffRef(0) += rolling_adjoint_sum + y.adj().coeff(0);
72template <
typename VarVec, require_var_col_vector_t<VarVec>* =
nullptr>
75 lp +=
sum(x.tail(x.size() - 1));
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
plain_type_t< EigVec > ordered_constrain(const EigVec &x)
Return an increasing ordered vector derived from the specified free vector.
fvar< T > exp(const fvar< T > &x)
typename plain_type< T >::type plain_type_t
typename scalar_type< T >::type scalar_type_t
typename internal::arena_type_impl< std::decay_t< T > >::type arena_t
Determines a type that can be used in place of T that does any dynamic allocations on the AD stack.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...