| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
check_ordered.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_ORDERED_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_CHECK_ORDERED_HPP
3
4 #include <stan/math/prim/scal/err/domain_error.hpp>
5 #include <stan/math/prim/mat/fun/Eigen.hpp>
6 #include <stan/math/prim/mat/meta/index_type.hpp>
7 #include <stan/math/prim/scal/meta/error_index.hpp>
8 #include <sstream>
9 #include <string>
10 #include <vector>
11
12 namespace stan {
13 namespace math {
14
30 template <typename T_y>
31 bool check_ordered(const char* function,
32 const char* name,
33 const Eigen::Matrix<T_y, Eigen::Dynamic, 1>& y) {
34 using Eigen::Dynamic;
35 using Eigen::Matrix;
36 using stan::math::index_type;
37
38 typedef typename index_type<Matrix<T_y, Dynamic, 1> >::type size_t;
39
40 if (y.size() == 0)
41 return true;
42
43 for (size_t n = 1; n < y.size(); n++) {
44 if (!(y[n] > y[n-1])) {
45 std::ostringstream msg1;
46 msg1 << "is not a valid ordered vector."
47 << " The element at " << stan::error_index::value + n
48 << " is ";
49 std::string msg1_str(msg1.str());
50 std::ostringstream msg2;
51 msg2 << ", but should be greater than the previous element, "
52 << y[n-1];
53 std::string msg2_str(msg2.str());
54 domain_error(function, name, y[n],
55 msg1_str.c_str(), msg2_str.c_str());
56 return false;
57 }
58 }
59 return true;
60 }
61
77 template <typename T_y>
78 bool check_ordered(const char* function,
79 const char* name,
80 const std::vector<T_y>& y) {
81 if (y.size() == 0)
82 return true;
83
84 for (size_t n = 1; n < y.size(); n++) {
85 if (!(y[n] > y[n-1])) {
86 std::ostringstream msg1;
87 msg1 << "is not a valid ordered vector."
88 << " The element at " << stan::error_index::value + n
89 << " is ";
90 std::string msg1_str(msg1.str());
91 std::ostringstream msg2;
92 msg2 << ", but should be greater than the previous element, "
93 << y[n-1];
94 std::string msg2_str(msg2.str());
95 domain_error(function, name, y[n],
96 msg1_str.c_str(), msg2_str.c_str());
97 return false;
98 }
99 }
100 return true;
101 }
102 }
103 }
104 #endif
stan::math::index_type
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:19
index_type.hpp
stan::math::check_ordered
bool check_ordered(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, 1 > &y)
Return true if the specified vector is sorted into strictly increasing order.
Definition: check_ordered.hpp:31
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:32
Eigen.hpp
domain_error.hpp
error_index.hpp

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