1 #ifndef STAN_MATH_PRIM_FUN_EIGEN_COMPARISONS_HPP
2 #define STAN_MATH_PRIM_FUN_EIGEN_COMPARISONS_HPP
3 
4 #include <stan/math/prim/meta.hpp>
5 #include <stan/math/prim/fun/Eigen.hpp>
6 #include <stan/math/prim/fun/value_of.hpp>
7 
8 namespace stan {
9 namespace math {
10 
11 /**
12  * Add support for comparisons involving Eigen types with different scalars,
13  * where one of the scalars is an autodiff type. This includes comparisons of
14  * an Eigen type and a scalar.
15  * @param OPERATOR name of the operator function to implement
16  * @param OP operator to use for comparison of values
17  **/
18 #define ADD_MIXED_AUTODIFF_SCALAR_COMPARISON(OPERATOR, OP) \
19   template <typename T_a, typename T_b,                    \
20             require_any_eigen_t<T_a, T_b>* = nullptr,      \
21             require_any_st_autodiff<T_a, T_b>* = nullptr,  \
22             require_not_st_same<T_a, T_b>* = nullptr>      \
23   auto OPERATOR(const T_a& a, const T_b& b) {              \
24     return value_of(a) OP value_of(b);                     \
25   }
26 
27 ADD_MIXED_AUTODIFF_SCALAR_COMPARISON(operator<, <);
28 ADD_MIXED_AUTODIFF_SCALAR_COMPARISON(operator<=, <=);
29 ADD_MIXED_AUTODIFF_SCALAR_COMPARISON(operator>, >);
30 ADD_MIXED_AUTODIFF_SCALAR_COMPARISON(operator>=, >=);
31 ADD_MIXED_AUTODIFF_SCALAR_COMPARISON(operator==, ==);
32 ADD_MIXED_AUTODIFF_SCALAR_COMPARISON(operator!=, !=);
33 
34 #undef ADD_MIXED_AUTODIFF_SCALAR_COMPARISON
35 
36 }  // namespace math
37 }  // namespace stan
38 
39 #endif
40