16 #ifndef OPENKALMAN_EIGEN_TRAITS_CWISEBINARYOP_HPP 17 #define OPENKALMAN_EIGEN_TRAITS_CWISEBINARYOP_HPP 22 template<
typename BinaryOp,
typename LhsType,
typename RhsType>
28 using Xpr = Eigen::CwiseBinaryOp<BinaryOp, LhsType, RhsType>;
34 template<
typename Arg,
typename N>
38 if constexpr (square_shaped<LhsType> or square_shaped<RhsType>)
39 return internal::most_fixed_pattern(
40 OpenKalman::get_pattern_collection<0>(arg.lhs()),
41 OpenKalman::get_pattern_collection<0>(arg.rhs()),
42 OpenKalman::get_pattern_collection<1>(arg.lhs()),
43 OpenKalman::get_pattern_collection<1>(arg.rhs()));
45 return internal::most_fixed_pattern(
55 #ifndef __cpp_concepts 56 template<
typename T = Traits,
typename =
void>
57 struct custom_get_constant_defined : std::false_type {};
60 struct custom_get_constant_defined<T, std::void_t<decltype(T::template get_constant<LhsType, RhsType>(std::declval<const Xpr&>()))>>
63 template<
typename T = Traits,
typename =
void>
64 struct constexpr_operation_defined : std::false_type {};
67 struct constexpr_operation_defined<T, std::void_t<decltype(T::constexpr_operation())>>
73 template<
typename Arg>
74 static constexpr
auto get_constant(
const Arg& arg)
77 if constexpr (requires { Traits::template get_constant<LhsType, RhsType>(arg); })
81 return Traits::template get_constant<LhsType, RhsType>(arg);
82 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::sum and zero<LhsType>)
84 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::sum and zero<RhsType>)
86 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::product and zero<LhsType>)
88 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::product and zero<RhsType>)
91 else if constexpr (requires { Traits::constexpr_operation(); })
104 #ifndef __cpp_concepts 105 template<
typename T = Traits,
typename =
void>
106 struct custom_get_constant_diagonal_defined : std::false_type {};
109 struct custom_get_constant_diagonal_defined<T, std::void_t<decltype(T::template get_constant_diagonal<LhsType, RhsType>(std::declval<const Xpr&>()))>>
115 template<
typename Arg>
116 static constexpr
auto get_constant_diagonal(
const Arg& arg)
118 #ifdef __cpp_concepts 119 if constexpr (requires { Traits::template get_constant_diagonal<LhsType, RhsType>(arg); })
123 return Traits::template get_constant_diagonal<LhsType, RhsType>(arg);
124 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::sum and zero<LhsType>)
125 return constant_diagonal_value {arg.rhs()};
126 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::sum and zero<RhsType>)
127 return constant_diagonal_value {arg.lhs()};
128 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::product and zero<LhsType>)
130 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::product and zero<RhsType>)
132 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::product)
134 auto c_left = [](
const Arg& arg){
135 if constexpr (constant_matrix<LhsType>)
return constant_value {arg.lhs()};
136 else return constant_diagonal_value {arg.lhs()};
138 auto c_right = [](
const Arg& arg){
139 if constexpr (constant_matrix<RhsType>)
return constant_value {arg.rhs()};
140 else return constant_diagonal_value {arg.rhs()};
142 #ifdef __cpp_concepts 143 if constexpr (requires { Traits::constexpr_operation(); })
151 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::sum or Traits::preserves_constant_diagonal)
153 #ifdef __cpp_concepts 154 if constexpr (requires { Traits::constexpr_operation(); })
159 constant_diagonal_value {arg.lhs()}, constant_diagonal_value {arg.rhs()});
162 constant_diagonal_value {arg.lhs()}, constant_diagonal_value {arg.rhs()});
166 return std::monostate{};
171 template<applicability b>
173 OpenKalman::one_dimensional<LhsType, applicability::permitted> and
174 OpenKalman::one_dimensional<RhsType, applicability::permitted> and
176 not has_dynamic_dimensions<Xpr> or
177 OpenKalman::one_dimensional<LhsType, b> or
178 OpenKalman::one_dimensional<RhsType, b>);
181 template<applicability b>
182 static constexpr
bool is_square =
183 square_shaped<LhsType, applicability::permitted> and
184 square_shaped<RhsType, applicability::permitted> and
186 not has_dynamic_dimensions<Xpr> or
187 square_shaped<LhsType, b> or
188 square_shaped<RhsType, b>);
191 static constexpr
bool is_triangular_adapter =
false;
194 template<triangle_type t>
195 static constexpr
bool triangle_type_value =
196 Traits::binary_functor_type == Eigen3::BinaryFunctorType::sum ?
197 triangular_matrix<LhsType, t> and triangular_matrix<RhsType, t> and
199 Traits::binary_functor_type == Eigen3::BinaryFunctorType::product and
200 (triangular_matrix<LhsType, t> or triangular_matrix<RhsType, t> or
201 (triangular_matrix<LhsType, triangle_type::lower> and triangular_matrix<RhsType, triangle_type::upper>) or
202 (triangular_matrix<LhsType, triangle_type::upper> and triangular_matrix<RhsType, triangle_type::lower>));
205 static constexpr
bool is_hermitian = Traits::preserves_hermitian and
206 hermitian_matrix<LhsType, applicability::permitted> and hermitian_matrix<RhsType, applicability::permitted>;;
constexpr bool one_dimensional
Specifies that a type is one-dimensional in every index.
Definition: one_dimensional.hpp:56
Definition: basics.hpp:41
The concept, trait, or restraint represents a compile-time guarantee.
Definition: eigen-comma-initializers.hpp:20
decltype(auto) constexpr get_pattern_collection(T &&t)
Get the coordinates::pattern_collection associated with indexible object T.
Definition: get_pattern_collection.hpp:59
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
Lower, upper, or diagonal matrix.
Definition: object_traits.hpp:38
Trait object providing get and set routines.
Definition: eigen-forward-declarations.hpp:502
Definition: eigen-forward-declarations.hpp:61
constexpr auto constant_value(T &&t)
The constant value associated with a constant_object or constant_diagonal_object. ...
Definition: constant_value.hpp:37
constexpr auto operation(Operation &&op, Args &&...args)
A potentially constant-evaluated operation involving some number of values.
Definition: operation.hpp:98