OpenKalman
TriangularView.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_TRIANGULARVIEW_HPP
17 #define OPENKALMAN_EIGEN_TRIANGULARVIEW_HPP
18 
19 #include <type_traits>
20 
21 
22 namespace OpenKalman
23 {
24  namespace interface
25  {
26  template<typename MatrixType, unsigned int Mode>
27  struct indexible_object_traits<Eigen::TriangularView<MatrixType, Mode>>
28  {
29  private:
30 
31  using Xpr = Eigen::TriangularView<MatrixType, Mode>;
32  using IndexType = typename MatrixType::Index;
33 
34  public:
35 
36  using scalar_type = scalar_type_of_t<MatrixType>;
37 
38 
39  template<typename Arg>
40  static constexpr auto count_indices(const Arg& arg) { return OpenKalman::count_indices(arg.nestedExpression()); }
41 
42 
43  template<typename Arg, typename N>
44  static constexpr auto get_vector_space_descriptor(const Arg& arg, N n)
45  {
46  return OpenKalman::get_vector_space_descriptor(arg.nestedExpression(), n);
47  }
48 
49 
50  template<typename Arg>
51  static decltype(auto) nested_object(Arg&& arg)
52  {
53  return std::forward<Arg>(arg).nestedExpression();
54  }
55 
56 
57  template<typename Arg>
58  static constexpr auto get_constant(const Arg& arg)
59  {
60  if constexpr (zero<MatrixType> or ((Mode & Eigen::ZeroDiag) != 0 and diagonal_matrix<MatrixType>))
62  else
63  return std::monostate{};
64  }
65 
66 
67  template<typename Arg>
68  static constexpr auto get_constant_diagonal(const Arg& arg)
69  {
70  using Scalar = scalar_type_of_t<MatrixType>;
71 
72  if constexpr ((Mode & Eigen::UnitDiag) != 0 and (
73  ((Mode & Eigen::Upper) != 0 and triangular_matrix<MatrixType, TriangleType::lower>) or
74  ((Mode & Eigen::Lower) != 0 and triangular_matrix<MatrixType, TriangleType::upper>)))
75  {
76  return values::Fixed<Scalar, 1>{};
77  }
78  else if constexpr ((Mode & Eigen::ZeroDiag) != 0 and (
79  ((Mode & Eigen::Upper) != 0 and triangular_matrix<MatrixType, TriangleType::lower>) or
80  ((Mode & Eigen::Lower) != 0 and triangular_matrix<MatrixType, TriangleType::upper>)))
81  {
82  return values::Fixed<Scalar, 0>{};
83  }
84  else
85  {
86  return constant_diagonal_coefficient {arg.nestedExpression()};
87  }
88  }
89 
90 
91  template<Applicability b>
92  static constexpr bool one_dimensional = OpenKalman::one_dimensional<MatrixType, b>;
93 
94 
95  template<Applicability b>
96  static constexpr bool is_square = square_shaped<MatrixType, b>;
97 
98 
99  template<TriangleType t>
100  static constexpr bool is_triangular =
101  (t == TriangleType::any) or
102  (t == TriangleType::lower and ((Mode & Eigen::Lower) != 0 or triangular_matrix<MatrixType, TriangleType::lower>)) or
103  (t == TriangleType::upper and ((Mode & Eigen::Upper) != 0 or triangular_matrix<MatrixType, TriangleType::upper>)) or
104  (t == TriangleType::diagonal and triangular_matrix<MatrixType, (Mode & Eigen::Lower) != 0 ? TriangleType::upper : TriangleType::lower>);
105 
106 
107  static constexpr bool is_triangular_adapter = true;
108 
109 
110  static constexpr bool is_hermitian = diagonal_matrix<MatrixType> and (not values::complex<scalar_type> or
112 
113  };
114 
115  } // namespace interface
116 
117 } // namespace OpenKalman
118 
119 #endif //OPENKALMAN_EIGEN_TRAITS_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
typename scalar_type_of< T >::type scalar_type_of_t
helper template for scalar_type_of.
Definition: scalar_type_of.hpp:54
Lower, upper, or diagonal matrix.
Definition: eigen-comma-initializers.hpp:20
constexpr bool not_complex
T is a values::value in which either its type is not a values::complex or its imaginary component is ...
Definition: not_complex.hpp:47
An upper-right triangular matrix.
constexpr bool triangular_matrix
Specifies that a type is a triangular matrix (upper, lower, or diagonal).
Definition: triangular_matrix.hpp:37
The constant associated with T, assuming T is a constant_matrix.
Definition: constant_coefficient.hpp:36
The root namespace for OpenKalman.
Definition: basics.hpp:34
The constant associated with T, assuming T is a constant_diagonal_matrix.
Definition: constant_diagonal_coefficient.hpp:32
Definition: Fixed.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
A lower-left triangular matrix.
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