16 #ifndef OPENKALMAN_EIGEN_TRAITS_RESHAPED_HPP 17 #define OPENKALMAN_EIGEN_TRAITS_RESHAPED_HPP 19 #include <type_traits> 26 template<
typename XprType,
int Rows,
int Cols,
int Order,
bool HasDirectAccess>
27 struct ReshapedNested {
using type =
typename Eigen::Reshaped<XprType, Rows, Cols, Order>::MatrixTypeNested; };
29 template<
typename XprType,
int Rows,
int Cols,
int Order>
32 using type =
typename Eigen::internal::ref_selector<XprType>::non_const_type;
37 template<
typename XprType,
int Rows,
int Cols,
int Order>
45 static constexpr std::size_t nested_components = has_dynamic_dimensions<XprType> ?
dynamic_size :
46 index_dimension_of_v<XprType, 0> * index_dimension_of_v<XprType, 1>;
48 static constexpr std::size_t xprtypemax = dynamic_index_count_v<XprType> < 2 ? std::max(
49 dynamic_dimension<XprType, 0> ? 0 : index_dimension_of_v<XprType, 0>,
50 dynamic_dimension<XprType, 1> ? 0 : index_dimension_of_v<XprType, 1>) :
dynamic_size;
52 static constexpr
bool HasDirectAccess = Eigen::internal::traits<Eigen::Reshaped<XprType, Rows, Cols, Order>>::HasDirectAccess;
54 using Nested_t =
typename detail::ReshapedNested<XprType, Rows, Cols, Order, HasDirectAccess>::type;
58 template<
typename Arg,
typename N>
61 if constexpr (values::fixed<N>)
63 constexpr
auto dim = n == 0_uz ? Rows : Cols;
64 constexpr
auto other_dim = n == 0_uz ? Cols : Rows;
65 constexpr std::size_t dimension =
66 dim != Eigen::Dynamic ? dim :
67 other_dim == Eigen::Dynamic or other_dim == 0 ?
dynamic_size :
68 other_dim == index_dimension_of_v<XprType, 0> ? index_dimension_of_v<XprType, 1> :
69 other_dim == index_dimension_of_v<XprType, 1> ? index_dimension_of_v<XprType, 0> :
70 nested_components !=
dynamic_size and nested_components % other_dim == 0 ? nested_components / other_dim :
75 if constexpr (n == 0_uz)
return static_cast<std::size_t
>(arg.rows());
76 else return static_cast<std::size_t
>(arg.cols());
78 else return Dimensions<dimension>{};
82 if (n == 0_uz)
return static_cast<std::size_t
>(arg.rows());
83 else return static_cast<std::size_t
>(arg.cols());
88 template<
typename Arg>
91 return std::forward<Arg>(arg).nestedExpression();
95 template<
typename Arg>
96 static constexpr
auto get_constant(
const Arg& arg)
102 template<
typename Arg>
103 static constexpr
auto get_constant_diagonal(
const Arg& arg)
105 if constexpr ((Rows != Eigen::Dynamic and Rows == XprType::RowsAtCompileTime) or (Cols != Eigen::Dynamic and Cols == XprType::ColsAtCompileTime))
108 return std::monostate{};
112 template<Applicability b>
114 (Rows == 1 and Cols == 1 and OpenKalman::one_dimensional<XprType, Applicability::permitted>) or
115 ((Rows == 1 or Rows == Eigen::Dynamic) and (Cols == 1 or Cols == Eigen::Dynamic) and OpenKalman::one_dimensional<XprType, b>);
118 template<Applicability b>
119 static constexpr
bool is_square =
121 ((Rows != Eigen::Dynamic or Cols != Eigen::Dynamic) and not has_dynamic_dimensions<XprType>)) and
122 (Rows == Eigen::Dynamic or Cols == Eigen::Dynamic or Rows == Cols) and
125 (Rows == Eigen::Dynamic or Rows * Rows == nested_components))) and
126 (Rows == Eigen::Dynamic or xprtypemax ==
dynamic_size or (Rows * Rows) % xprtypemax == 0) and
127 (Cols == Eigen::Dynamic or xprtypemax ==
dynamic_size or (Cols * Cols) % xprtypemax == 0);
130 template<TriangleType t>
131 static constexpr
bool is_triangular = triangular_matrix<XprType, t> and
132 ((Rows != Eigen::Dynamic and Rows == XprType::RowsAtCompileTime) or (Cols != Eigen::Dynamic and Cols == XprType::ColsAtCompileTime));
135 static constexpr
bool is_triangular_adapter =
false;
138 static constexpr
bool is_hermitian = hermitian_matrix<XprType, Applicability::permitted> and
139 ((XprType::RowsAtCompileTime == Eigen::Dynamic and XprType::ColsAtCompileTime == Eigen::Dynamic) or
140 (Rows == Eigen::Dynamic or Rows == XprType::RowsAtCompileTime or Rows == XprType::ColsAtCompileTime) and
141 (Cols == Eigen::Dynamic or Cols == XprType::ColsAtCompileTime or Cols == XprType::RowsAtCompileTime));
146 #endif //OPENKALMAN_EIGEN_TRAITS_RESHAPED_HPP constexpr bool one_dimensional
Specifies that a type is one-dimensional in every index.
Definition: one_dimensional.hpp:83
Definition: indexible_object_traits.hpp:36
Definition: basics.hpp:41
Trait object providing get and set routines.
Definition: eigen-forward-declarations.hpp:502
Definition: eigen-comma-initializers.hpp:20
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 sqrt(const Arg &arg)
A constexpr alternative to std::sqrt.
Definition: sqrt.hpp:46
constexpr bool near(const Arg1 &arg1, const Arg2 &arg2)
Determine whether two numbers are within a rounding tolerance.
Definition: near.hpp:36
constexpr std::size_t dynamic_size
A constant indicating that a size or index is dynamic.
Definition: global-definitions.hpp:33
decltype(auto) constexpr nested_object(Arg &&arg)
Retrieve a nested object of Arg, if it exists.
Definition: nested_object.hpp:34
Definition: Reshaped.hpp:27
The concept, trait, or restraint represents a compile-time guarantee.
constexpr auto get_vector_space_descriptor(const T &t, const N &n)
Get the coordinates::pattern object for index N of indexible object T.
Definition: get_vector_space_descriptor.hpp:56