Stan Math Library  2.15.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 
4 #include <boost/math/tools/promotion.hpp>
6 #include <cmath>
7 #include <limits>
8 
9 namespace stan {
10  namespace math {
11 
31  template <typename T, typename TL>
32  inline
33  T lb_constrain(const T x, const TL lb) {
34  using std::exp;
35  if (lb == -std::numeric_limits<double>::infinity())
36  return identity_constrain(x);
37  return exp(x) + lb;
38  }
39 
56  template <typename T, typename TL>
57  inline
58  typename boost::math::tools::promote_args<T, TL>::type
59  lb_constrain(const T x, const TL lb, T& lp) {
60  using std::exp;
61  if (lb == -std::numeric_limits<double>::infinity())
62  return identity_constrain(x, lp);
63  lp += x;
64  return exp(x) + lb;
65  }
66 
67  }
68 
69 }
70 
71 #endif
T lb_constrain(const T x, const TL 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:10
T identity_constrain(T x)
Returns the result of applying the identity constraint transform to the input.

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