1#ifndef STAN_MATH_FWD_FUN_LOG_SUM_EXP_HPP
2#define STAN_MATH_FWD_FUN_LOG_SUM_EXP_HPP
54template <
typename T, require_container_st<is_fvar, T>* =
nullptr>
57 to_ref(x), [&](
const auto& v) {
58 using T_fvar_inner =
typename value_type_t<
decltype(v)>::Scalar;
59 using mat_type = Eigen::Matrix<T_fvar_inner, -1, -1>;
60 mat_type vals = v.val();
61 mat_type exp_vals = vals.array().exp();
65 v.d().cwiseProduct(exp_vals).sum() / exp_vals.sum());
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
static constexpr double NEGATIVE_INFTY
Negative infinity.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
fvar< T > inv_logit(const fvar< T > &x)
Returns the inverse logit function applied to the argument.
fvar< T > log_sum_exp(const fvar< T > &x1, const fvar< T > &x2)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Scalar val_
The value of this variable.
Scalar d_
The tangent (derivative) of this variable.
This template class represents scalars used in forward-mode automatic differentiation,...