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 <type_traits>
20 #include <random>
21 #include "basics/traits/traits.hpp"
22 
23 namespace OpenKalman
24 {
25  // ----------------- //
26  // ConstantAdapter //
27  // ----------------- //
28 
48 #ifdef __cpp_concepts
49  template<indexible PatternMatrix, values::scalar Scalar = scalar_type_of_t<PatternMatrix>, auto...constant>
50  requires (sizeof...(constant) == 0) or requires { Scalar {constant...}; }
51 #else
52  template<typename PatternMatrix, typename Scalar = scalar_type_of_t<PatternMatrix>, auto...constant>
53 #endif
54  struct ConstantAdapter;
55 
56 
57  // ------------------ //
58  // constant_adapter //
59  // ------------------ //
60 
61  namespace detail
62  {
63  template<typename T>
64  struct is_constant_adapter : std::false_type {};
65 
66  template<typename PatternMatrix, typename Scalar, auto...constant>
67  struct is_constant_adapter<ConstantAdapter<PatternMatrix, Scalar, constant...>> : std::true_type {};
68  }
69 
70 
74  template<typename T>
75 #ifdef __cpp_concepts
77 #else
78  constexpr bool constant_adapter = detail::is_constant_adapter<std::decay_t<T>>::value;
79 #endif
80 
81 
82  // ------------- //
83  // ZeroAdapter //
84  // ------------- //
85 
90 #ifdef __cpp_concepts
91  template<indexible PatternObject, values::number Scalar = scalar_type_of_t<PatternObject>>
92 #else
93  template<typename PatternObject, typename Scalar = scalar_type_of_t<PatternObject>>
94 #endif
96 
97 
98  // ---------------------------------------- //
99  // pattern_matrix_of, pattern_matrix_of_t //
100  // ---------------------------------------- //
101 
106 #ifdef __cpp_concepts
107  template<typename T>
108 #else
109  template<typename T, typename = void>
110 #endif
112 
113  template<typename PatternMatrix, typename Scalar, auto...constant>
114  struct pattern_matrix_of<ConstantAdapter<PatternMatrix, Scalar, constant...>> { using type = PatternMatrix; };
115 
116 
117 #ifdef __cpp_concepts
118  template<has_nested_object T>
119  struct pattern_matrix_of<T> { using type = nested_object_of_t<T>; };
120 #else
121  template<typename T>
122  struct pattern_matrix_of<T, std::enable_if_t<has_nested_object<T>>> { using type = nested_object_of_t<T>; };
123 #endif
124 
125 
129  template<typename T>
131 
132 
133  // ------------------------------------------ //
134  // DiagonalAdapter, internal::diagonal_expr //
135  // ------------------------------------------ //
136 
144 #ifdef __cpp_concepts
145  template<vector<0, Applicability::permitted> NestedMatrix>
146 #else
147  template<typename NestedMatrix>
148 #endif
149  struct DiagonalAdapter;
150 
151 
152  namespace internal
153  {
154  namespace detail
155  {
156  template<typename T>
157  struct is_diagonal_expr : std::false_type {};
158 
159  template<typename NestedMatrix>
160  struct is_diagonal_expr<DiagonalAdapter<NestedMatrix>> : std::true_type {};
161  }
162 
163 
167  template<typename T>
168 #ifdef __cpp_concepts
170 #else
171  constexpr bool diagonal_expr = detail::is_diagonal_expr<std::decay_t<T>>::value;
172 #endif
173  } // namespace internal
174 
175 
176  // -------------------------------------------- //
177  // HermitianAdapter, internal::hermitian_expr //
178  // -------------------------------------------- //
179 
193 #ifdef __cpp_concepts
194  template<square_shaped<Applicability::permitted> NestedMatrix, HermitianAdapterType storage_triangle =
195  triangular_matrix<NestedMatrix, TriangleType::diagonal> ? HermitianAdapterType::lower :
196  triangular_matrix<NestedMatrix, TriangleType::upper> ? HermitianAdapterType::upper : HermitianAdapterType::lower> requires
197  (index_count_v<NestedMatrix> <= 2) and
198  (storage_triangle == HermitianAdapterType::lower or storage_triangle == HermitianAdapterType::upper) and
199  (not constant_matrix<NestedMatrix> or values::not_complex<constant_coefficient<NestedMatrix>>) and
200  (not constant_diagonal_matrix<NestedMatrix> or values::not_complex<constant_diagonal_coefficient<NestedMatrix>>) and
201  (not triangular_matrix<NestedMatrix, TriangleType::any> or triangular_matrix<NestedMatrix, static_cast<TriangleType>(storage_triangle)>)
202 #else
203  template<typename NestedMatrix, HermitianAdapterType storage_triangle =
204  triangular_matrix<NestedMatrix, TriangleType::diagonal> ? HermitianAdapterType::lower :
205  triangular_matrix<NestedMatrix, TriangleType::upper> ? HermitianAdapterType::upper : HermitianAdapterType::lower>
206 #endif
207  struct HermitianAdapter;
208 
209 
210  namespace internal
211  {
212  namespace detail
213  {
214  template<typename T>
215  struct is_hermitian_expr : std::false_type {};
216 
217  template<typename NestedMatrix, HermitianAdapterType storage_triangle>
218  struct is_hermitian_expr<HermitianAdapter<NestedMatrix, storage_triangle>> : std::true_type {};
219  }
220 
221 
225  template<typename T>
226 #ifdef __cpp_concepts
228 #else
229  constexpr bool hermitian_expr = detail::is_hermitian_expr<std::decay_t<T>>::value;
230 #endif
231  } // namespace internal
232 
233 
234  // ---------------------------------------------- //
235  // TriangularAdapter, internal::triangular_expr //
236  // ---------------------------------------------- //
237 
247 #ifdef __cpp_concepts
248  template<
249  square_shaped<Applicability::permitted> NestedMatrix,
250  TriangleType triangle_type = (diagonal_matrix<NestedMatrix> ? TriangleType::diagonal :
251  (triangular_matrix<NestedMatrix, TriangleType::upper> ? TriangleType::upper : TriangleType::lower))>
252  requires (index_count_v<NestedMatrix> <= 2)
253 #else
254  template<typename NestedMatrix, TriangleType triangle_type = (diagonal_matrix<NestedMatrix> ? TriangleType::diagonal :
255  (triangular_matrix<NestedMatrix, TriangleType::upper> ? TriangleType::upper : TriangleType::lower))>
256 #endif
258 
259 
260  namespace internal
261  {
262  namespace detail
263  {
264  template<typename T>
265  struct is_triangular_expr : std::false_type {};
266 
267  template<typename NestedMatrix, TriangleType triangle_type>
268  struct is_triangular_expr<TriangularAdapter<NestedMatrix, triangle_type>> : std::true_type {};
269  }
270 
271 
275  template<typename T>
276 #ifdef __cpp_concepts
278 #else
279  constexpr bool triangular_expr = detail::is_triangular_expr<std::decay_t<T>>::value;
280 #endif
281  }
282 
283 
284  // ------------------------------------------ //
285  // VectorSpaceAdapter; vector_space_adapter //
286  // ------------------------------------------ //
287 
294 #ifdef __cpp_concepts
295  template<indexible NestedObject, pattern_collection Descriptors>
296  requires internal::not_more_fixed_than<NestedObject, Descriptors> and (not internal::less_fixed_than<NestedObject, Descriptors>) and
297  internal::maybe_same_shape_as_vector_space_descriptors<NestedObject, Descriptors>
298 #else
299  template<typename NestedObject, typename Descriptors>
300 #endif
302 
303  namespace internal
304  {
305  namespace detail
306  {
307  template<typename T>
308  struct is_vector_space_adapter : std::false_type {};
309 
310  template<typename NestedObject, typename Descriptors>
311  struct is_vector_space_adapter<VectorSpaceAdapter<NestedObject, Descriptors>> : std::true_type {};
312  } // namespace detail
313 
314 
319  template<typename T>
320 #ifdef __cpp_concepts
321  concept vector_space_adapter =
322 #else
323  constexpr bool vector_space_adapter =
324 #endif
326 
327  } // namespace internal
328 
329 
330  // -------------------------------------------------------- //
331  // FromEuclideanExpr, from_euclidean_expr, euclidean_expr //
332  // -------------------------------------------------------- //
333 
340 #ifdef __cpp_concepts
341  template<indexible NestedObject, coordinates::pattern RowDescriptor> requires
342  compares_with<vector_space_descriptor_of<NestedObject, 0>, coordinates::Dimensions<coordinates::stat_dimension_of_v<RowDescriptor>>, equal_to<>, Applicability::permitted>
343 #else
344  template<typename NestedMatrix, typename RowDescriptor>
345 #endif
346  struct FromEuclideanExpr;
347 
348 
349  namespace detail
350  {
351  template<typename T>
352  struct is_from_euclidean_expr : std::false_type {};
353 
354  template<typename NestedMatrix, typename D>
355  struct is_from_euclidean_expr<FromEuclideanExpr<NestedMatrix, D>> : std::true_type {};
356  }
357 
358 
362  template<typename T>
363 #ifdef __cpp_concepts
365 #else
366  constexpr bool from_euclidean_expr = detail::is_from_euclidean_expr<std::decay_t<T>>::value;
367 #endif
368 
369 
370  // ------------------------------------ //
371  // ToEuclideanExpr, to_euclidean_expr //
372  // ------------------------------------ //
373 
379 #ifdef __cpp_concepts
380  template<indexible NestedObject> requires (not from_euclidean_expr<NestedObject>)
381 #else
382  template<typename NestedObject>
383 #endif
385 
386 
387  namespace detail
388  {
389  template<typename T>
390  struct is_to_euclidean_expr : std::false_type {};
391 
392  template<typename NestedObject>
393  struct is_to_euclidean_expr<ToEuclideanExpr<NestedObject>> : std::true_type {};
394  }
395 
396 
400  template<typename T>
401 #ifdef __cpp_concepts
403 #else
404  constexpr bool to_euclidean_expr = detail::is_to_euclidean_expr<std::decay_t<T>>::value;
405 #endif
406 
407 
411  template<typename T>
412 #ifdef __cpp_concepts
413  concept euclidean_expr = to_euclidean_expr<T> or from_euclidean_expr<T>;
414 #else
415  constexpr bool euclidean_expr = from_euclidean_expr<T> or to_euclidean_expr<T>;
416 #endif
417 
418 
419  // --------------------- //
420  // Deprecated adapters //
421  // --------------------- //
422 
438 #ifdef __cpp_concepts
439  template<fixed_pattern RowCoefficients, fixed_pattern ColumnCoefficients, typed_matrix_nestable NestedMatrix>
440  requires (coordinates::dimension_of_v<RowCoefficients> == index_dimension_of_v<NestedMatrix, 0>) and
441  (coordinates::dimension_of_v<ColumnCoefficients> == index_dimension_of_v<NestedMatrix, 1>) and
442  (not std::is_rvalue_reference_v<NestedMatrix>) and
443  (dynamic_pattern<RowCoefficients> == dynamic_dimension<NestedMatrix, 0>) and
444  (dynamic_pattern<ColumnCoefficients> == dynamic_dimension<NestedMatrix, 1>)
445 #else
446  template<typename RowCoefficients, typename ColumnCoefficients, typename NestedMatrix>
447 #endif
448  struct Matrix;
449 
450 
451  namespace internal
452  {
453  template<typename RowCoefficients, typename ColumnCoefficients, typename NestedMatrix>
454  struct is_matrix<Matrix<RowCoefficients, ColumnCoefficients, NestedMatrix>> : std::true_type {};
455  }
456 
457 
470 #ifdef __cpp_concepts
471  template<fixed_pattern Descriptor, typed_matrix_nestable NestedMatrix> requires
472  (coordinates::dimension_of_v<Descriptor> == index_dimension_of_v<NestedMatrix, 0>) and
473  (not std::is_rvalue_reference_v<NestedMatrix>)
474 #else
475  template<typename Descriptor, typename NestedMatrix>
476 #endif
477  struct Mean;
478 
479 
480  namespace internal
481  {
482  template<typename Descriptor, typename NestedMatrix>
483  struct is_mean<Mean<Descriptor, NestedMatrix>> : std::true_type {};
484  }
485 
486 
499 #ifdef __cpp_concepts
500  template<fixed_pattern Descriptor, typed_matrix_nestable NestedMatrix> requires
501  (coordinates::stat_dimension_of_v<Descriptor> == index_dimension_of_v<NestedMatrix, 0>) and (not std::is_rvalue_reference_v<NestedMatrix>)
502 #else
503  template<typename Descriptor, typename NestedMatrix>
504 #endif
505  struct EuclideanMean;
506 
507 
508  namespace internal
509  {
510  template<typename Descriptor, typename NestedMatrix>
511  struct is_euclidean_mean<EuclideanMean<Descriptor, NestedMatrix>> : std::true_type {};
512  }
513 
514 
524 #ifdef __cpp_concepts
525  template<fixed_pattern Descriptor, covariance_nestable NestedMatrix> requires
526  (coordinates::dimension_of_v<Descriptor> == index_dimension_of_v<NestedMatrix, 0>) and
527  (not std::is_rvalue_reference_v<NestedMatrix>) and values::number<scalar_type_of_t<NestedMatrix>>
528 #else
529  template<typename Descriptor, typename NestedMatrix>
530 #endif
531  struct Covariance;
532 
533 
534  namespace internal
535  {
536  template<typename Descriptor, typename NestedMatrix>
537  struct is_self_adjoint_covariance<Covariance<Descriptor, NestedMatrix>> : std::true_type {};
538  }
539 
540 
552 #ifdef __cpp_concepts
553  template<fixed_pattern Descriptor, covariance_nestable NestedMatrix> requires
554  (coordinates::dimension_of_v<Descriptor> == index_dimension_of_v<NestedMatrix, 0>) and
555  (not std::is_rvalue_reference_v<NestedMatrix>) and values::number<scalar_type_of_t<NestedMatrix>>
556 #else
557  template<typename Descriptor, typename NestedMatrix>
558 #endif
560 
561 
562  // ------------------- //
563  // Internal adapters //
564  // ------------------- //
565 
566  namespace internal
567  {
575  #ifdef __cpp_concepts
576  template<indexible NestedObject, indexible LibraryObject>
577  #else
578  template<typename NestedObject, typename LibraryObject>
579  #endif
581 
582 
583  namespace detail
584  {
585  template<typename T>
586  struct is_library_wrapper : std::false_type {};
587 
588  template<typename N, typename L>
589  struct is_library_wrapper<internal::LibraryWrapper<N, L>> : std::true_type {};
590  } // namespace detail
591 
592 
597  template<typename T>
598 #ifdef __cpp_concepts
599  concept library_wrapper =
600 #else
601  constexpr bool library_wrapper =
602 #endif
604 
605 
613  #ifdef __cpp_concepts
614  template<indexible NestedObject, pattern_tuple Descriptors> requires
615  compatible_with_vector_space_descriptor_collection<NestedObject, Descriptors> and
616  internal::not_more_fixed_than<NestedObject, Descriptors> and internal::less_fixed_than<NestedObject, Descriptors>
617  #else
618  template<typename NestedObject, typename Descriptors>
619  #endif
620  struct FixedSizeAdapter;
621 
622 
623  namespace detail
624  {
625  template<typename T>
626  struct is_fixed_size_adapter : std::false_type {};
627 
628  template<typename NestedMatrix, typename Descriptors>
629  struct is_fixed_size_adapter<FixedSizeAdapter<NestedMatrix, Descriptors>> : std::true_type {};
630  }
631 
632 
637  template<typename T>
638 #ifdef __cpp_concepts
639  concept fixed_size_adapter =
640 #else
641  constexpr bool fixed_size_adapter =
642 #endif
644 
645 
646  template<typename Descriptor, typename NestedMatrix>
647  struct is_triangular_covariance<SquareRootCovariance<Descriptor, NestedMatrix>> : std::true_type {};
648 
649  } // namespace internal
650 
651 
660 #ifdef __cpp_concepts
661  template<
662  fixed_pattern Descriptor,
663  typed_matrix_nestable MeanNestedMatrix,
664  covariance_nestable CovarianceNestedMatrix,
665  std::uniform_random_bit_generator random_number_engine = std::mt19937> requires
666  (index_dimension_of_v<MeanNestedMatrix, 0> == index_dimension_of_v<CovarianceNestedMatrix, 0>) and
667  (index_dimension_of_v<MeanNestedMatrix, 1> == 1) and
668  (std::is_same_v<scalar_type_of_t<MeanNestedMatrix>,
670 #else
671  template<
672  typename Descriptor,
673  typename MeanNestedMatrix,
674  typename CovarianceNestedMatrix,
675  typename random_number_engine = std::mt19937>
676 #endif
677  struct GaussianDistribution;
678 
679 
680  namespace internal
681  {
682  template<typename Descriptor, typename MeanNestedMatrix, typename CovarianceNestedMatrix, typename re>
683  struct is_gaussian_distribution<GaussianDistribution<Descriptor, MeanNestedMatrix, CovarianceNestedMatrix, re>>
684  : std::true_type {};
685  }
686 
687 } // OpenKalman
688 
689 #endif //OPENKALMAN_FORWARD_CLASS_DECLARATIONS_HPP
typename nested_object_of< T >::type nested_object_of_t
Helper type for nested_object_of.
Definition: nested_object_of.hpp:66
A hermitian matrix wrapper.
Definition: HermitianAdapter.hpp:31
An adapter that adds vector space descriptors for each index.
Definition: forward-class-declarations.hpp:301
TriangleType
The type of a triangular matrix.
Definition: global-definitions.hpp:60
typename pattern_matrix_of< std::decay_t< T > >::type pattern_matrix_of_t
Helper template for pattern_matrix_of.
Definition: forward-class-declarations.hpp:130
constexpr bool constant_matrix
Specifies that all components of an object are the same constant value.
Definition: constant_matrix.hpp:31
Definition: forward-class-declarations.hpp:157
constexpr bool to_euclidean_expr
Specifies that T is an expression converting coefficients to Euclidean space (i.e., ToEuclideanExpr).
Definition: forward-class-declarations.hpp:404
An expression that transforms angular or other modular vector space descriptors back from Euclidean s...
Definition: FromEuclideanExpr.hpp:29
The native matrix on which an OpenKalman matrix adapter is patterned.
Definition: forward-class-declarations.hpp:111
constexpr bool euclidean_expr
Specifies that T is either to_euclidean_expr or from_euclidean_expr.
Definition: forward-class-declarations.hpp:415
A set of one or more column vectors, each representing a statistical mean.
Definition: forward-class-declarations.hpp:477
typename scalar_type_of< T >::type scalar_type_of_t
helper template for scalar_type_of.
Definition: scalar_type_of.hpp:54
A triangular_adapter, where components above or below the diagonal (or both) are zero.
Definition: forward-class-declarations.hpp:257
Definition: tuple_reverse.hpp:103
HermitianAdapterType
The type of a hermitian adapter, indicating which triangle of the nested matrix is used...
Definition: global-definitions.hpp:78
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
Definition: forward-class-declarations.hpp:265
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
constexpr bool constant_diagonal_matrix
Specifies that all diagonal elements of a diagonal object are the same constant value.
Definition: constant_diagonal_matrix.hpp:34
An upper-right triangular matrix.
Definition: object-types.hpp:121
Definition: object-types.hpp:29
Definition: forward-class-declarations.hpp:586
constexpr bool triangular_matrix
Specifies that a type is a triangular matrix (upper, lower, or diagonal).
Definition: triangular_matrix.hpp:37
Definition: object-types.hpp:172
The constant associated with T, assuming T is a constant_matrix.
Definition: constant_coefficient.hpp:36
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:229
The upper or lower triangle Cholesky factor (square root) of a covariance matrix. ...
Definition: forward-class-declarations.hpp:559
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
constexpr bool from_euclidean_expr
Specifies that T is an expression converting coefficients from Euclidean space (i.e., FromEuclideanExpr).
Definition: forward-class-declarations.hpp:366
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
An expression that transforms vector space descriptors into Euclidean space for application of direct...
Definition: forward-class-declarations.hpp:384
constexpr bool diagonal_expr
Specifies that T is a diagonal matrix based on the Eigen library (i.e., DiaginalMatrix).
Definition: forward-class-declarations.hpp:171
Definition: forward-class-declarations.hpp:215
Definition: FixedSizeAdapter.hpp:28
Definition: forward-class-declarations.hpp:626
constexpr bool constant_adapter
Specifies that T is a ConstantAdapter.
Definition: forward-class-declarations.hpp:78
A structure representing the dimensions associated with of a particular index.
Definition: Dimensions.hpp:42
A self-adjoint Covariance matrix.
Definition: Covariance.hpp:30
A diagonal matrix (both a lower-left and an upper-right triangular matrix).
A tensor or other matrix in which all elements are a constant scalar value.
Definition: ConstantAdapter.hpp:34
constexpr bool triangular_expr
Specifies that T is a triangular matrix based on the Eigen library (i.e., TriangularAdapter).
Definition: forward-class-declarations.hpp:279
A generalization of std::equal_to in which the arguments may be of different types.
Definition: equal_to.hpp:29
Definition: forward-class-declarations.hpp:352
Definition: forward-class-declarations.hpp:390
Definition: forward-class-declarations.hpp:308
constexpr bool covariance_nestable
T is an acceptable nested matrix for a covariance (including triangular_covariance).
Definition: object-types.hpp:237
Definition: forward-class-declarations.hpp:64
An adapter for creating a diagonal matrix or tensor.
Definition: DiagonalAdapter.hpp:27
Definition: object-types.hpp:139
Definition: forward-class-declarations.hpp:580
A lower-left triangular matrix.
Definition: object-types.hpp:99
A matrix with typed rows and columns.
Definition: forward-class-declarations.hpp:448