Stan Math Library  2.20.0
reverse mode automatic differentiation
check_ordered.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_ARR_ERR_CHECK_ORDERED_HPP
2 #define STAN_MATH_PRIM_ARR_ERR_CHECK_ORDERED_HPP
3 
6 #include <sstream>
7 #include <vector>
8 #include <string>
9 
10 namespace stan {
11 namespace math {
12 
23 template <typename T_y>
24 void check_ordered(const char* function, const char* name,
25  const std::vector<T_y>& y) {
26  for (size_t n = 1; n < y.size(); n++) {
27  if (!(y[n] > y[n - 1])) {
28  std::ostringstream msg1;
29  msg1 << "is not a valid ordered vector."
30  << " The element at " << stan::error_index::value + n << " is ";
31  std::string msg1_str(msg1.str());
32  std::ostringstream msg2;
33  msg2 << ", but should be greater than the previous element, " << y[n - 1];
34  std::string msg2_str(msg2.str());
35  domain_error(function, name, y[n], msg1_str.c_str(), msg2_str.c_str());
36  }
37  }
38 }
39 } // namespace math
40 } // namespace stan
41 #endif
void check_ordered(const char *function, const char *name, const std::vector< T_y > &y)
Check if the specified vector is sorted into strictly increasing order.
void 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.

     [ Stan Home Page ] © 2011–2018, Stan Development Team.