check_positive.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_POSITIVE_HPP
#define STAN_MATH_PRIM_SCAL_ERR_CHECK_POSITIVE_HPP
#include <stan/math/prim/scal/err/domain_error.hpp>
#include <stan/math/prim/scal/err/domain_error_vec.hpp>
#include <stan/math/prim/scal/meta/value_type.hpp>
#include <stan/math/prim/scal/meta/length.hpp>
#include <stan/math/prim/scal/meta/get.hpp>
#include <stan/math/prim/scal/meta/is_vector_like.hpp>
#include <boost/type_traits/is_unsigned.hpp>
namespace stan {
namespace math {
namespace {
template <typename T_y, bool is_vec>
struct positive {
static void check(const char* function,
const char* name,
const T_y& y) {
// have to use not is_unsigned. is_signed will be false
// floating point types that have no unsigned versions.
if (!boost::is_unsigned<T_y>::value && !(y > 0))
domain_error(function, name, y,
"is ", ", but must be > 0!");
}
};
template <typename T_y>
struct positive<T_y, true> {
static void check(const char* function,
const char* name,
const T_y& y) {
using stan::length;
for (size_t n = 0; n < length(y); n++) {
if (!boost::is_unsigned<typename value_type<T_y>::type>::value
&& !(stan::get(y, n) > 0))
domain_error_vec(function, name, y, n,
"is ", ", but must be > 0!");
}
}
};
}
template <typename T_y>
inline void check_positive(const char* function,
const char* name,
const T_y& y) {
positive<T_y, is_vector_like<T_y>::value>::check(function, name, y);
}
}
}
#endif
stan
Definition: log_sum_exp.hpp:8
stan::length
size_t length(const std::vector< T > &x)
Definition: length.hpp:10
stan::math::domain_error_vec
void domain_error_vec(const char *function, const char *name, const T &y, size_t i, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
Definition: domain_error_vec.hpp:37
domain_error_vec.hpp
is_vector_like.hpp
get.hpp
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:30
length.hpp
value_type.hpp
domain_error.hpp
stan::math::check_positive
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
Definition: check_positive.hpp:63

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