Automatic Differentiation
 
Loading...
Searching...
No Matches
check_greater.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_ERR_CHECK_GREATER_HPP
2#define STAN_MATH_PRIM_ERR_CHECK_GREATER_HPP
3
13#include <string>
14
15namespace stan {
16namespace math {
17
34template <typename T_y, typename T_low,
35 require_all_stan_scalar_t<T_y, T_low>* = nullptr, typename... Idxs>
36inline void check_greater(const char* function, const char* name, const T_y& y,
37 const T_low& low, Idxs... idxs) {
38 if (unlikely(!(y > low))) {
39 [](auto y, auto low, auto function, auto name,
40 auto... idxs) STAN_COLD_PATH {
42 function, internal::make_iter_name(name, idxs...).c_str(), y, "is ",
43 (", but must be greater than " + std::to_string(value_of_rec(low)))
44 .c_str());
45 }(y, low, function, name, idxs...);
46 }
47}
48
67template <
68 typename T_y, typename T_low, require_stan_scalar_t<T_y>* = nullptr,
69 require_vector_t<T_low>* = nullptr,
71 typename... Idxs>
72inline void check_greater(const char* function, const char* name, const T_y& y,
73 const T_low& low, Idxs... idxs) {
74 auto&& low_arr = value_of_rec(as_array_or_scalar(to_ref(low)));
75 for (Eigen::Index i = 0; i < low_arr.size(); ++i) {
76 if (unlikely(!(y > low_arr.coeff(i)))) {
77 [](auto y, auto&& low_arr, auto name, auto function, auto i,
78 auto... idxs) STAN_COLD_PATH {
80 function, internal::make_iter_name(name, idxs...).c_str(), y, "is ",
81 (", but must be greater than " + std::to_string(low_arr.coeff(i)))
82 .c_str());
83 }(y, low_arr, name, function, i, idxs...);
84 }
85 }
86}
87
106template <typename T_y, typename T_low, require_stan_scalar_t<T_y>* = nullptr,
107 require_dense_dynamic_t<T_low>* = nullptr, typename... Idxs>
108inline void check_greater(const char* function, const char* name, const T_y& y,
109 const T_low& low, Idxs... idxs) {
110 auto&& low_arr = value_of_rec(to_ref(low));
111 for (Eigen::Index j = 0; j < low_arr.cols(); ++j) {
112 for (Eigen::Index i = 0; i < low_arr.rows(); ++i) {
113 if (unlikely(!(y > low_arr.coeff(i, j)))) {
114 [](auto y, auto&& low_arr, auto name, auto function, auto i, auto j,
115 auto... idxs) STAN_COLD_PATH {
116 throw_domain_error(function,
117 internal::make_iter_name(name, idxs...).c_str(), y,
118 "is ",
119 (", but must be greater than "
120 + std::to_string(low_arr.coeff(i, j)))
121 .c_str());
122 }(y, low_arr, name, function, i, j, idxs...);
123 }
124 }
125 }
126}
127
146template <typename T_y, typename T_low, require_vector_t<T_y>* = nullptr,
147 require_not_std_vector_vt<is_container_or_var_matrix, T_y>* = nullptr,
148 require_stan_scalar_t<T_low>* = nullptr, typename... Idxs>
149inline void check_greater(const char* function, const char* name, const T_y& y,
150 const T_low& low, Idxs... idxs) {
151 auto&& y_arr = value_of_rec(as_array_or_scalar(to_ref(y)));
152 for (Eigen::Index i = 0; i < y_arr.size(); ++i) {
153 if (unlikely(!(y_arr.coeff(i) > low))) {
154 [](auto&& y_arr, auto low, auto name, auto function, auto i,
155 auto... idxs) STAN_COLD_PATH {
157 function, internal::make_iter_name(name, idxs...).c_str(), y_arr, i,
158 "is ",
159 (", but must be greater than " + std::to_string(value_of_rec(low)))
160 .c_str());
161 }(y_arr, low, name, function, i, idxs...);
162 }
163 }
164}
165
184template <typename T_y, typename T_low, require_dense_dynamic_t<T_y>* = nullptr,
185 require_stan_scalar_t<T_low>* = nullptr, typename... Idxs>
186inline void check_greater(const char* function, const char* name, const T_y& y,
187 const T_low& low, Idxs... idxs) {
188 auto&& y_arr = value_of_rec(to_ref(y));
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) > low))) {
192 [](auto&& y_arr, auto low, auto name, auto function, auto i, auto j,
193 auto... idxs) STAN_COLD_PATH {
195 function, internal::make_iter_name(name, idxs...).c_str(), y_arr,
196 i, j, "is ",
197 (", but must be greater than "
198 + std::to_string(value_of_rec(low)))
199 .c_str());
200 }(y_arr, low, name, function, i, j, idxs...);
201 }
202 }
203 }
204}
205
226template <typename T_y, typename T_low,
227 require_all_vector_t<T_y, T_low>* = nullptr,
229 T_low>* = nullptr,
230 typename... Idxs>
231inline void check_greater(const char* function, const char* name, const T_y& y,
232 const T_low& low, Idxs... idxs) {
233 auto&& y_arr = value_of_rec(as_array_or_scalar(to_ref(y)));
234 auto&& low_arr = value_of_rec(as_array_or_scalar(to_ref(low)));
235 for (Eigen::Index i = 0; i < low_arr.size(); ++i) {
236 if (unlikely(!(y_arr.coeff(i) > low_arr.coeff(i)))) {
237 [](auto&& y_arr, auto&& low_arr, auto name, auto function, auto i,
238 auto... idxs) STAN_COLD_PATH {
240 function, internal::make_iter_name(name, idxs...).c_str(), y_arr, i,
241 "is ",
242 (", but must be greater than " + std::to_string(low_arr.coeff(i)))
243 .c_str());
244 }(y_arr, low_arr, name, function, i, idxs...);
245 }
246 }
247}
248
269template <typename T_y, typename T_low,
270 require_all_dense_dynamic_t<T_y, T_low>* = nullptr, typename... Idxs>
271inline void check_greater(const char* function, const char* name, const T_y& y,
272 const T_low& low, Idxs... idxs) {
273 auto&& y_arr = value_of_rec(to_ref(y));
274 auto&& low_arr = value_of_rec(to_ref(low));
275 for (Eigen::Index j = 0; j < low_arr.cols(); ++j) {
276 for (Eigen::Index i = 0; i < low_arr.rows(); ++i) {
277 if (unlikely(!(y_arr.coeff(i, j) > low_arr.coeff(i, j)))) {
278 [](auto&& y_arr, auto&& low_arr, auto name, auto function, auto i,
279 auto j, auto... idxs) STAN_COLD_PATH {
281 function, internal::make_iter_name(name, idxs...).c_str(), y_arr,
282 i, j, "is ",
283 (", but must be greater than "
284 + std::to_string(low_arr.coeff(i, j)))
285 .c_str());
286 }(y_arr, low_arr, name, function, i, j, idxs...);
287 }
288 }
289 }
290}
291
309template <typename T_y, typename T_low,
310 require_std_vector_vt<is_container_or_var_matrix, T_y>* = nullptr,
311 require_not_std_vector_t<T_low>* = nullptr, typename... Idxs>
312inline void check_greater(const char* function, const char* name, const T_y& y,
313 const T_low& low, Idxs... idxs) {
314 for (size_t i = 0; i < y.size(); ++i) {
315 check_greater(function, name, y[i], low, idxs..., i);
316 }
317}
318
336template <typename T_y, typename T_low,
337 require_not_std_vector_t<T_y>* = nullptr,
338 require_std_vector_vt<is_container_or_var_matrix, T_low>* = nullptr,
339 typename... Idxs>
340inline void check_greater(const char* function, const char* name, const T_y& y,
341 const T_low& low, Idxs... idxs) {
342 for (size_t i = 0; i < low.size(); ++i) {
343 check_greater(function, name, y, low[i], idxs..., i);
344 }
345}
346
365template <typename T_y, typename T_low,
367 T_low>* = nullptr,
368 require_all_std_vector_t<T_y, T_low>* = nullptr, typename... Idxs>
369inline void check_greater(const char* function, const char* name, const T_y& y,
370 const T_low& low, Idxs... idxs) {
371 for (size_t i = 0; i < y.size(); ++i) {
372 check_greater(function, name, y[i], low[i], idxs..., i);
373 }
374}
375
376} // namespace math
377} // namespace stan
378#endif
#define STAN_COLD_PATH
#define unlikely(x)
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.
Definition to_ref.hpp:17
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_greater(const char *function, const char *name, const T_y &y, const T_low &low, Idxs... idxs)
Throw an exception if y is not strictly greater than low.
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 ...