| 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_less.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_LESS_HPP
2 #define STAN_MATH_PRIM_SCAL_ERR_CHECK_LESS_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/length.hpp>
8 #include <stan/math/prim/scal/meta/VectorView.hpp>
9 #include <functional>
10 #include <string>
11
12 namespace stan {
13 namespace math {
14
15 namespace {
16 template <typename T_y, typename T_high, bool is_vec>
17 struct less {
18 static bool check(const char* function,
19 const char* name,
20 const T_y& y,
21 const T_high& high) {
22 using stan::length;
23 VectorView<const T_high> high_vec(high);
24 for (size_t n = 0; n < length(high); n++) {
25 if (!(y < high_vec[n])) {
26 std::stringstream msg;
27 msg << ", but must be less than ";
28 msg << high_vec[n];
29 std::string msg_str(msg.str());
30 domain_error(function, name, y,
31 "is ", msg_str.c_str());
32 }
33 }
34 return true;
35 }
36 };
37
38 template <typename T_y, typename T_high>
39 struct less<T_y, T_high, true> {
40 static bool check(const char* function,
41 const char* name,
42 const T_y& y,
43 const T_high& high) {
44 using stan::length;
45 VectorView<const T_high> high_vec(high);
46 for (size_t n = 0; n < length(y); n++) {
47 if (!(stan::get(y, n) < high_vec[n])) {
48 std::stringstream msg;
49 msg << ", but must be less than ";
50 msg << high_vec[n];
51 std::string msg_str(msg.str());
52 domain_error_vec(function, name, y, n,
53 "is ", msg_str.c_str());
54 }
55 }
56 return true;
57 }
58 };
59 }
60
80 template <typename T_y, typename T_high>
81 inline bool check_less(const char* function,
82 const char* name,
83 const T_y& y,
84 const T_high& high) {
85 return less<T_y, T_high, is_vector_like<T_y>::value>
86 ::check(function, name, y, high);
87 }
88 }
89 }
90 #endif
stan::math::check_less
bool check_less(const char *function, const char *name, const T_y &y, const T_high &high)
Return true if y is strictly less than high.
Definition: check_less.hpp:81
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 Home Page ] © 2011–2015, Stan Development Team.