Loading [MathJax]/extensions/TeX/AMSsymbols.js
Automatic Differentiation
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
positive_constrain.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_CONSTRAINT_POSITIVE_CONSTRAIN_HPP
2#define STAN_MATH_PRIM_CONSTRAINT_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
66template <bool Jacobian, typename T, typename Lp,
69inline auto positive_constrain(const T& x, Lp& lp) {
70 if constexpr (Jacobian) {
71 return positive_constrain(x, lp);
72 } else {
73 return positive_constrain(x);
74 }
75}
76
95template <bool Jacobian, typename T, typename Lp,
96 require_std_vector_t<T>* = nullptr,
98inline auto positive_constrain(const T& x, Lp& lp) {
99 return apply_vector_unary<T>::apply(
100 x, [&lp](auto&& v) { return positive_constrain<Jacobian>(v, lp); });
101}
102
103} // namespace math
104} // namespace stan
105
106#endif
require_t< std::is_convertible< std::decay_t< T >, std::decay_t< S > > > require_convertible_t
Require types T and S satisfies std::is_convertible.
require_not_t< is_std_vector< std::decay_t< T > > > require_not_std_vector_t
Require type does not satisfy is_std_vector.
require_t< is_std_vector< std::decay_t< T > > > require_std_vector_t
Require type satisfies is_std_vector.
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
Definition sum.hpp:23
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:15
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...