OpenKalman
forward-class-declarations.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_FORWARD_CLASS_DECLARATIONS_HPP
17 #define OPENKALMAN_FORWARD_CLASS_DECLARATIONS_HPP
18 
19 #include "coordinates/coordinates.hpp"
20 
21 namespace OpenKalman
22 {
23  // ------------------------------------------ //
24  // diagonal_adapter, internal::diagonal_expr //
25  // ------------------------------------------ //
26 
34 #ifdef __cpp_concepts
35  template<vector<0, applicability::permitted> NestedMatrix>
36 #else
37  template<typename NestedMatrix>
38 #endif
39  struct diagonal_adapter;
40 
41 
42  namespace internal
43  {
44  namespace detail
45  {
46  template<typename T>
47  struct is_diagonal_expr : std::false_type {};
48 
49  template<typename NestedMatrix>
50  struct is_diagonal_expr<diagonal_adapter<NestedMatrix>> : std::true_type {};
51  }
52 
53 
57  template<typename T>
58 #ifdef __cpp_concepts
60 #else
61  constexpr bool diagonal_expr = detail::is_diagonal_expr<std::decay_t<T>>::value;
62 #endif
63  }
64 
65 
66  // -------------------------------------------- //
67  // HermitianAdapter, internal::hermitian_expr //
68  // -------------------------------------------- //
69 
83 #ifdef __cpp_concepts
84  template<square_shaped<applicability::permitted> NestedMatrix, HermitianAdapterType storage_triangle =
85  triangular_matrix<NestedMatrix, triangle_type::diagonal> ? HermitianAdapterType::lower :
86  triangular_matrix<NestedMatrix, triangle_type::upper> ? HermitianAdapterType::upper : HermitianAdapterType::lower> requires
87  (index_count_v<NestedMatrix> <= 2) and
88  (storage_triangle == HermitianAdapterType::lower or storage_triangle == HermitianAdapterType::upper) and
89  (not constant_matrix<NestedMatrix> or values::not_complex<constant_value<NestedMatrix>>) and
90  (not constant_diagonal_matrix<NestedMatrix> or values::not_complex<constant_diagonal_value<NestedMatrix>>) and
91  (not triangular_matrix<NestedMatrix, triangle_type::any> or triangular_matrix<NestedMatrix, static_cast<triangle_type>(storage_triangle)>)
92 #else
93  template<typename NestedMatrix, HermitianAdapterType storage_triangle =
94  triangular_matrix<NestedMatrix, triangle_type::diagonal> ? HermitianAdapterType::lower :
95  triangular_matrix<NestedMatrix, triangle_type::upper> ? HermitianAdapterType::upper : HermitianAdapterType::lower>
96 #endif
97  struct HermitianAdapter;
98 
99 
100  namespace internal
101  {
102  namespace detail
103  {
104  template<typename T>
105  struct is_hermitian_expr : std::false_type {};
106 
107  template<typename NestedMatrix, HermitianAdapterType storage_triangle>
108  struct is_hermitian_expr<HermitianAdapter<NestedMatrix, storage_triangle>> : std::true_type {};
109  }
110 
111 
115  template<typename T>
116 #ifdef __cpp_concepts
118 #else
119  constexpr bool hermitian_expr = detail::is_hermitian_expr<std::decay_t<T>>::value;
120 #endif
121  }
122 
123 
124  // ---------------------------------------------- //
125  // TriangularAdapter, internal::triangular_expr //
126  // ---------------------------------------------- //
127 
137 #ifdef __cpp_concepts
138  template<
139  square_shaped<applicability::permitted> NestedMatrix,
140  triangle_type tri = (diagonal_matrix<NestedMatrix> ? triangle_type::diagonal :
141  (triangular_matrix<NestedMatrix, triangle_type::upper> ? triangle_type::upper : triangle_type::lower))>
142  requires (index_count_v<NestedMatrix> <= 2)
143 #else
144  template<typename NestedMatrix, triangle_type tri = (diagonal_matrix<NestedMatrix> ? triangle_type::diagonal :
145  (triangular_matrix<NestedMatrix, triangle_type::upper> ? triangle_type::upper : triangle_type::lower))>
146 #endif
148 
149 
150  namespace internal
151  {
152  namespace detail
153  {
154  template<typename T>
155  struct is_triangular_expr : std::false_type {};
156 
157  template<typename NestedMatrix, triangle_type tri>
158  struct is_triangular_expr<TriangularAdapter<NestedMatrix, tri>> : std::true_type {};
159  }
160 
161 
165  template<typename T>
166 #ifdef __cpp_concepts
168 #else
169  constexpr bool triangular_expr = detail::is_triangular_expr<std::decay_t<T>>::value;
170 #endif
171  }
172 
173 
174  // -------------------------------------------------------- //
175  // FromEuclideanExpr, from_euclidean_expr, euclidean_expr //
176  // -------------------------------------------------------- //
177 
184 #ifdef __cpp_concepts
185  template<indexible NestedObject, coordinates::pattern RowDescriptor> requires
186  compares_with<vector_space_descriptor_of<NestedObject, 0>, coordinates::Dimensions<coordinates::stat_dimension_of_v<RowDescriptor>>, equal_to<>, applicability::permitted>
187 #else
188  template<typename NestedMatrix, typename RowDescriptor>
189 #endif
190  struct FromEuclideanExpr;
191 
192 
193  namespace detail
194  {
195  template<typename T>
196  struct is_from_euclidean_expr : std::false_type {};
197 
198  template<typename NestedMatrix, typename D>
199  struct is_from_euclidean_expr<FromEuclideanExpr<NestedMatrix, D>> : std::true_type {};
200  }
201 
202 
206  template<typename T>
207 #ifdef __cpp_concepts
209 #else
210  constexpr bool from_euclidean_expr = detail::is_from_euclidean_expr<std::decay_t<T>>::value;
211 #endif
212 
213 
214  // ------------------------------------ //
215  // ToEuclideanExpr, to_euclidean_expr //
216  // ------------------------------------ //
217 
223 #ifdef __cpp_concepts
224  template<indexible NestedObject> requires (not from_euclidean_expr<NestedObject>)
225 #else
226  template<typename NestedObject>
227 #endif
229 
230 
231  namespace detail
232  {
233  template<typename T>
234  struct is_to_euclidean_expr : std::false_type {};
235 
236  template<typename NestedObject>
237  struct is_to_euclidean_expr<ToEuclideanExpr<NestedObject>> : std::true_type {};
238  }
239 
240 
244  template<typename T>
245 #ifdef __cpp_concepts
247 #else
248  constexpr bool to_euclidean_expr = detail::is_to_euclidean_expr<std::decay_t<T>>::value;
249 #endif
250 
251 
255  template<typename T>
256 #ifdef __cpp_concepts
257  concept euclidean_expr = to_euclidean_expr<T> or from_euclidean_expr<T>;
258 #else
259  constexpr bool euclidean_expr = from_euclidean_expr<T> or to_euclidean_expr<T>;
260 #endif
261 
262 
263  // --------------------- //
264  // Deprecated adapters //
265  // --------------------- //
266 
282 #ifdef __cpp_concepts
283  template<fixed_pattern RowCoefficients, fixed_pattern ColumnCoefficients, typed_matrix_nestable NestedMatrix>
284  requires (coordinates::dimension_of_v<RowCoefficients> == index_dimension_of_v<NestedMatrix, 0>) and
285  (coordinates::dimension_of_v<ColumnCoefficients> == index_dimension_of_v<NestedMatrix, 1>) and
286  (not std::is_rvalue_reference_v<NestedMatrix>) and
287  (dynamic_pattern<RowCoefficients> == dynamic_dimension<NestedMatrix, 0>) and
288  (dynamic_pattern<ColumnCoefficients> == dynamic_dimension<NestedMatrix, 1>)
289 #else
290  template<typename RowCoefficients, typename ColumnCoefficients, typename NestedMatrix>
291 #endif
292  struct Matrix;
293 
294 
295  namespace internal
296  {
297  template<typename RowCoefficients, typename ColumnCoefficients, typename NestedMatrix>
298  struct is_matrix<Matrix<RowCoefficients, ColumnCoefficients, NestedMatrix>> : std::true_type {};
299  }
300 
301 
314 #ifdef __cpp_concepts
315  template<fixed_pattern Descriptor, typed_matrix_nestable NestedMatrix> requires
316  (coordinates::dimension_of_v<Descriptor> == index_dimension_of_v<NestedMatrix, 0>) and
317  (not std::is_rvalue_reference_v<NestedMatrix>)
318 #else
319  template<typename Descriptor, typename NestedMatrix>
320 #endif
321  struct Mean;
322 
323 
324  namespace internal
325  {
326  template<typename Descriptor, typename NestedMatrix>
327  struct is_mean<Mean<Descriptor, NestedMatrix>> : std::true_type {};
328  }
329 
330 
343 #ifdef __cpp_concepts
344  template<fixed_pattern Descriptor, typed_matrix_nestable NestedMatrix> requires
345  (coordinates::stat_dimension_of_v<Descriptor> == index_dimension_of_v<NestedMatrix, 0>) and (not std::is_rvalue_reference_v<NestedMatrix>)
346 #else
347  template<typename Descriptor, typename NestedMatrix>
348 #endif
349  struct EuclideanMean;
350 
351 
352  namespace internal
353  {
354  template<typename Descriptor, typename NestedMatrix>
355  struct is_euclidean_mean<EuclideanMean<Descriptor, NestedMatrix>> : std::true_type {};
356  }
357 
358 
368 #ifdef __cpp_concepts
369  template<fixed_pattern Descriptor, covariance_nestable NestedMatrix> requires
370  (coordinates::dimension_of_v<Descriptor> == index_dimension_of_v<NestedMatrix, 0>) and
371  (not std::is_rvalue_reference_v<NestedMatrix>) and values::number<scalar_type_of_t<NestedMatrix>>
372 #else
373  template<typename Descriptor, typename NestedMatrix>
374 #endif
375  struct Covariance;
376 
377 
378  namespace internal
379  {
380  template<typename Descriptor, typename NestedMatrix>
381  struct is_self_adjoint_covariance<Covariance<Descriptor, NestedMatrix>> : std::true_type {};
382  }
383 
384 
396 #ifdef __cpp_concepts
397  template<fixed_pattern Descriptor, covariance_nestable NestedMatrix> requires
398  (coordinates::dimension_of_v<Descriptor> == index_dimension_of_v<NestedMatrix, 0>) and
399  (not std::is_rvalue_reference_v<NestedMatrix>) and values::number<scalar_type_of_t<NestedMatrix>>
400 #else
401  template<typename Descriptor, typename NestedMatrix>
402 #endif
404 
405 
406  // ------------------- //
407  // Internal adapters //
408  // ------------------- //
409 
410  namespace internal
411  {
419  #ifdef __cpp_concepts
420  template<indexible NestedObject, indexible LibraryObject>
421  #else
422  template<typename NestedObject, typename LibraryObject>
423  #endif
425 
426 
427  namespace detail
428  {
429  template<typename T>
430  struct is_library_wrapper : std::false_type {};
431 
432  template<typename N, typename L>
433  struct is_library_wrapper<internal::LibraryWrapper<N, L>> : std::true_type {};
434  }
435 
436 
441  template<typename T>
442 #ifdef __cpp_concepts
443  concept library_wrapper =
444 #else
445  constexpr bool library_wrapper =
446 #endif
448 
449 
457  #ifdef __cpp_concepts
458  template<indexible NestedObject, pattern_collection Descriptors> requires
459  compatible_with_vector_space_descriptor_collection<NestedObject, Descriptors> and
460  internal::not_more_fixed_than<NestedObject, Descriptors> and internal::less_fixed_than<NestedObject, Descriptors>
461  #else
462  template<typename NestedObject, typename Descriptors>
463  #endif
464  struct FixedSizeAdapter;
465 
466 
467  namespace detail
468  {
469  template<typename T>
470  struct is_fixed_size_adapter : std::false_type {};
471 
472  template<typename NestedMatrix, typename Descriptors>
473  struct is_fixed_size_adapter<FixedSizeAdapter<NestedMatrix, Descriptors>> : std::true_type {};
474  }
475 
476 
481  template<typename T>
482 #ifdef __cpp_concepts
483  concept fixed_size_adapter =
484 #else
485  constexpr bool fixed_size_adapter =
486 #endif
488 
489 
490  template<typename Descriptor, typename NestedMatrix>
491  struct is_triangular_covariance<SquareRootCovariance<Descriptor, NestedMatrix>> : std::true_type {};
492 
493  }
494 
495 
504 #ifdef __cpp_concepts
505  template<
506  fixed_pattern Descriptor,
507  typed_matrix_nestable MeanNestedMatrix,
508  covariance_nestable CovarianceNestedMatrix,
509  std::uniform_random_bit_generator random_number_engine = std::mt19937> requires
510  (index_dimension_of_v<MeanNestedMatrix, 0> == index_dimension_of_v<CovarianceNestedMatrix, 0>) and
511  (index_dimension_of_v<MeanNestedMatrix, 1> == 1) and
512  (std::is_same_v<scalar_type_of_t<MeanNestedMatrix>,
513  scalar_type_of_t<CovarianceNestedMatrix>>)
514 #else
515  template<
516  typename Descriptor,
517  typename MeanNestedMatrix,
518  typename CovarianceNestedMatrix,
519  typename random_number_engine = std::mt19937>
520 #endif
521  struct GaussianDistribution;
522 
523 
524  namespace internal
525  {
526  template<typename Descriptor, typename MeanNestedMatrix, typename CovarianceNestedMatrix, typename re>
527  struct is_gaussian_distribution<GaussianDistribution<Descriptor, MeanNestedMatrix, CovarianceNestedMatrix, re>>
528  : std::true_type {};
529  }
530 
531 } // OpenKalman
532 
533 #endif
A hermitian matrix wrapper.
Definition: HermitianAdapter.hpp:33
triangle_type
The type of a triangular matrix.
Definition: enumerations.hpp:26
Definition: forward-class-declarations.hpp:47
constexpr bool to_euclidean_expr
Specifies that T is an expression converting coefficients to Euclidean space (i.e., ToEuclideanExpr).
Definition: forward-class-declarations.hpp:248
An expression that transforms angular or other modular vector space descriptors back from Euclidean s...
Definition: FromEuclideanExpr.hpp:29
constexpr bool euclidean_expr
Specifies that T is either to_euclidean_expr or from_euclidean_expr.
Definition: forward-class-declarations.hpp:259
A set of one or more column vectors, each representing a statistical mean.
Definition: forward-class-declarations.hpp:321
A lower-left triangular matrix.
The concept, trait, or restraint is permitted, but whether it applies is not necessarily known at com...
A triangular_adapter, where components above or below the diagonal (or both) are zero.
Definition: forward-class-declarations.hpp:147
HermitianAdapterType
The type of a hermitian adapter, indicating which triangle of the nested matrix is used...
Definition: enumerations.hpp:79
constexpr bool not_complex
T is a value in which either its type is not complex or its imaginary component is 0...
Definition: not_complex.hpp:48
Definition: forward-class-declarations.hpp:155
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
A diagonal matrix (both a lower-left and an upper-right triangular matrix).
Definition: object-types.hpp:121
Definition: object-types.hpp:29
diagonal_adapter(Arg &&) -> diagonal_adapter< Arg >
Deduce diagonal_adapter NestedObject from its constructor argument.
Definition: forward-class-declarations.hpp:430
constexpr bool triangular_matrix
Specifies that an argument is an indexible object having a given triangle_type (e.g., upper, lower, or diagonal).
Definition: triangular_matrix.hpp:36
Definition: object-types.hpp:172
Definition: object-types.hpp:64
constexpr bool hermitian_expr
Specifies that T is a self-adjoint matrix based on the Eigen library (i.e., HermitianAdapter).
Definition: forward-class-declarations.hpp:119
Lower, upper, or diagonal matrix.
The upper or lower triangle Cholesky factor (square root) of a covariance matrix. ...
Definition: forward-class-declarations.hpp:403
A Gaussian distribution, defined in terms of a Mean and a Covariance.
Definition: GaussianDistribution.hpp:42
constexpr bool typed_matrix_nestable
Specifies a type that is nestable in a general typed matrix (e.g., matrix, mean, or euclidean_mean) ...
Definition: object-types.hpp:253
Similar to a Mean, but the coefficients are transformed into Euclidean space, based on their type...
Definition: EuclideanMean.hpp:29
The root namespace for OpenKalman.
Definition: basics.hpp:34
An adapter for creating a diagonal matrix or tensor.
Definition: diagonal_adapter.hpp:27
constexpr bool from_euclidean_expr
Specifies that T is an expression converting coefficients from Euclidean space (i.e., FromEuclideanExpr).
Definition: forward-class-declarations.hpp:210
constexpr bool fixed_pattern
A coordinates::pattern for which the dimension is fixed at compile time.
Definition: fixed_pattern.hpp:46
An expression that transforms vector space descriptors into Euclidean space for application of direct...
Definition: forward-class-declarations.hpp:228
constexpr bool diagonal_expr
Specifies that T is a diagonal matrix based on the Eigen library (i.e., DiaginalMatrix).
Definition: forward-class-declarations.hpp:61
Definition: forward-class-declarations.hpp:105
Definition: FixedSizeAdapter.hpp:30
An upper-right triangular matrix.
Definition: forward-class-declarations.hpp:470
constexpr auto constant_value(T &&t)
The constant value associated with a constant_object or constant_diagonal_object. ...
Definition: constant_value.hpp:37
A structure representing the dimensions associated with of a particular index.
Definition: Dimensions.hpp:42
A self-adjoint Covariance matrix.
Definition: Covariance.hpp:30
constexpr bool triangular_expr
Specifies that T is a triangular matrix based on the Eigen library (i.e., TriangularAdapter).
Definition: forward-class-declarations.hpp:169
Definition: forward-class-declarations.hpp:196
Definition: forward-class-declarations.hpp:234
constexpr bool covariance_nestable
T is an acceptable nested matrix for a covariance (including triangular_covariance).
Definition: object-types.hpp:237
Definition: object-types.hpp:139
Definition: forward-class-declarations.hpp:424
Definition: object-types.hpp:99
A matrix with typed rows and columns.
Definition: forward-class-declarations.hpp:292