OpenKalman
smallest_vector_space_descriptor.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) 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 
17 #ifndef OPENKALMAN_SMALLEST_VECTOR_SPACE_DESCRIPTOR_HPP
18 #define OPENKALMAN_SMALLEST_VECTOR_SPACE_DESCRIPTOR_HPP
19 
21 {
30 #ifdef __cpp_concepts
31  template<values::number Scalar, coordinates::pattern V, coordinates::pattern...Vs>
32  constexpr coordinates::pattern decltype(auto)
33 #else
34  template<typename Scalar, typename V, typename...Vs, std::enable_if_t<
35  values::number<Scalar> and (coordinates::pattern<V> and ... and coordinates::pattern<Vs>), int> = 0>
36  constexpr decltype(auto)
37 #endif
38  smallest_vector_space_descriptor(V&& v, Vs&&...vs)
39  {
40  if constexpr (sizeof...(Vs) == 0)
41  {
42  return std::forward<V>(v);
43  }
44  else
45  {
46  decltype(auto) tail = smallest_vector_space_descriptor<Scalar>(std::forward<Vs>(vs)...);
47 
48  if constexpr ((fixed_pattern<V> and fixed_pattern<decltype(tail)>))
49  {
50  if constexpr (dimension_of_v<V> <= dimension_of_v<decltype(tail)>)
51  return std::forward<V>(v);
52  else
53  return std::forward<decltype(tail)>(tail);
54  }
55  else if constexpr (euclidean_pattern<V> and euclidean_pattern<decltype(tail)>)
56  {
57  return coordinates::Dimensions {std::min<std::size_t>(get_dimension(v), get_dimension(tail))};
58  }
59  else
60  {
61  if (get_dimension(v) <= get_dimension(tail))
62  return coordinates::DynamicDescriptor<Scalar> {std::forward<V>(v)};
63  else
64  return coordinates::DynamicDescriptor<Scalar> {std::forward<decltype(tail)>(tail)};
65  }
66  }
67  }
68 
69 } // namespace OpenKalman::coordinates::internal
70 
71 #endif //OPENKALMAN_SMALLEST_VECTOR_SPACE_DESCRIPTOR_HPP
Definition: get_component_start_indices.hpp:29
constexpr bool number
T is a numerical type.
Definition: number.hpp:33
Definition: tuple_reverse.hpp:103
constexpr auto get_dimension(const Arg &arg)
Get the vector dimension of coordinates::pattern Arg.
Definition: get_dimension.hpp:55