Automatic Differentiation
 
Loading...
Searching...
No Matches
positive_ordered_free.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_CONSTRAINT_POSITIVE_ORDERED_FREE_HPP
2#define STAN_MATH_PRIM_CONSTRAINT_POSITIVE_ORDERED_FREE_HPP
3
9#include <cmath>
10
11namespace stan {
12namespace math {
13
27template <typename EigVec, require_eigen_col_vector_t<EigVec>* = nullptr>
28auto positive_ordered_free(const EigVec& y) {
29 using std::log;
30 const auto& y_ref = to_ref(y);
31 check_positive_ordered("stan::math::positive_ordered_free",
32 "Positive ordered variable", y_ref);
33 Eigen::Index k = y_ref.size();
35 if (k == 0) {
36 return x;
37 }
38 x.coeffRef(0) = log(y_ref.coeff(0));
39 x.tail(k - 1)
40 = (y_ref.tail(k - 1) - y_ref.head(k - 1)).array().log().matrix();
41 return x;
42}
43
51template <typename T, require_std_vector_t<T>* = nullptr>
52auto positive_ordered_free(const T& x) {
54 x, [](auto&& v) { return positive_ordered_free(v); });
55}
56
57} // namespace math
58} // namespace stan
59
60#endif
void check_positive_ordered(const char *function, const char *name, const Vec &y)
Throw an exception if the specified the vector contains negative values or is not sorted into strictl...
fvar< T > log(const fvar< T > &x)
Definition log.hpp:15
auto positive_ordered_free(const EigVec &y)
Return the vector of unconstrained scalars that transform to the specified positive ordered vector.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...