Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations 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 #include <stan/meta/traits.hpp>
9 
10 namespace stan {
11 
12  namespace math {
13 
28  template <typename T_y, typename T_result>
29  bool check_positive_ordered(const char* function,
30  const Eigen::Matrix<T_y,Eigen::Dynamic,1>& y,
31  const char* name,
32  T_result* result) {
33  using Eigen::Dynamic;
34  using Eigen::Matrix;
35  typedef typename index_type<Matrix<T_y,Dynamic,1> >::type size_type;
36  if (y.size() == 0) {
37  return true;
38  }
39  if (y[0] < 0) {
40  std::ostringstream stream;
41  stream << " is not a valid positive_ordered vector."
42  << " The element at " << stan::error_index::value
43  << " is %1%, but should be postive.";
44  std::string msg(stream.str());
45  return dom_err(function,y[0],name,
46  msg.c_str(),"",
47  result);
48  }
49  for (size_type n = 1; n < y.size(); n++) {
50  if (!(y[n] > y[n-1])) {
51  std::ostringstream stream;
52  stream << " is not a valid ordered vector."
53  << " The element at " << stan::error_index::value + n
54  << " is %1%, but should be greater than the previous element, "
55  << y[n-1];
56  std::string msg(stream.str());
57  return dom_err(function,y[n],name,
58  msg.c_str(),"",
59  result);
60  }
61  }
62  return true;
63  }
64 
65  }
66 }
67 #endif
bool dom_err(const char *function, const T &y, const char *name, const char *error_msg, const T_msg error_msg2, T_result *result)
Definition: dom_err.hpp:36
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:21
index_type< Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > >::type size_type
Type for sizes and indexes in an Eigen matrix with double e.
Definition: typedefs.hpp:16
bool check_positive_ordered(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, 1 > &y, const char *name, T_result *result)
Return true if the specified vector contains only non-negative values and is sorted into increasing o...

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