1#ifndef STAN_MATH_PRIM_CONSTRAINT_SUM_TO_ZERO_CONSTRAIN_HPP
2#define STAN_MATH_PRIM_CONSTRAINT_SUM_TO_ZERO_CONSTRAIN_HPP
38template <
typename Vec, require_eigen_col_vector_t<Vec>* =
nullptr,
39 require_not_st_var<Vec>* =
nullptr>
41 const auto N = y.size();
51 for (
int i = N; i > 0; --i) {
52 double n =
static_cast<double>(i);
53 auto w = y_ref(i - 1) *
inv_sqrt(n * (n + 1));
56 z.coeffRef(i - 1) += sum_w;
57 z.coeffRef(i) -= w * n;
88template <
typename Vec, require_eigen_col_vector_t<Vec>* =
nullptr,
89 require_not_st_var<Vec>* =
nullptr>
123template <
bool Jacobian,
typename Vec, require_not_std_vector_t<Vec>* =
nullptr>
157template <
bool Jacobian,
typename T, require_std_vector_t<T>* =
nullptr>
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
plain_type_t< Vec > sum_to_zero_constrain(const Vec &y)
Return a vector with sum zero corresponding to the specified free vector.
fvar< T > inv_sqrt(const fvar< T > &x)
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...