1#ifndef STAN_MATH_REV_FUN_LOG_SOFTMAX_HPP
2#define STAN_MATH_REV_FUN_LOG_SOFTMAX_HPP
24template <
typename T, require_rev_matrix_t<T>* =
nullptr>
27 auto x_arena =
to_arena(std::forward<T>(x));
32 const auto& res_adj =
to_ref(res.adj());
34 += res_adj.array() - res_adj.sum() * res.val().array().exp();
47template <
typename T, require_std_vector_st<is_var, T>* =
nullptr>
49 return apply_vector_unary<T>::apply(std::forward<T>(x), [](
auto&& v) {
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...
auto log_softmax(T &&x)
Return the log softmax of each vector in a container of fvar values.
void check_nonzero_size(const char *function, const char *name, const T_y &y)
Check if the specified matrix/vector is of non-zero size.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
typename plain_type< std::decay_t< T > >::type plain_type_t
std::conditional_t< is_any_var_matrix< ReturnType, Types... >::value, stan::math::var_value< stan::math::promote_scalar_t< double, plain_type_t< ReturnType > > >, stan::math::promote_scalar_t< stan::math::var_value< double >, plain_type_t< ReturnType > > > return_var_matrix_t
Given an Eigen type and several inputs, determine if a matrix should be var<Matrix> or Matrix<var>.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...