Automatic Differentiation
 
Loading...
Searching...
No Matches
corr_constrain.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_CONSTRAINT_CORR_CONSTRAIN_HPP
2#define STAN_MATH_PRIM_CONSTRAINT_CORR_CONSTRAIN_HPP
3
9#include <utility>
10
11namespace stan {
12namespace math {
13
26template <typename T>
28 return tanh(std::forward<T>(x));
29}
30
46template <typename T_x, typename T_lp>
47inline auto corr_constrain(T_x&& x, T_lp& lp) {
48 decltype(auto) x_ref = to_ref(std::forward<T_x>(x));
49 lp -= 2.0 * sum(log_cosh(x_ref));
50 return corr_constrain(x_ref);
51}
52
68template <bool Jacobian, typename T_x, typename T_lp>
69inline auto corr_constrain(T_x&& x, T_lp& lp) {
70 if constexpr (Jacobian) {
71 return corr_constrain(std::forward<T_x>(x), lp);
72 } else {
73 return corr_constrain(std::forward<T_x>(x));
74 }
75}
76
77} // namespace math
78} // namespace stan
79#endif
plain_type_t< T > corr_constrain(T &&x)
Return the result of transforming the specified scalar or container of values to have a valid correla...
fvar< T > tanh(const fvar< T > &x)
Return the hyperbolic tangent of the argument.
Definition tanh.hpp:27
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
Definition sum.hpp:23
fvar< T > log_cosh(const fvar< T > &x)
Return the natural logarithm of the hyperbolic cosine of the argument.
Definition log_cosh.hpp:21
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:18
typename plain_type< std::decay_t< T > >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...