Stan Math Library: stan/math/prim/scal/err/check_greater_or_equal.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

check_greater_or_equal.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_GREATER_OR_EQUAL_HPP
2 #define STAN_MATH_PRIM_SCAL_ERR_CHECK_GREATER_OR_EQUAL_HPP
3
4 #include <stan/math/prim/scal/meta/length.hpp>
5 #include <stan/math/prim/scal/meta/VectorView.hpp>
6 #include <stan/math/prim/scal/meta/is_vector_like.hpp>
7 #include <stan/math/prim/scal/err/domain_error_vec.hpp>
8 #include <stan/math/prim/scal/err/domain_error.hpp>
9 #include <string>
10
11 namespace stan {
12 namespace math {
13
14 namespace {
15 template <typename T_y,
16 typename T_low,
17 bool is_vec>
18 struct greater_or_equal {
19 static bool check(const char* function,
20 const char* name,
21 const T_y& y,
22 const T_low& low) {
23 using stan::length;
24 VectorView<const T_low> low_vec(low);
25 for (size_t n = 0; n < length(low); n++) {
26 if (!(y >= low_vec[n])) {
27 std::stringstream msg;
28 msg << ", but must be greater than or equal to ";
29 msg << low_vec[n];
30 std::string msg_str(msg.str());
31 domain_error(function, name, y,
32 "is ", msg_str.c_str());
33 }
34 }
35 return true;
36 }
37 };
38
39 template <typename T_y,
40 typename T_low>
41 struct greater_or_equal<T_y, T_low, true> {
42 static bool check(const char* function,
43 const char* name,
44 const T_y& y,
45 const T_low& low) {
46 using stan::length;
47 using stan::get;
48 VectorView<const T_low> low_vec(low);
49 for (size_t n = 0; n < length(y); n++) {
50 if (!(get(y, n) >= low_vec[n])) {
51 std::stringstream msg;
52 msg << ", but must be greater than or equal to ";
53 msg << low_vec[n];
54 std::string msg_str(msg.str());
55 domain_error_vec(function, name, y, n,
56 "is ", msg_str.c_str());
57 }
58 }
59 return true;
60 }
61 };
62 }
63
83 template <typename T_y, typename T_low>
84 inline bool check_greater_or_equal(const char* function,
85 const char* name,
86 const T_y& y,
87 const T_low& low) {
88 return greater_or_equal<T_y, T_low, is_vector_like<T_y>::value>
89 ::check(function, name, y, low);
90 }
91 }
92 }
93 #endif
stan::math::check_greater_or_equal
bool check_greater_or_equal(const char *function, const char *name, const T_y &y, const T_low &low)
Return true if y is greater or equal than low.
Definition: check_greater_or_equal.hpp:84
stan
Definition: log_sum_exp.hpp:8
stan::length
size_t length(const std::vector< T > &x)
Definition: length.hpp:10
domain_error_vec.hpp
is_vector_like.hpp
VectorView.hpp
stan::math::domain_error_vec
void domain_error_vec(const char *function, const char *name, const T &y, const size_t i, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
Definition: domain_error_vec.hpp:38
stan::get
T get(const std::vector< T > &x, size_t n)
Definition: get.hpp:10
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
length.hpp
domain_error.hpp

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