1 #ifndef STAN_MATH_REV_MAT_FUN_SOFTMAX_HPP 2 #define STAN_MATH_REV_MAT_FUN_SOFTMAX_HPP 28 template <std::
size_t size>
29 Eigen::VectorXd
operator()(
const std::array<bool, size>& needs_adj,
30 const Eigen::VectorXd& alpha) {
35 for (
int n = 0; n < N_; ++n)
49 template <std::
size_t size>
51 const std::array<bool, size>& needs_adj,
52 const Eigen::VectorXd& adj)
const {
53 Eigen::VectorXd adj_times_jac(N_);
54 Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, 1> > y(y_, N_);
56 double adj_dot_y = adj.dot(y);
57 for (
int n = 0; n < N_; ++n) {
58 adj_times_jac(n) = -y(n) * adj_dot_y + y(n) * adj(n);
61 return std::make_tuple(adj_times_jac);
74 inline Eigen::Matrix<var, Eigen::Dynamic, 1>
softmax(
75 const Eigen::Matrix<var, Eigen::Dynamic, 1>& alpha) {
78 return adj_jac_apply<internal::softmax_op>(alpha);
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.
Eigen::Matrix< fvar< T >, Eigen::Dynamic, 1 > softmax(const Eigen::Matrix< fvar< T >, Eigen::Dynamic, 1 > &alpha)
Eigen::VectorXd operator()(const std::array< bool, size > &needs_adj, const Eigen::VectorXd &alpha)
static STAN_THREADS_DEF AutodiffStackStorage * instance_
std::tuple< Eigen::VectorXd > multiply_adjoint_jacobian(const std::array< bool, size > &needs_adj, const Eigen::VectorXd &adj) const
T * alloc_array(size_t n)
Allocate an array on the arena of the specified size to hold values of the specified template paramet...