check_greater_or_equal.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_GREATER_OR_EQUAL_HPP
#define STAN_MATH_PRIM_SCAL_ERR_CHECK_GREATER_OR_EQUAL_HPP
#include <stan/math/prim/scal/meta/length.hpp>
#include <stan/math/prim/scal/meta/VectorView.hpp>
#include <stan/math/prim/scal/meta/is_vector_like.hpp>
#include <stan/math/prim/scal/err/domain_error_vec.hpp>
#include <stan/math/prim/scal/err/domain_error.hpp>
#include <string>
namespace stan {
namespace math {
namespace {
template <typename T_y, typename T_low, bool is_vec>
struct greater_or_equal {
static void check(const char* function,
const char* name,
const T_y& y,
const T_low& low) {
using stan::length;
VectorView<const T_low> low_vec(low);
for (size_t n = 0; n < length(low); n++) {
if (!(y >= low_vec[n])) {
std::stringstream msg;
msg << ", but must be greater than or equal to ";
msg << low_vec[n];
std::string msg_str(msg.str());
domain_error(function, name, y,
"is ", msg_str.c_str());
}
}
}
};
template <typename T_y, typename T_low>
struct greater_or_equal<T_y, T_low, true> {
static void check(const char* function,
const char* name,
const T_y& y,
const T_low& low) {
using stan::length;
using stan::get;
VectorView<const T_low> low_vec(low);
for (size_t n = 0; n < length(y); n++) {
if (!(get(y, n) >= low_vec[n])) {
std::stringstream msg;
msg << ", but must be greater than or equal to ";
msg << low_vec[n];
std::string msg_str(msg.str());
domain_error_vec(function, name, y, n,
"is ", msg_str.c_str());
}
}
}
};
}
template <typename T_y, typename T_low>
inline void check_greater_or_equal(const char* function,
const char* name,
const T_y& y,
const T_low& low) {
greater_or_equal<T_y, T_low, is_vector_like<T_y>::value>
::check(function, name, y, low);
}
}
}
#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
stan::math::check_greater_or_equal
void check_greater_or_equal(const char *function, const char *name, const T_y &y, const T_low &low)
Check if y is greater or equal than low.
Definition: check_greater_or_equal.hpp:78
domain_error_vec.hpp
is_vector_like.hpp
VectorView.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
domain_error.hpp

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