Stan Math Library  2.14.0
reverse mode automatic differentiation
check_ordered.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_ORDERED_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_CHECK_ORDERED_HPP
3 
8 #include <sstream>
9 #include <string>
10 #include <vector>
11 
12 namespace stan {
13  namespace math {
14 
29  template <typename T_y>
30  void check_ordered(const char* function,
31  const char* name,
32  const Eigen::Matrix<T_y, Eigen::Dynamic, 1>& y) {
33  using Eigen::Dynamic;
34  using Eigen::Matrix;
35 
36  typedef typename index_type<Matrix<T_y, Dynamic, 1> >::type size_t;
37 
38  for (size_t n = 1; n < y.size(); n++) {
39  if (!(y[n] > y[n-1])) {
40  std::ostringstream msg1;
41  msg1 << "is not a valid ordered vector."
42  << " The element at " << stan::error_index::value + n
43  << " is ";
44  std::string msg1_str(msg1.str());
45  std::ostringstream msg2;
46  msg2 << ", but should be greater than the previous element, "
47  << y[n-1];
48  std::string msg2_str(msg2.str());
49  domain_error(function, name, y[n],
50  msg1_str.c_str(), msg2_str.c_str());
51  }
52  }
53  }
54 
55  }
56 }
57 #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.
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:18
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–2016, Stan Development Team.