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

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