1#ifndef STAN_MATH_PRIM_FUN_SOFTMAX_HPP
2#define STAN_MATH_PRIM_FUN_SOFTMAX_HPP
47template <
typename Container, require_st_arithmetic<Container>* =
nullptr,
48 require_container_t<Container>* =
nullptr,
49 require_not_t<
bool_constant<
50 is_eigen<std::decay_t<Container>>::value
51 && !is_eigen_vector<std::decay_t<Container>>::value>>* =
nullptr>
56 std::forward<
decltype(a)>(a),
61 const auto theta = (v.array() - v.maxCoeff()).exp();
62 return (theta / theta.sum()).matrix();
65 to_ref(std::forward<Container>(x)));
auto softmax(T &&x)
Return the softmax of each vector in a container of fvar values.
auto make_holder(F &&func, Args &&... args)
Calls given function with given arguments.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
constexpr decltype(auto) apply(F &&f, Tuple &&t, PreArgs &&... pre_args)
typename plain_type< std::decay_t< T > >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...