16 #ifndef OPENKALMAN_EIGEN_TRAITS_DIAGONAL_HPP 17 #define OPENKALMAN_EIGEN_TRAITS_DIAGONAL_HPP 19 #include <type_traits> 24 template<
typename MatrixType,
int DiagIndex>
30 using Xpr = Eigen::Diagonal<MatrixType, DiagIndex>;
35 template<
typename Arg>
38 return std::forward<Arg>(arg).nestedExpression();
42 template<
typename Arg>
43 static constexpr
auto get_constant(
const Arg& arg)
47 if constexpr (constant_diagonal_matrix<MatrixType> and DiagIndex == 0)
51 else if constexpr (zero<MatrixType> or (constant_diagonal_matrix<MatrixType> and DiagIndex != Eigen::DynamicIndex and
52 ((DiagIndex < 0 and (dynamic_dimension<MatrixType, 0> or DiagIndex > -
int(index_dimension_of_v<MatrixType, 0>))) or
53 (DiagIndex > 0 and (dynamic_dimension<MatrixType, 1> or DiagIndex <
int(index_dimension_of_v<MatrixType, 1>))))))
55 if constexpr (DiagIndex < 0 and dynamic_dimension<MatrixType, 0>)
57 if (DiagIndex <= -arg.nestedExpression().rows())
throw std::out_of_range{
"DiagIndex in Eigen::Diagonal is too low for MatrixType."};
59 else if constexpr (DiagIndex > 0 and dynamic_dimension<MatrixType, 1>)
61 if (DiagIndex >= arg.nestedExpression().cols())
throw std::out_of_range{
"DiagIndex in Eigen::Diagonal is too high for MatrixType."};
66 else if constexpr (constant_diagonal_matrix<MatrixType> and DiagIndex == Eigen::DynamicIndex)
69 else if (arg.index() > -arg.nestedExpression().rows() and arg.index() < arg.nestedExpression().cols())
return Scalar(0);
70 else throw std::out_of_range {
"Dynamic index for Eigen::Diagonal is out of range."};
72 else if constexpr (constant_matrix<MatrixType>>)
78 return std::monostate{};
83 template<Applicability b>
84 static constexpr
bool one_dimensional = dimension_size_of_index_is<Xpr, 0, 1, b>;
87 template<Applicability b>
88 static constexpr
bool is_square = one_dimensional<b>;
94 #endif //OPENKALMAN_EIGEN_TRAITS_DIAGONAL_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
typename scalar_type_of< T >::type scalar_type_of_t
helper template for scalar_type_of.
Definition: scalar_type_of.hpp:54
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
decltype(auto) constexpr nested_object(Arg &&arg)
Retrieve a nested object of Arg, if it exists.
Definition: nested_object.hpp:34