1#ifndef STAN_MATH_REV_CONSTRAINT_SIMPLEX_CONSTRAIN_HPP
2#define STAN_MATH_REV_CONSTRAINT_SIMPLEX_CONSTRAIN_HPP
29template <
typename T, require_rev_col_vector_t<T>* =
nullptr>
31 using ret_type = plain_type_t<T>;
33 const auto N = y.size();
34 arena_t<T> arena_y = y;
39 return ret_type(arena_x);
43 auto&& res_val = arena_x.val();
46 Eigen::VectorXd x_pre_softmax_adj = -res_val * arena_x.adj().
dot(res_val)
47 + res_val.cwiseProduct(arena_x.adj());
53 return ret_type(arena_x);
70template <
typename T, require_rev_col_vector_t<T>* =
nullptr>
74 const auto N = y.size();
82 return ret_type(arena_x);
86 auto&& res_val = arena_x.val();
94 Eigen::VectorXd x_pre_softmax_adj
95 = -res_val * (arena_x.adj().
dot(res_val) + res_val.size() * lp.adj())
96 + (res_val.cwiseProduct(arena_x.adj()).array() + lp.adj()).matrix();
102 return ret_type(arena_x);
void sum_to_zero_vector_backprop(T &&y_adj, const Eigen::VectorXd &z_adj)
The reverse pass backprop for the sum_to_zero_constrain on vectors.
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
plain_type_t< Vec > simplex_constrain(const Vec &y)
Return the simplex corresponding to the specified free vector.
double dot(const std::vector< double > &x, const std::vector< double > &y)
typename plain_type< std::decay_t< 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 ...