OpenKalman
DiagonalWrapper.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-2023 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_DIAGONALWRAPPER_HPP
17 #define OPENKALMAN_EIGEN_TRAITS_DIAGONALWRAPPER_HPP
18 
19 #include <type_traits>
20 
21 
22 namespace OpenKalman::interface
23 {
24  template<typename DiagVectorType>
25  struct indexible_object_traits<Eigen::DiagonalWrapper<DiagVectorType>>
26  : Eigen3::indexible_object_traits_base<Eigen::DiagonalWrapper<DiagVectorType>>
27  {
28  private:
29 
30  using Xpr = Eigen::DiagonalWrapper<DiagVectorType>;
32 
33  public:
34 
35  template<typename Arg>
36  static constexpr auto
37  count_indices(const Arg& arg)
38  {
39  if constexpr (Arg::RowsAtCompileTime == 1 and Arg::ColsAtCompileTime == 1)
40  return std::integral_constant<std::size_t, 0_uz>{};
41  else
42  return std::integral_constant<std::size_t, 2_uz>{};
43  }
44 
45 
46  template<typename Arg, typename N>
47  static constexpr auto get_vector_space_descriptor(const Arg& arg, N)
48  {
49  if constexpr (has_dynamic_dimensions<DiagVectorType>) return static_cast<std::size_t>(arg.rows());
50  else return Dimensions<index_dimension_of_v<DiagVectorType, 0> * index_dimension_of_v<DiagVectorType, 1>>{};
51  }
52 
53 
54  template<typename Arg>
55  static decltype(auto) nested_object(Arg&& arg)
56  {
57  auto&& d = std::forward<Arg>(arg).diagonal();
58  using D = decltype(d);
59  using NCD = std::conditional_t<
60  std::is_const_v<std::remove_reference_t<Arg>> or std::is_const_v<DiagVectorType>,
61  D, std::conditional_t<std::is_lvalue_reference_v<D>, std::decay_t<D>&, std::decay_t<D>>>;
62  return const_cast<NCD>(std::forward<decltype(d)>(d));
63  }
64 
65 
66  template<typename Arg>
67  static constexpr auto get_constant_diagonal(const Arg& arg)
68  {
69  return constant_coefficient {arg.diagonal()};
70  }
71 
72 
73  template<Applicability b>
74  static constexpr bool one_dimensional = OpenKalman::one_dimensional<DiagVectorType, b>;
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  // is_hermitian not defined because matrix is diagonal;
88 
89  // make_hermitian_adapter(Arg&& arg) not defined
90 
91  };
92 
93 } // namespace OpenKalman::interface
94 
95 #endif //OPENKALMAN_EIGEN_TRAITS_DIAGONALWRAPPER_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
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
A diagonal matrix (both a lower-left and an upper-right triangular matrix).
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