Stan Math Library  2.11.0
reverse mode automatic differentiation
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 
9 #include <sstream>
10 #include <string>
11 
12 namespace stan {
13 
14  namespace math {
15 
30  template <typename T_y>
31  bool
32  check_positive_ordered(const char* function,
33  const char* name,
34  const Eigen::Matrix<T_y, Eigen::Dynamic, 1>& y) {
35  using Eigen::Dynamic;
36  using Eigen::Matrix;
38 
39  typedef typename index_type<Matrix<T_y, Dynamic, 1> >::type size_type;
40  if (y.size() == 0) {
41  return true;
42  }
43  if (y[0] < 0) {
44  std::ostringstream msg;
45  msg << "is not a valid positive_ordered vector."
46  << " The element at " << stan::error_index::value
47  << " is ";
48  std::string msg_str(msg.str());
49  domain_error(function, name, y[0],
50  msg_str.c_str(), ", but should be postive.");
51  return false;
52  }
53  check_ordered(function, name, y);
54  return true;
55  }
56  }
57 }
58 #endif
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Type for sizes and indexes in an Eigen matrix with double e.
Definition: typedefs.hpp:13
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:19
bool check_ordered(const char *function, const char *name, const std::vector< T_y > &y)
Return true if the specified vector is sorted into strictly increasing order.
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.
bool check_positive_ordered(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, 1 > &y)
Return true if the specified vector contains non-negative values and is sorted into strictly increasi...

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