1#ifndef STAN_MATH_PRIM_ERR_CHECK_LESS_HPP
2#define STAN_MATH_PRIM_ERR_CHECK_LESS_HPP
33template <
typename T_y,
typename T_high,
34 require_all_stan_scalar_t<T_y, T_high>* =
nullptr,
typename... Idxs>
35inline void check_less(
const char* function,
const char* name,
const T_y& y,
36 const T_high& high, Idxs... idxs) {
38 [](
auto y,
auto high,
auto function,
auto name,
42 (
", but must be less than " + std::to_string(
value_of_rec(high)))
44 }(y, high, function, name, idxs...);
71inline void check_less(
const char* function,
const char* name,
const T_y& y,
72 const T_high& high, Idxs... idxs) {
74 for (Eigen::Index i = 0; i < high_arr.size(); ++i) {
75 if (
unlikely(!(y < high_arr.coeff(i)))) {
76 [](
auto y,
auto&& high_arr,
auto name,
auto function,
auto i,
80 (
", but must be less than " + std::to_string(high_arr.coeff(i)))
82 }(y, high_arr, name, function, i, idxs...);
105template <
typename T_y,
typename T_high, require_stan_scalar_t<T_y>* =
nullptr,
106 require_dense_dynamic_t<T_high>* =
nullptr,
typename... Idxs>
107inline void check_less(
const char* function,
const char* name,
const T_y& y,
108 const T_high& high, Idxs... idxs) {
110 for (Eigen::Index j = 0; j < high_arr.cols(); ++j) {
111 for (Eigen::Index i = 0; i < high_arr.rows(); ++i) {
112 if (
unlikely(!(y < high_arr.coeff(i, j)))) {
113 [](
auto y,
auto&& high_arr,
auto name,
auto function,
auto i,
auto j,
118 (
", but must be less than "
119 + std::to_string(high_arr.coeff(i, j)))
121 }(y, high_arr, name, function, i, j, idxs...);
145template <
typename T_y,
typename T_high, require_vector_t<T_y>* =
nullptr,
146 require_not_std_vector_vt<is_container_or_var_matrix, T_y>* =
nullptr,
147 require_stan_scalar_t<T_high>* =
nullptr,
typename... Idxs>
148inline void check_less(
const char* function,
const char* name,
const T_y& y,
149 const T_high& high, Idxs... idxs) {
151 for (Eigen::Index i = 0; i < y_arr.size(); ++i) {
152 if (
unlikely(!(y_arr.coeff(i) < high))) {
153 [](
auto&& y_arr,
auto high,
auto name,
auto function,
auto i,
158 (
", but must be less than " + std::to_string(
value_of_rec(high)))
160 }(y_arr, high, name, function, i, idxs...);
183template <
typename T_y,
typename T_high,
184 require_dense_dynamic_t<T_y>* =
nullptr,
185 require_stan_scalar_t<T_high>* =
nullptr,
typename... Idxs>
186inline void check_less(
const char* function,
const char* name,
const T_y& y,
187 const T_high& high, Idxs... idxs) {
189 for (Eigen::Index j = 0; j < y_arr.cols(); ++j) {
190 for (Eigen::Index i = 0; i < y_arr.rows(); ++i) {
191 if (
unlikely(!(y_arr.coeff(i, j) < high))) {
192 [](
auto&& y_arr,
auto high,
auto name,
auto function,
auto i,
auto j,
197 (
", but must be less than " + std::to_string(
value_of_rec(high)))
199 }(y_arr, high, name, function, i, j, idxs...);
225template <
typename T_y,
typename T_high,
226 require_all_vector_t<T_y, T_high>* =
nullptr,
230inline void check_less(
const char* function,
const char* name,
const T_y& y,
231 const T_high& high, Idxs... idxs) {
234 for (Eigen::Index i = 0; i < y_arr.size(); ++i) {
235 if (
unlikely(!(y_arr.coeff(i) < high_arr.coeff(i)))) {
236 [](
auto&& y_arr,
auto&& high_arr,
auto name,
auto function,
auto i,
241 (
", but must be less than " + std::to_string(high_arr.coeff(i)))
243 }(y_arr, high_arr, name, function, i, idxs...);
268template <
typename T_y,
typename T_high,
269 require_all_dense_dynamic_t<T_y, T_high>* =
nullptr,
typename... Idxs>
270inline void check_less(
const char* function,
const char* name,
const T_y& y,
271 const T_high& high, Idxs... idxs) {
274 for (Eigen::Index j = 0; j < y_arr.cols(); ++j) {
275 for (Eigen::Index i = 0; i < y_arr.rows(); ++i) {
276 if (
unlikely(!(y_arr.coeff(i, j) < high_arr.coeff(i, j)))) {
277 [](
auto&& y_arr,
auto&& high_arr,
auto name,
auto function,
auto i,
282 (
", but must be less than "
283 + std::to_string(high_arr.coeff(i, j)))
285 }(y_arr, high_arr, name, function, i, j, idxs...);
308template <
typename T_y,
typename T_high,
309 require_std_vector_vt<is_container_or_var_matrix, T_y>* =
nullptr,
310 require_not_std_vector_t<T_high>* =
nullptr,
typename... Idxs>
311inline void check_less(
const char* function,
const char* name,
const T_y& y,
312 const T_high& high, Idxs... idxs) {
313 for (
size_t i = 0; i < y.size(); ++i) {
314 check_less(function, name, y[i], high, idxs..., i);
335template <
typename T_y,
typename T_high,
336 require_not_std_vector_t<T_y>* =
nullptr,
337 require_std_vector_vt<is_container_or_var_matrix, T_high>* =
nullptr,
339inline void check_less(
const char* function,
const char* name,
const T_y& y,
340 const T_high& high, Idxs... idxs) {
341 for (
size_t i = 0; i < high.size(); ++i) {
342 check_less(function, name, y, high[i], idxs..., i);
364template <
typename T_y,
typename T_high,
367 require_all_std_vector_t<T_y, T_high>* =
nullptr,
typename... Idxs>
368inline void check_less(
const char* function,
const char* name,
const T_y& y,
369 const T_high& high, Idxs... idxs) {
370 for (
size_t i = 0; i < y.size(); ++i) {
371 check_less(function, name, y[i], high[i], idxs..., i);
require_t< is_stan_scalar< std::decay_t< T > > > require_stan_scalar_t
Require type satisfies is_stan_scalar.
require_any_t< container_type_check_base< is_std_vector, value_type_t, TypeCheck, Check >... > require_any_std_vector_vt
Require any of the types satisfy is_std_vector.
require_not_t< container_type_check_base< is_std_vector, value_type_t, TypeCheck, Check... > > require_not_std_vector_vt
Require type does not satisfy is_std_vector or.
require_all_not_t< container_type_check_base< is_std_vector, value_type_t, TypeCheck, Check >... > require_all_not_std_vector_vt
Require none of the types satisfy is_std_vector.
require_t< is_vector< std::decay_t< T > > > require_vector_t
Require type satisfies is_vector.
auto make_iter_name(const char *name)
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
T as_array_or_scalar(T &&v)
Returns specified input value.
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.
void throw_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.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
void throw_domain_error_mat(const char *function, const char *name, const T &y, size_t i, size_t j, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message for matrices.
void check_less(const char *function, const char *name, const T_y &y, const T_high &high, Idxs... idxs)
Throw an exception if y is not strictly less than high.
bool_constant< math::disjunction< is_container< Container >, is_var_matrix< Container > >::value > is_container_or_var_matrix
Deduces whether type is eigen matrix, standard vector, or var<Matrix>.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...