Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
check_ordered.hpp
Go to the documentation of this file.
1 #ifndef __STAN__MATH__ERROR_HANDLING__MATRIX__CHECK_ORDERED_HPP__
2 #define __STAN__MATH__ERROR_HANDLING__MATRIX__CHECK_ORDERED_HPP__
3 
4 #include <sstream>
8 
9 namespace stan {
10  namespace math {
11 
26  template <typename T_y, typename T_result, class Policy>
27  bool check_ordered(const char* function,
28  const Eigen::Matrix<T_y,Eigen::Dynamic,1>& y,
29  const char* name,
30  T_result* result,
31  const Policy&) {
33  typedef typename Eigen::Matrix<T_y,Eigen::Dynamic,1>::size_type size_t;
34  if (y.size() == 0) {
35  return true;
36  }
37  for (size_t n = 1; n < y.size(); n++) {
38  if (!(y[n] > y[n-1])) {
39  std::ostringstream stream;
40  stream << name << " is not a valid ordered vector."
41  << " The element at " << n
42  << " is %1%, but should be greater than the previous element, "
43  << y[n-1];
44  T_result tmp = raise_domain_error<T_result,T_y>(function,
45  stream.str().c_str(),
46  y[n],
47  Policy());
48  if (result != 0)
49  *result = tmp;
50  return false;
51  }
52  }
53  return true;
54  }
55  template <typename T_y, typename T_result>
56  bool check_ordered(const char* function,
57  const Eigen::Matrix<T_y,Eigen::Dynamic,1>& y,
58  const char* name,
59  T_result* result) {
60  return check_ordered(function,y,name,result,default_policy());
61  }
62  template <typename T>
63  bool check_ordered(const char* function,
64  const Eigen::Matrix<T,Eigen::Dynamic,1>& y,
65  const char* name,
66  T* result = 0) {
67  return check_ordered(function,y,name,result,default_policy());
68  }
69 
70  }
71 }
72 #endif

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