OpenKalman
make_identity_matrix_like.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) 2022-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_MAKE_IDENTITY_MATRIX_LIKE_HPP
17 #define OPENKALMAN_MAKE_IDENTITY_MATRIX_LIKE_HPP
18 
19 namespace OpenKalman
20 {
27 #ifdef __cpp_concepts
28  template<indexible T, values::number Scalar = scalar_type_of_t<T>, pattern_collection Descriptors>
29  constexpr identity_matrix auto
30 #else
31  template<typename T, typename Scalar = typename scalar_type_of<T>::type, typename Descriptors, std::enable_if_t<
32  indexible<T> and values::number<Scalar> and pattern_collection<Descriptors>, int> = 0>
33  constexpr auto
34 #endif
35  make_identity_matrix_like(Descriptors&& descriptors)
36  {
37  decltype(auto) d = internal::remove_trailing_1D_descriptors(std::forward<Descriptors>(descriptors));
38  using D = decltype(d);
40 
41  if constexpr (coordinates::euclidean_pattern_collection<D> and interface::make_identity_matrix_defined_for<T, Scalar, D>)
42  {
43  return Trait::template make_identity_matrix<Scalar>(std::forward<D>(d));
44  }
45  else if constexpr (interface::make_identity_matrix_defined_for<T, Scalar, decltype(internal::to_euclidean_vector_space_descriptor_collection(d))>)
46  {
47  auto ed = internal::to_euclidean_vector_space_descriptor_collection(d);
48  return make_vector_space_adapter(Trait::template make_identity_matrix<Scalar>(ed), std::forward<D>(d));
49  }
50  else
51  {
52  return internal::make_constant_diagonal_from_descriptors<T>(values::Fixed<Scalar, 1>{}, std::forward<D>(d));
53  }
54  }
55 
56 
61 #ifdef __cpp_concepts
62  template<indexible T, values::number Scalar = scalar_type_of_t<T>, coordinates::pattern...Ds>
63  constexpr identity_matrix auto
64 #else
65  template<typename T, typename Scalar = typename scalar_type_of<T>::type, typename...Ds, std::enable_if_t<
66  indexible<T> and values::number<Scalar> and (... and coordinates::pattern<Ds>), int> = 0>
67  constexpr auto
68 #endif
70  {
71  return make_identity_matrix_like<T, Scalar>(std::tuple {std::forward<Ds>(ds)...});
72  }
73 
74 
82 #ifdef __cpp_concepts
83  template<values::number Scalar, indexible Arg>
84  constexpr identity_matrix auto
85 #else
86  template<typename Scalar, typename Arg, std::enable_if_t<values::number<Scalar> and indexible<Arg>, int> = 0>
87  constexpr auto
88 #endif
90  {
91  if constexpr (identity_matrix<Arg> and std::is_same_v<Scalar, scalar_type_of_t<Arg>>) return std::forward<Arg>(arg);
92  else return make_identity_matrix_like<Arg, Scalar>(all_vector_space_descriptors(std::forward<Arg>(arg)));
93  }
94 
95 
102 #ifdef __cpp_concepts
103  template<indexible Arg>
104  constexpr identity_matrix auto
105 #else
106  template<typename Arg, std::enable_if_t<indexible<Arg>, int> = 0>
107  constexpr auto
108 #endif
110  {
111  return make_identity_matrix_like<scalar_type_of_t<Arg>>(std::forward<Arg>(arg));
112  }
113 
114 
115 } // namespace OpenKalman
116 
117 #endif //OPENKALMAN_MAKE_IDENTITY_MATRIX_LIKE_HPP
auto make_vector_space_adapter(Arg &&arg, Descriptors &&descriptors)
If necessary, wrap an object in a wrapper that adds vector space descriptors for each index...
Definition: make_vector_space_adapter.hpp:37
typename scalar_type_of< T >::type scalar_type_of_t
helper template for scalar_type_of.
Definition: scalar_type_of.hpp:54
decltype(auto) constexpr all_vector_space_descriptors(const T &t)
Return a collection of coordinates::pattern objects associated with T.
Definition: all_vector_space_descriptors.hpp:52
The root namespace for OpenKalman.
Definition: basics.hpp:34
An interface to various routines from the linear algebra library associated with indexible object T...
Definition: library_interface.hpp:37
constexpr auto make_identity_matrix_like(Descriptors &&descriptors)
Make an identity_matrix with a particular set of coordinates::pattern objects.
Definition: make_identity_matrix_like.hpp:35
constexpr bool identity_matrix
Specifies that a type is an identity matrix.
Definition: identity_matrix.hpp:45
Definition: Fixed.hpp:36