16 #ifndef OPENKALMAN_EIGEN_TRAITS_TENSORCWISEBINARYOP_HPP 17 #define OPENKALMAN_EIGEN_TRAITS_TENSORCWISEBINARYOP_HPP 22 template<
typename BinaryOp,
typename LhsXprType,
typename RhsXprType>
28 using Xpr = Eigen::TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType>;
34 template<
typename Arg,
typename N>
38 if constexpr (values::fixed<N>)
40 if constexpr (not dynamic_dimension<LhsXprType, n>)
53 #ifndef __cpp_concepts 54 template<
typename T = Traits,
typename =
void>
55 struct custom_get_constant_defined : std::false_type {};
58 struct custom_get_constant_defined<T, std::void_t<decltype(T::template get_constant<LhsXprType, RhsXprType>(std::declval<const Xpr&>()))>>
61 template<
typename T = Traits,
typename =
void>
62 struct constexpr_operation_defined : std::false_type {};
65 struct constexpr_operation_defined<T, std::void_t<decltype(T::constexpr_operation())>>
71 template<
typename Arg>
72 static constexpr
auto get_constant(
const Arg& arg)
75 if constexpr (requires { Traits::template get_constant<LhsXprType, RhsXprType>(arg); })
79 return Traits::template get_constant<LhsXprType, RhsXprType>(arg);
80 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::sum and zero<LhsXprType>)
82 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::sum and zero<RhsXprType>)
84 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::product and zero<LhsXprType>)
86 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::product and zero<RhsXprType>)
89 else if constexpr (requires { Traits::constexpr_operation(); })
102 #ifndef __cpp_concepts 103 template<
typename T = Traits,
typename =
void>
104 struct custom_get_constant_diagonal_defined : std::false_type {};
107 struct custom_get_constant_diagonal_defined<T, std::void_t<decltype(T::template get_constant_diagonal<LhsXprType, RhsXprType>(std::declval<const Xpr&>()))>>
113 template<
typename Arg>
114 static constexpr
auto get_constant_diagonal(
const Arg& arg)
116 #ifdef __cpp_concepts 117 if constexpr (requires { Traits::template get_constant_diagonal<LhsXprType, RhsXprType>(arg); })
121 return Traits::template get_constant_diagonal<LhsXprType, RhsXprType>(arg);
122 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::sum and zero<LhsXprType>)
123 return constant_diagonal_value {arg.rhsExpression()};
124 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::sum and zero<RhsXprType>)
125 return constant_diagonal_value {arg.lhsExpression()};
126 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::product and zero<LhsXprType>)
128 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::product and zero<RhsXprType>)
130 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::product)
132 auto c_left = [](
const Arg& arg){
133 if constexpr (constant_matrix<LhsXprType>)
return constant_value {arg.lhsExpression()};
134 else return constant_diagonal_value {arg.lhsExpression()};
136 auto c_right = [](
const Arg& arg){
137 if constexpr (constant_matrix<RhsXprType>)
return constant_value {arg.rhsExpression()};
138 else return constant_diagonal_value {arg.rhsExpression()};
140 #ifdef __cpp_concepts 141 if constexpr (requires { Traits::constexpr_operation(); })
149 else if constexpr (Traits::binary_functor_type == Eigen3::BinaryFunctorType::sum or Traits::preserves_constant_diagonal)
151 #ifdef __cpp_concepts 152 if constexpr (requires { Traits::constexpr_operation(); })
157 constant_diagonal_value {arg.lhsExpression()}, constant_diagonal_value {arg.rhsExpression()});
160 constant_diagonal_value {arg.lhsExpression()}, constant_diagonal_value {arg.rhsExpression()});
164 return std::monostate{};
169 template<applicability b>
171 OpenKalman::one_dimensional<LhsXprType, applicability::permitted> and OpenKalman::one_dimensional<RhsXprType, applicability::permitted> and
173 (square_shaped<LhsXprType, b> and (dimension_size_of_index_is<RhsXprType, 0, 1> or dimension_size_of_index_is<RhsXprType, 1, 1>)) or
174 ((dimension_size_of_index_is<LhsXprType, 0, 1> or dimension_size_of_index_is<LhsXprType, 1, 1>) and square_shaped<RhsXprType, b>));
177 template<applicability b>
178 static constexpr
bool is_square =
179 square_shaped<LhsXprType, applicability::permitted> and square_shaped<RhsXprType, applicability::permitted> and
181 square_shaped<LhsXprType, b> or square_shaped<RhsXprType, b>);
184 static constexpr
bool is_triangular_adapter =
false;
187 template<triangle_type t>
188 static constexpr
bool triangle_type_value =
189 Traits::binary_functor_type == Eigen3::BinaryFunctorType::sum ?
190 triangular_matrix<LhsXprType, t> and triangular_matrix<RhsXprType, t> and
192 Traits::binary_functor_type == Eigen3::BinaryFunctorType::product and
193 (triangular_matrix<LhsXprType, t> or triangular_matrix<RhsXprType, t> or
194 (triangular_matrix<LhsXprType, triangle_type::lower> and triangular_matrix<RhsXprType, triangle_type::upper>) or
195 (triangular_matrix<LhsXprType, triangle_type::upper> and triangular_matrix<RhsXprType, triangle_type::lower>));
198 static constexpr
bool is_hermitian = Traits::preserves_hermitian and
199 hermitian_matrix<LhsXprType, applicability::permitted> and hermitian_matrix<RhsXprType, 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
Trait object providing get and set routines for Eigen tensors.
Definition: eigen-tensor-forward-declarations.hpp:114
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
Definition: eigen-forward-declarations.hpp:61
constexpr bool has_dynamic_dimensions
Specifies that T has at least one index with dynamic dimensions.
Definition: has_dynamic_dimensions.hpp:30
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