Stan Math Library  2.6.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
log_sum_exp.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_LOG_SUM_EXP_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_LOG_SUM_EXP_HPP
3 
5 #include <boost/math/tools/promotion.hpp>
6 #include <limits>
7 
8 namespace stan {
9  namespace math {
10 
46  template <typename T1, typename T2>
47  inline typename boost::math::tools::promote_args<T1, T2>::type
48  log_sum_exp(const T2& a, const T1& b) {
49  using std::exp;
50  if (a > b)
51  return a + log1p_exp(b - a);
52  return b + log1p_exp(a - b);
53  }
54 
55  }
56 }
57 
58 #endif
fvar< T > log_sum_exp(const std::vector< fvar< T > > &v)
Definition: log_sum_exp.hpp:14
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
fvar< T > log1p_exp(const fvar< T > &x)
Definition: log1p_exp.hpp:13

     [ Stan Home Page ] © 2011–2015, Stan Development Team.