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