Stan Math Library  2.20.0
reverse mode automatic differentiation
lb_constrain.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_LB_CONSTRAIN_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_LB_CONSTRAIN_HPP
3 
5 #include <boost/math/tools/promotion.hpp>
8 #include <cmath>
9 
10 namespace stan {
11 namespace math {
12 
32 template <typename T, typename L>
33 inline typename boost::math::tools::promote_args<T, L>::type lb_constrain(
34  const T& x, const L& lb) {
35  using std::exp;
36  if (lb == NEGATIVE_INFTY)
37  return identity_constrain(x);
38  return exp(x) + lb;
39 }
40 
57 template <typename T, typename L>
58 inline typename boost::math::tools::promote_args<T, L>::type lb_constrain(
59  const T& x, const L& lb, T& lp) {
60  using std::exp;
61  if (lb == NEGATIVE_INFTY)
62  return identity_constrain(x, lp);
63  lp += x;
64  return exp(x) + lb;
65 }
66 
67 } // namespace math
68 
69 } // namespace stan
70 
71 #endif
T identity_constrain(const T &x)
Returns the result of applying the identity constraint transform to the input.
boost::math::tools::promote_args< T, L >::type lb_constrain(const T &x, const L &lb)
Return the lower-bounded value for the specified unconstrained input and specified lower bound...
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:11
const double NEGATIVE_INFTY
Negative infinity.
Definition: constants.hpp:53

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