| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

check_ordered.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_ARR_ERR_CHECK_ORDERED_HPP
2 #define STAN_MATH_PRIM_ARR_ERR_CHECK_ORDERED_HPP
3
4 #include <stan/math/prim/arr/meta/index_type.hpp>
5 #include <stan/math/prim/scal/err/domain_error.hpp>
6 #include <stan/math/prim/scal/meta/error_index.hpp>
7 #include <sstream>
8 #include <string>
9 #include <vector>
10
11 namespace stan {
12 namespace math {
13
29 template <typename T_y>
30 bool check_ordered(const char* function,
31 const char* name,
32 const std::vector<T_y>& y) {
33 if (y.size() == 0)
34 return true;
35
36 for (size_t n = 1; n < y.size(); n++) {
37 if (!(y[n] > y[n-1])) {
38 std::ostringstream msg1;
39 msg1 << "is not a valid ordered vector."
40 << " The element at " << stan::error_index::value + n
41 << " is ";
42 std::string msg1_str(msg1.str());
43 std::ostringstream msg2;
44 msg2 << ", but should be greater than the previous element, "
45 << y[n-1];
46 std::string msg2_str(msg2.str());
47 domain_error(function, name, y[n],
48 msg1_str.c_str(), msg2_str.c_str());
49 return false;
50 }
51 }
52 return true;
53 }
54 }
55 }
56 #endif
stan
Definition: log_sum_exp.hpp:8
index_type.hpp
stan::math::check_ordered
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.
Definition: check_ordered.hpp:30
stan::error_index::value
Definition: error_index.hpp:7
stan::math::domain_error
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.
Definition: domain_error.hpp:30
domain_error.hpp
error_index.hpp

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