Stan Math Library  2.20.0
reverse mode automatic differentiation
offset_multiplier_constrain.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_OFFSET_MULTIPLIER_CONSTRAIN_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_OFFSET_MULTIPLIER_CONSTRAIN_HPP
3 
4 #include <boost/math/tools/promotion.hpp>
11 #include <cmath>
12 #include <limits>
13 
14 namespace stan {
15 namespace math {
16 
40 template <typename T, typename M, typename S>
41 inline typename boost::math::tools::promote_args<T, M, S>::type
42 offset_multiplier_constrain(const T& x, const M& mu, const S& sigma) {
43  check_finite("offset_multiplier_constrain", "offset", mu);
44  if (sigma == 1) {
45  if (mu == 0)
46  return identity_constrain(x);
47  return mu + x;
48  }
49  check_positive_finite("offset_multiplier_constrain", "multiplier", sigma);
50  return fma(sigma, x, mu);
51 }
52 
79 template <typename T, typename M, typename S>
80 inline typename boost::math::tools::promote_args<T, M, S>::type
81 offset_multiplier_constrain(const T& x, const M& mu, const S& sigma, T& lp) {
82  using std::log;
83  check_finite("offset_multiplier_constrain", "offset", mu);
84  if (sigma == 1) {
85  if (mu == 0)
86  return identity_constrain(x);
87  return mu + x;
88  }
89  check_positive_finite("offset_multiplier_constrain", "multiplier", sigma);
90  lp += multiply_log(size_of(x), sigma);
91  return fma(sigma, x, mu);
92 }
93 
94 } // namespace math
95 
96 } // namespace stan
97 
98 #endif
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
boost::math::tools::promote_args< T, M, S >::type offset_multiplier_constrain(const T &x, const M &mu, const S &sigma)
Return the linearly transformed value for the specified unconstrained input and specified offset and ...
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:12
T identity_constrain(const T &x)
Returns the result of applying the identity constraint transform to the input.
void check_positive_finite(const char *function, const char *name, const T_y &y)
Check if y is positive and finite.
fvar< typename stan::return_type< T1, T2, T3 >::type > fma(const fvar< T1 > &x1, const fvar< T2 > &x2, const fvar< T3 > &x3)
The fused multiply-add operation (C99).
Definition: fma.hpp:59
size_t size_of(const T &x)
Returns the size of the provided vector or the constant 1 if the input argument is not a vector...
Definition: size_of.hpp:27
fvar< T > multiply_log(const fvar< T > &x1, const fvar< T > &x2)

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