OpenKalman
DiagonalMatrix.hpp
Go to the documentation of this file.
1 /* This file is part of OpenKalman, a header-only C++ library for
2  * Kalman filters and other recursive filters.
3  *
4  * Copyright (c) 2019-2024 Christopher Lee Ogden <ogden@gatech.edu>
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
9  */
10 
16 #ifndef OPENKALMAN_EIGEN_TRAITS_DIAGONALMATRIX_HPP
17 #define OPENKALMAN_EIGEN_TRAITS_DIAGONALMATRIX_HPP
18 
19 #include <type_traits>
20 
21 
22 namespace OpenKalman
23 {
24  namespace interface
25  {
26  template<typename Scalar, int SizeAtCompileTime, int MaxSizeAtCompileTime>
27  struct indexible_object_traits<Eigen::DiagonalMatrix<Scalar, SizeAtCompileTime, MaxSizeAtCompileTime>>
28  : Eigen3::indexible_object_traits_base<Eigen::DiagonalMatrix<Scalar, SizeAtCompileTime, MaxSizeAtCompileTime>>
29  {
30  private:
31 
32  using Xpr = Eigen::DiagonalMatrix<Scalar, SizeAtCompileTime, MaxSizeAtCompileTime>;
34 
35  public:
36 
37  template<typename Arg>
38  static constexpr auto
39  count_indices(const Arg& arg)
40  {
41  if constexpr (SizeAtCompileTime == 1)
42  return std::integral_constant<std::size_t, 0_uz>{};
43  else
44  return std::integral_constant<std::size_t, 2_uz>{};
45  }
46 
47 
48  template<typename Arg, typename N>
49  static constexpr auto get_vector_space_descriptor(const Arg& arg, N)
50  {
51  if constexpr (SizeAtCompileTime == Eigen::Dynamic) return static_cast<std::size_t>(arg.rows());
52  else return Dimensions<SizeAtCompileTime>{};
53  }
54 
55 
56  template<typename Arg>
57  static decltype(auto) nested_object(Arg&& arg)
58  {
59  // Note, early Eigen versions, at least, do not have rvalue-qualified "diagonal()" member functions.
60  if constexpr (std::is_rvalue_reference_v<Arg&&>)
61  return std::move(arg.diagonal());
62  else
63  return arg.diagonal();
64  }
65 
66 
67  // get_constant() not defined
68 
69 
70  // get_constant_diagonal() not defined
71 
72 
73  template<Applicability b>
74  static constexpr bool one_dimensional = SizeAtCompileTime == 1 or (SizeAtCompileTime == Eigen::Dynamic and b == Applicability::permitted);
75 
76 
77  template<Applicability b>
78  static constexpr bool is_square = true;
79 
80 
81  template<TriangleType t>
82  static constexpr bool is_triangular = true;
83 
84 
85  static constexpr bool is_triangular_adapter = false;
86 
87 
88  // is_hermitian not defined because matrix is diagonal;
89 
90 
91  // make_hermitian_adapter(Arg&& arg) not defined
92 
93  };
94 
95  } // namespace interface
96 
97 } // namespace OpenKalman
98 
99 #endif //OPENKALMAN_EIGEN_TRAITS_DIAGONALMATRIX_HPP
constexpr auto count_indices(const T &t)
Get the number of indices available to address the components of an indexible object.
Definition: count_indices.hpp:33
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
Trait object providing get and set routines.
Definition: eigen-forward-declarations.hpp:502
Definition: eigen-comma-initializers.hpp:20
The root namespace for OpenKalman.
Definition: basics.hpp:34
The concept, trait, or restraint is permitted, but whether it applies is not necessarily known at com...
decltype(auto) constexpr nested_object(Arg &&arg)
Retrieve a nested object of Arg, if it exists.
Definition: nested_object.hpp:34
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