Automatic Differentiation
 
Loading...
Searching...
No Matches
positive_constrain.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_POSITIVE_CONSTRAIN_HPP
2#define STAN_MATH_PRIM_FUN_POSITIVE_CONSTRAIN_HPP
3
7#include <cmath>
8
9namespace stan {
10namespace math {
11
22template <typename T>
23inline auto positive_constrain(const T& x) {
24 return exp(x);
25}
26
43template <typename T, typename S>
44inline auto positive_constrain(const T& x, S& lp) {
45 lp += sum(x);
46 return exp(x);
47}
48
64template <bool Jacobian, typename T, require_not_std_vector_t<T>* = nullptr>
65inline auto positive_constrain(const T& x, return_type_t<T>& lp) {
66 if (Jacobian) {
67 return positive_constrain(x, lp);
68 } else {
69 return positive_constrain(x);
70 }
71}
72
89template <bool Jacobian, typename T, require_std_vector_t<T>* = nullptr>
90inline auto positive_constrain(const T& x, return_type_t<T>& lp) {
91 return apply_vector_unary<T>::apply(
92 x, [&lp](auto&& v) { return positive_constrain<Jacobian>(v, lp); });
93}
94
95} // namespace math
96} // namespace stan
97
98#endif
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
fvar< T > sum(const std::vector< fvar< T > > &m)
Return the sum of the entries of the specified standard vector.
Definition sum.hpp:22
auto positive_constrain(const T &x)
Return the positive value for the specified unconstrained input.
fvar< T > exp(const fvar< T > &x)
Definition exp.hpp:13
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9