Automatic Differentiation
 
Loading...
Searching...
No Matches
check_positive_ordered.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_ERR_CHECK_POSITIVE_ORDERED_HPP
2#define STAN_MATH_PRIM_ERR_CHECK_POSITIVE_ORDERED_HPP
3
11#include <sstream>
12#include <string>
13
14namespace stan {
15namespace math {
16
29template <typename Vec, require_vector_t<Vec>* = nullptr,
30 require_not_std_vector_t<Vec>* = nullptr>
31void check_positive_ordered(const char* function, const char* name,
32 const Vec& y) {
33 if (y.size() == 0) {
34 return;
35 }
36 auto&& y_ref = to_ref(value_of_rec(y));
37 if (y_ref.coeff(0) < 0) {
38 [&]() STAN_COLD_PATH {
39 std::ostringstream msg;
40 msg << "is not a valid positive_ordered vector."
41 << " The element at " << stan::error_index::value << " is ";
42 std::string msg_str(msg.str());
43 throw_domain_error(function, name, value_of_rec(to_ref(y).coeff(0)),
44 msg_str.c_str(), ", but should be postive.");
45 }();
46 }
47 check_ordered(function, name, y_ref);
48}
49
62template <typename StdVec, require_std_vector_t<StdVec>* = nullptr>
63void check_positive_ordered(const char* function, const char* name,
64 const StdVec& y) {
65 for (size_t i = 0; i < y.size(); ++i) {
66 check_positive_ordered(function, internal::make_iter_name(name, i).c_str(),
67 y[i]);
68 }
69}
70} // namespace math
71} // namespace stan
72#endif
#define STAN_COLD_PATH
auto make_iter_name(const char *name)
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
void check_positive_ordered(const char *function, const char *name, const Vec &y)
Throw an exception if the specified the vector contains negative values or is not sorted into strictl...
void throw_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.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
void check_ordered(const char *function, const char *name, const T_y &y)
Throw an exception if the specified vector is not sorted into strictly increasing order.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...