| 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_positive.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_POSITIVE_HPP
2 #define STAN_MATH_PRIM_SCAL_ERR_CHECK_POSITIVE_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/value_type.hpp>
7 #include <stan/math/prim/scal/meta/length.hpp>
8 #include <stan/math/prim/scal/meta/get.hpp>
9 #include <stan/math/prim/scal/meta/is_vector_like.hpp>
10 #include <boost/type_traits/is_unsigned.hpp>
11
12 namespace stan {
13
14 namespace math {
15
16 namespace {
17
18 template <typename T_y, bool is_vec>
19 struct positive {
20 static bool check(const char* function,
21 const char* name,
22 const T_y& y) {
23 // have to use not is_unsigned. is_signed will be false
24 // floating point types that have no unsigned versions.
25 if (!boost::is_unsigned<T_y>::value && !(y > 0))
26 domain_error(function, name, y,
27 "is ", ", but must be > 0!");
28 return true;
29 }
30 };
31
32 template <typename T_y>
33 struct positive<T_y, true> {
34 static bool check(const char* function,
35 const char* name,
36 const T_y& y) {
37 using stan::math::value_type;
38 using stan::length;
39 for (size_t n = 0; n < length(y); n++) {
40 if (!boost::is_unsigned<typename value_type<T_y>::type>::value
41 && !(stan::get(y, n) > 0))
42 domain_error_vec(function, name, y, n,
43 "is ", ", but must be > 0!");
44 }
45 return true;
46 }
47 };
48
49 }
50
67 template <typename T_y>
68 inline bool check_positive(const char* function,
69 const char* name,
70 const T_y& y) {
71 return positive<T_y, is_vector_like<T_y>::value>
72 ::check(function, name, y);
73 }
74
75 }
76 }
77 #endif
stan::length
size_t length(const std::vector< T > &x)
Definition: length.hpp:10
domain_error_vec.hpp
is_vector_like.hpp
get.hpp
stan::math::check_positive
bool check_positive(const char *function, const char *name, const T_y &y)
Return true if y is positive.
Definition: check_positive.hpp:68
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
value_type.hpp
domain_error.hpp
stan::math::value_type
Primary template class for metaprogram to compute the type of values stored in a container.
Definition: value_type.hpp:21

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