1#ifndef STAN_MATH_REV_CONSTRAINT_SUM_TO_ZERO_CONSTRAIN_HPP
2#define STAN_MATH_REV_CONSTRAINT_SUM_TO_ZERO_CONSTRAIN_HPP
41template <
typename T, require_rev_col_vector_t<T>* =
nullptr>
47 auto arena_y =
to_arena(std::forward<T>(y));
51 const auto N = arena_y.size();
54 for (
int i = 0; i < N; ++i) {
55 double n =
static_cast<double>(i + 1);
58 sum_u_adj += arena_z.adj()(i);
61 double v_adj = -arena_z.adj()(i + 1) * n;
63 double w_adj = v_adj + sum_u_adj;
65 arena_y.adj()(i) += w_adj /
sqrt(n * (n + 1));
97template <
typename T, require_rev_col_vector_t<T>* =
nullptr>
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
arena_t< T > to_arena(const T &a)
Converts given argument into a type that either has any dynamic allocation on AD stack or schedules i...
fvar< T > sqrt(const fvar< T > &x)
plain_type_t< Vec > sum_to_zero_constrain(const Vec &y)
Return a vector with sum zero corresponding to the specified free vector.
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 ...