Stan Math Library  2.20.0
reverse mode automatic differentiation
ub_constrain.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_UB_CONSTRAIN_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_UB_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 U>
33 inline typename boost::math::tools::promote_args<T, U>::type ub_constrain(
34  const T& x, const U& ub) {
35  using std::exp;
36  if (ub == INFTY)
37  return identity_constrain(x);
38  return ub - exp(x);
39 }
40 
64 template <typename T, typename U>
65 inline typename boost::math::tools::promote_args<T, U>::type ub_constrain(
66  const T& x, const U& ub, T& lp) {
67  using std::exp;
68  if (ub == INFTY)
69  return identity_constrain(x, lp);
70  lp += x;
71  return ub - exp(x);
72 }
73 
74 } // namespace math
75 
76 } // namespace stan
77 
78 #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, U >::type ub_constrain(const T &x, const U &ub)
Return the upper-bounded value for the specified unconstrained scalar and upper bound.
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:11
const double INFTY
Positive infinity.
Definition: constants.hpp:48

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