OpenKalman
Select.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_SELECT_HPP
17 #define OPENKALMAN_EIGEN_TRAITS_SELECT_HPP
18 
19 #include <type_traits>
20 
21 
22 namespace OpenKalman::interface
23 {
24  template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType>
25  struct indexible_object_traits<Eigen::Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType>>
26  : Eigen3::indexible_object_traits_base<Eigen::Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType>>
27  {
28  private:
29 
30  using Xpr = Eigen::Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType>;
32 
33  public:
34 
35  template<typename Arg, typename N>
36  static constexpr auto get_vector_space_descriptor(const Arg& arg, N n)
37  {
38  if constexpr (square_shaped<ConditionMatrixType> or square_shaped<ThenMatrixType> or square_shaped<ElseMatrixType>)
39  return internal::best_vector_space_descriptor(
40  OpenKalman::get_vector_space_descriptor<0>(arg.conditionMatrix()),
41  OpenKalman::get_vector_space_descriptor<0>(arg.thenMatrix()),
42  OpenKalman::get_vector_space_descriptor<0>(arg.elseMatrix()),
43  OpenKalman::get_vector_space_descriptor<1>(arg.conditionMatrix()),
44  OpenKalman::get_vector_space_descriptor<1>(arg.thenMatrix()),
45  OpenKalman::get_vector_space_descriptor<1>(arg.elseMatrix()));
46  else
47  return internal::best_vector_space_descriptor(
48  OpenKalman::get_vector_space_descriptor(arg.conditionMatrix(), n),
49  OpenKalman::get_vector_space_descriptor(arg.thenMatrix(), n),
50  OpenKalman::get_vector_space_descriptor(arg.elseMatrix(), n));
51  }
52 
53 
54  // nested_object not defined
55 
56 
57  template<typename Arg>
58  static constexpr auto get_constant(const Arg& arg)
59  {
60  if constexpr (constant_matrix<ConditionMatrixType>)
61  {
62  if constexpr (static_cast<bool>(constant_coefficient_v<ConditionMatrixType>))
63  return constant_coefficient{arg.thenMatrix()};
64  else
65  return constant_coefficient{arg.elseMatrix()};
66  }
67  else if constexpr (constant_matrix<ThenMatrixType> and constant_matrix<ElseMatrixType>)
68  {
69  if constexpr (constant_coefficient_v<ThenMatrixType> == constant_coefficient_v<ElseMatrixType>)
70  return constant_coefficient{arg.thenMatrix()};
71  else return std::monostate{};
72  }
73  else return std::monostate{};
74  }
75 
76 
77  template<typename Arg>
78  static constexpr auto get_constant_diagonal(const Arg& arg)
79  {
80  if constexpr (constant_matrix<ConditionMatrixType>)
81  {
82  if constexpr (static_cast<bool>(constant_coefficient_v<ConditionMatrixType>))
83  return constant_diagonal_coefficient{arg.thenMatrix()};
84  else
85  return constant_diagonal_coefficient{arg.elseMatrix()};
86  }
87  else if constexpr (constant_diagonal_matrix<ThenMatrixType> and constant_diagonal_matrix<ElseMatrixType>)
88  {
89  if constexpr (constant_diagonal_coefficient_v<ThenMatrixType> == constant_diagonal_coefficient_v<ElseMatrixType>)
90  return constant_diagonal_coefficient{arg.thenMatrix()};
91  else return std::monostate{};
92  }
93  else return std::monostate{};
94  }
95 
96 
97  template<Applicability b>
98  static constexpr bool one_dimensional =
99  OpenKalman::one_dimensional<ConditionMatrixType, Applicability::permitted> and
100  OpenKalman::one_dimensional<ThenMatrixType, Applicability::permitted> and
101  OpenKalman::one_dimensional<ElseMatrixType, Applicability::permitted> and
103  not has_dynamic_dimensions<Xpr> or
104  OpenKalman::one_dimensional<ConditionMatrixType> or
105  OpenKalman::one_dimensional<ThenMatrixType> or
106  OpenKalman::one_dimensional<ElseMatrixType>);
107 
108 
109  template<Applicability b>
110  static constexpr bool is_square =
111  square_shaped<ConditionMatrixType, Applicability::permitted> and
112  square_shaped<ThenMatrixType, Applicability::permitted> and
113  square_shaped<ElseMatrixType, Applicability::permitted> and
115  not has_dynamic_dimensions<Xpr> or
116  square_shaped<ConditionMatrixType, b> or
117  square_shaped<ThenMatrixType, b> or
118  square_shaped<ElseMatrixType, b>);
119 
120 
121  template<TriangleType t>
122  static constexpr bool is_triangular =
123  [](){
124  if constexpr (constant_matrix<ConditionMatrixType>)
125  return triangular_matrix<std::conditional_t<static_cast<bool>(constant_coefficient_v<ConditionMatrixType>),
126  ThenMatrixType, ElseMatrixType>, t>;
127  else return false;
128  }();
129 
130 
131  static constexpr bool is_triangular_adapter = false;
132 
133 
134  static constexpr bool is_hermitian =
135  (values::fixed<constant_coefficient<ConditionMatrixType>> and
136  [](){
137  if constexpr (constant_matrix<ConditionMatrixType>)
138  return hermitian_matrix<std::conditional_t<static_cast<bool>(constant_coefficient_v<ConditionMatrixType>),
139  ThenMatrixType, ElseMatrixType>, Applicability::permitted>;
140  else return false;
141  }()) or
142  (hermitian_matrix<ConditionMatrixType, Applicability::permitted> and hermitian_matrix<ThenMatrixType, Applicability::permitted> and
143  hermitian_matrix<ElseMatrixType, Applicability::permitted> and
145  };
146 
147 
148 } // namespace OpenKalman::interface
149 
150 #endif //OPENKALMAN_EIGEN_TRAITS_SELECT_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 concept, trait, or restraint is permitted, but whether it applies is not necessarily known at com...
The constant associated with T, assuming T is a constant_diagonal_matrix.
Definition: constant_diagonal_coefficient.hpp:32
constexpr bool fixed
T is a values::value that is determinable at compile time.
Definition: fixed.hpp:60
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