16 #ifndef OPENKALMAN_EIGEN_TRAITS_FUNCTORS_BINARY_HPP 17 #define OPENKALMAN_EIGEN_TRAITS_FUNCTORS_BINARY_HPP 19 #include <type_traits> 25 template<
typename Operation>
26 struct BinaryFunctorTraits
29 template<
typename...Args>
44 template<
typename Scalar>
48 static constexpr
bool preserves_constant_diagonal =
true;
54 template<
typename Scalar>
58 static constexpr
bool preserves_constant_diagonal =
true;
64 template<
typename Scalar>
68 static constexpr
bool preserves_constant_diagonal =
true;
74 template<
typename Scalar>
78 static constexpr
bool preserves_constant_diagonal =
false;
84 template<
typename Scalar>
88 static constexpr
bool preserves_constant_diagonal =
true;
94 template<
typename Scalar>
98 static constexpr
bool preserves_constant_diagonal =
true;
102 template<
typename LhsType,
typename RhsType,
typename Arg>
103 static constexpr
auto get_constant(
const Arg& arg)
117 return std::monostate{};
121 template<
typename LhsType,
typename RhsType,
typename Arg>
122 static constexpr
auto get_constant_diagonal(
const Arg& arg)
126 if constexpr (constant_diagonal_coefficient_v<RhsType> ==
true and diagonal_matrix<LhsType>)
128 else if constexpr (constant_diagonal_coefficient_v<RhsType> ==
false)
131 return std::monostate{};
135 if constexpr (constant_diagonal_coefficient_v<LhsType> ==
true and diagonal_matrix<RhsType>)
137 else if constexpr (constant_diagonal_coefficient_v<LhsType> ==
false)
140 return std::monostate{};
144 return std::monostate{};
150 template<
typename Scalar>
154 static constexpr
bool preserves_constant_diagonal =
false;
160 template<
typename Scalar>
164 static constexpr
bool preserves_constant_diagonal =
true;
170 template<
typename Scalar>
174 static constexpr
bool preserves_constant_diagonal =
true;
180 template<
typename Scalar>
184 static constexpr
bool preserves_constant_diagonal =
true;
190 template<
typename Scalar>
194 static constexpr
bool preserves_constant_diagonal =
false;
200 template<
typename Scalar>
204 static constexpr
bool preserves_constant_diagonal =
false;
214 template<
typename Scalar1,
typename Scalar2>
219 template<
typename Scalar1,
typename Scalar2>
224 template<
typename Scalar1,
typename Scalar2>
227 struct Op { constexpr
auto operator()(Scalar1 arg1, Scalar2 arg2)
const {
return values::conj(arg1) * arg2; } };
229 static constexpr
bool preserves_constant_diagonal =
true;
235 template<
typename Scalar1,
typename Scalar2>
238 struct Op { constexpr
auto operator()(Scalar1 arg1, Scalar2 arg2)
const {
return std::min(arg1, arg2); } };
240 static constexpr
bool preserves_constant_diagonal =
true;
244 template<
typename LhsType,
typename RhsType,
typename Arg>
245 static constexpr
auto get_constant(
const Arg& arg)
249 if constexpr (constant_coefficient_v<LhsType> < 0 and constant_coefficient_v<LhsType> < constant_diagonal_coefficient_v<RhsType>)
251 else return std::monostate{};
255 if constexpr (constant_coefficient_v<RhsType> < 0 and constant_coefficient_v<RhsType> < constant_diagonal_coefficient_v<LhsType>)
257 else return std::monostate{};
265 template<
typename LhsType,
typename RhsType,
typename Arg>
266 static constexpr
auto get_constant_diagonal(
const Arg& arg)
270 if constexpr (constant_coefficient_v<LhsType> > 0 and constant_coefficient_v<LhsType> > constant_diagonal_coefficient_v<RhsType>)
272 else return std::monostate{};
276 if constexpr (constant_coefficient_v<RhsType> > 0 and constant_coefficient_v<RhsType> > constant_diagonal_coefficient_v<LhsType>)
278 else return std::monostate{};
289 template<
typename Scalar1,
typename Scalar2>
292 struct Op { constexpr
auto operator()(Scalar1 arg1, Scalar2 arg2)
const {
return std::max(arg1, arg2); } };
294 static constexpr
bool preserves_constant_diagonal =
true;
298 template<
typename LhsType,
typename RhsType,
typename Arg>
299 static constexpr
auto get_constant(
const Arg& arg)
303 if constexpr (constant_coefficient_v<LhsType> > 0 and constant_coefficient_v<LhsType> > constant_diagonal_coefficient_v<RhsType>)
305 else return std::monostate{};
309 if constexpr (constant_coefficient_v<RhsType> > 0 and constant_coefficient_v<RhsType> > constant_diagonal_coefficient_v<LhsType>)
311 else return std::monostate{};
320 template<
typename LhsType,
typename RhsType,
typename Arg>
321 static constexpr
auto get_constant_diagonal(
const Arg& arg)
325 if constexpr (constant_coefficient_v<LhsType> < 0 and constant_coefficient_v<LhsType> < constant_diagonal_coefficient_v<RhsType>)
327 else return std::monostate{};
331 if constexpr (constant_coefficient_v<RhsType> < 0 and constant_coefficient_v<RhsType> < constant_diagonal_coefficient_v<LhsType>)
333 else return std::monostate{};
344 template<
typename LhsScalar,
typename RhsScalar, Eigen::
internal::ComparisonName cmp>
348 constexpr
auto operator()(LhsScalar a, RhsScalar b)
const {
349 if constexpr (cmp == Eigen::internal::ComparisonName::cmp_EQ)
return a == b;
350 else if constexpr (cmp == Eigen::internal::ComparisonName::cmp_LT)
return a < b;
351 else if constexpr (cmp == Eigen::internal::ComparisonName::cmp_LE)
return a <= b;
352 else if constexpr (cmp == Eigen::internal::ComparisonName::cmp_GT)
return a > b;
353 else if constexpr (cmp == Eigen::internal::ComparisonName::cmp_GE)
return a >= b;
354 else if constexpr (cmp == Eigen::internal::ComparisonName::cmp_NEQ)
return a != b;
355 else if constexpr (cmp == Eigen::internal::ComparisonName::cmp_UNORD)
return not (a<=b or b<=a);
356 else return Eigen::internal::scalar_cmp_op<LhsScalar, RhsScalar, cmp> {}(a, b);
360 static constexpr
bool preserves_constant_diagonal =
false;
366 template<
typename Scalar1,
typename Scalar2>
369 struct Op { constexpr
auto operator()(Scalar1 arg1, Scalar2 arg2)
const {
return values::sqrt(arg1 * arg1 + arg2 * arg2); } };
371 static constexpr
bool preserves_constant_diagonal =
true;
377 template<
typename Scalar,
typename Exponent>
380 struct Op { constexpr
auto operator()(Scalar arg1, Exponent arg2)
const {
return values::pow(arg1, arg2); } };
382 static constexpr
bool preserves_constant_diagonal =
false;
388 template<
typename Scalar1,
typename Scalar2>
393 template<
typename Scalar1,
typename Scalar2>
410 template<
typename Scalar>
414 template<
typename Scalar>
418 #if EIGEN_VERSION_AT_LEAST(3,4,0) 419 template<
typename Scalar1,
typename Scalar2>
420 struct BinaryFunctorTraits<Eigen::internal::scalar_absolute_difference_op<Scalar1, Scalar2>>
422 struct Op { constexpr
auto operator()(Scalar1 arg1, Scalar2 arg2)
const {
return arg2 > arg1 ? arg2 - arg1 : arg1 - arg2; } };
424 static constexpr
bool preserves_constant_diagonal =
true;
432 #endif //OPENKALMAN_EIGEN_TRAITS_FUNCTORS_BINARY_HPP A generalization of std::greater in which the arguments may be of different types.
Definition: greater.hpp:29
static constexpr auto constexpr_operation()=delete
Construct Operation or (preferably) an equivalent constexpr operation equivalent to Operation...
An operation involving some number of values.
Definition: operation.hpp:69
A generalization of std::less in which the arguments may be of different types.
Definition: less.hpp:29
Definition: eigen-comma-initializers.hpp:20
Definition: tuple_reverse.hpp:103
The constant associated with T, assuming T is a constant_matrix.
Definition: constant_coefficient.hpp:36
The constant associated with T, assuming T is a constant_diagonal_matrix.
Definition: constant_diagonal_coefficient.hpp:32
constexpr auto conj(const Arg &arg)
A constexpr function for the complex conjugate of a (complex) number.
Definition: conj.hpp:39
constexpr auto sqrt(const Arg &arg)
A constexpr alternative to std::sqrt.
Definition: sqrt.hpp:46
Definition: eigen-forward-declarations.hpp:22
Definition: eigen-forward-declarations.hpp:61
A generalization of std::less_equal in which the arguments may be of different types.
Definition: less_equal.hpp:29
constexpr bool fixed
T is a values::value that is determinable at compile time.
Definition: fixed.hpp:60
A generalization of std::equal_to in which the arguments may be of different types.
Definition: equal_to.hpp:29
static constexpr bool preserves_hermitian
Whether the operation applied to a hermitian matrix always yields a hermitian matrix.
Definition: binary.hpp:36
static constexpr BinaryFunctorType binary_functor_type
Whether binary functor type.
Definition: binary.hpp:33
A generalization of std::not_equal_to in which the arguments may be of different types.
Definition: not_equal_to.hpp:29
A generalization of std::less_equal in which the arguments may be of different types.
Definition: greater_equal.hpp:29