Automatic Differentiation
 
Loading...
Searching...
No Matches
check_positive.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_ERR_CHECK_POSITIVE_HPP
2#define STAN_MATH_PRIM_ERR_CHECK_POSITIVE_HPP
3
9#include <type_traits>
10#include <string>
11
12namespace stan {
13namespace math {
14
26template <typename T_y>
27inline void check_positive(const char* function, const char* name,
28 const T_y& y) {
29 elementwise_check([](double x) { return x > 0; }, function, name, y,
30 "positive");
31}
32
42inline void check_positive(const char* function, const char* name,
43 const char* expr, int size) {
44 if (size <= 0) {
45 [&]() STAN_COLD_PATH {
46 std::stringstream msg;
47 msg << "; dimension size expression = " << expr;
48 std::string msg_str(msg.str());
49 invalid_argument(function, name, size,
50 "must have a positive size, but is ", msg_str.c_str());
51 }();
52 }
53}
54
55} // namespace math
56} // namespace stan
57#endif
#define STAN_COLD_PATH
int64_t size(const T &m)
Returns the size (number of the elements) of a matrix_cl or var_value<matrix_cl<T>>.
Definition size.hpp:19
void elementwise_check(const F &is_good, const char *function, const char *name, const T &x, const char *must_be, const Indexings &... indexings)
Check that the predicate holds for the value of x.
void invalid_argument(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw an invalid_argument exception with a consistently formatted message.
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...