1#ifndef STAN_MATH_PRIM_ERR_CHECK_SORTED_HPP
2#define STAN_MATH_PRIM_ERR_CHECK_SORTED_HPP
25template <
typename EigVec, require_eigen_vector_t<EigVec>* =
nullptr>
26void check_sorted(
const char* function,
const char* name,
const EigVec& y) {
27 const auto& y_ref =
to_ref(y);
28 for (Eigen::Index n = 1; n < y_ref.size(); n++) {
29 if (!(y_ref[n] >= y_ref[n - 1])) {
30 std::ostringstream msg1;
31 msg1 <<
"is not a valid sorted vector."
33 std::string msg1_str(msg1.str());
34 std::ostringstream msg2;
35 msg2 <<
", but should be greater than or equal to the previous element, "
37 std::string msg2_str(msg2.str());
55template <
typename T_y>
57 const std::vector<T_y>& y) {
58 for (
size_t n = 1; n < y.size(); n++) {
59 if (!(y[n] >= y[n - 1])) {
60 std::ostringstream msg1;
61 msg1 <<
"is not a valid sorted vector."
63 std::string msg1_str(msg1.str());
64 std::ostringstream msg2;
65 msg2 <<
", but should be greater than or equal to the previous element, "
67 std::string msg2_str(msg2.str());
void throw_domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
void check_sorted(const char *function, const char *name, const EigVec &y)
Check if the specified vector is sorted into increasing order (repeated values are okay).
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...