Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
check_positive_ordered.hpp
Go to the documentation of this file.
1 #ifndef __STAN__MATH__ERROR_HANDLING__MATRIX__CHECK_POSITIVE_ORDERED_HPP__
2 #define __STAN__MATH__ERROR_HANDLING__MATRIX__CHECK_POSITIVE_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_positive_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  if (y[0] < 0) {
38  std::ostringstream stream;
39  stream << name << " is not a valid positive_ordered vector."
40  << " The element at 0 is %1%, but should be postive.";
41  T_result tmp = raise_domain_error<T_result,T_y>(function,
42  stream.str().c_str(),
43  y[0],
44  Policy());
45  if (result != 0)
46  *result = tmp;
47  return false;
48  }
49  for (size_t n = 1; n < y.size(); n++) {
50  if (!(y[n] > y[n-1])) {
51  std::ostringstream stream;
52  stream << name << " is not a valid ordered vector."
53  << " The element at " << n
54  << " is %1%, but should be greater than the previous element, "
55  << y[n-1];
56  T_result tmp = raise_domain_error<T_result,T_y>(function,
57  stream.str().c_str(),
58  y[n],
59  Policy());
60  if (result != 0)
61  *result = tmp;
62  return false;
63  }
64  }
65  return true;
66  }
67  template <typename T_y, typename T_result>
68  bool check_positive_ordered(const char* function,
69  const Eigen::Matrix<T_y,Eigen::Dynamic,1>& y,
70  const char* name,
71  T_result* result) {
72  return check_positive_ordered(function,y,name,result,default_policy());
73  }
74  template <typename T>
75  bool check_positive_ordered(const char* function,
76  const Eigen::Matrix<T,Eigen::Dynamic,1>& y,
77  const char* name,
78  T* result = 0) {
79  return check_positive_ordered(function,y,name,result,default_policy());
80  }
81 
82  }
83 }
84 #endif

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