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 = coordinates::internal::strip_1D_tail(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_pattern_collection(d))>)
46  {
47  auto ed = internal::to_euclidean_pattern_collection(d);
48  return attach_pattern(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_value<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 }
116 
117 #endif
constexpr auto attach_pattern(Arg &&arg, P &&p)
Attach a pattern_collection to an indexible object.
Definition: attach_pattern.hpp:36
Definition: fixed_value.hpp:41
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:42
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 known at compile time to be a rank-2 or lower identity matrix.
Definition: identity_matrix.hpp:50