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