check_positive_ordered.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_POSITIVE_ORDERED_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_CHECK_POSITIVE_ORDERED_HPP
3 
8 #include <sstream>
9 #include <string>
10 
11 namespace stan {
12 namespace math {
13 
14 /**
15  * Check if the specified vector contains
16  * non-negative values and is sorted into strictly increasing
17  * order.
18  *
19  * @param function Function name (for error messages)
20  * @param name Variable name (for error messages)
21  * @param y Vector to test
22  *
23  * @throw <code>std::domain_error</code> if the vector contains non-positive
24  * values, if the values are not ordered, if there are duplicated
25  * values, or if any element is <code>NaN</code>.
26  */
27 template <typename T_y>
28 void check_positive_ordered(const char* function, const char* name,
29  const Eigen::Matrix<T_y, Eigen::Dynamic, 1>& y) {
30  using Eigen::Dynamic;
31  using Eigen::Matrix;
32 
33  if (y.size() == 0)
34  return;
35 
36  if (y[0] < 0) {
37  std::ostringstream msg;
38  msg << "is not a valid positive_ordered vector."
39  << " The element at " << stan::error_index::value << " is ";
40  std::string msg_str(msg.str());
41  domain_error(function, name, y[0], msg_str.c_str(),
42  ", but should be postive.");
43  }
44  check_ordered(function, name, y);
45 }
46 } // namespace math
47 } // namespace stan
48 #endif
const XML_Char * name
Definition: expat.h:151
void check_ordered(const char *function, const char *name, const std::vector< T_y > &y)
void check_positive_ordered(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, 1 > &y)
void domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
enum BeamMode string