OpenKalman
get_index_table.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) 2025 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_DESCRIPTORS_GET_INDEX_TABLE_HPP
17 #define OPENKALMAN_DESCRIPTORS_GET_INDEX_TABLE_HPP
18 
19 #include <type_traits>
20 #include "collections/views/internal/repeat_tuple_view.hpp"
26 
28 {
29  namespace detail
30  {
31  template<std::size_t c = 0, std::size_t local = 0, typename Tup, std::size_t...is>
32  static constexpr auto
33  get_index_table_tuple(const Tup& tup, std::index_sequence<is...> seq = std::index_sequence<>{})
34  {
35  if constexpr (c < std::tuple_size_v<Tup>)
36  {
37  if constexpr (local < dimension_of_v<std::tuple_element_t<c, Tup>>)
38  return get_index_table_tuple<c, local + 1>(tup, std::index_sequence<is..., c>{});
39  else
40  return get_index_table_tuple<c + 1, 0>(tup, seq);
41  }
42  else return std::tuple {std::integral_constant<std::size_t, is>{}...};
43  }
44  } // namespace detail
45 
46 
52 #ifdef __cpp_lib_constexpr_vector
53  template<pattern Arg>
54  constexpr collections::index auto
55 #else
56  template<typename Arg, std::enable_if_t<pattern<Arg>, int> = 0>
57  auto
58 #endif
59  get_index_table(Arg&& arg)
60  {
61  if constexpr (dimension_of_v<Arg> != dynamic_size)
62  {
63  if constexpr (descriptor<Arg>)
64  {
65  constexpr std::size_t N = values::to_number(get_descriptor_dimension(arg));
67  }
68  else
69  {
70  return detail::get_index_table_tuple(arg);
71  }
72  }
73  else
74  {
75  std::vector<std::size_t> table;
76  std::size_t c = 0;
77  for (auto& comp : arg)
78  {
79  for (std::size_t local = 0; local < get_descriptor_dimension(comp); ++local) table.emplace_back(c);
80  ++c;
81  }
82  return table;
83  }
84  }
85 
86 
87 } // namespace OpenKalman::coordinates::internal
88 
89 
90 #endif //OPENKALMAN_DESCRIPTORS_GET_INDEX_TABLE_HPP
Definition: get_component_start_indices.hpp:29
Definition: tuple_reverse.hpp:103
Definition for coordinates::pattern.
constexpr auto to_number(Arg arg)
Convert any values::value to a values::number.
Definition: to_number.hpp:34
Definition for coordinates::descriptor.
Definition for collections::index.
constexpr std::size_t dynamic_size
A constant indicating that a size or index is dynamic.
Definition: global-definitions.hpp:33
auto get_index_table(Arg &&arg)
Get a collection mapping each index of an indexible vector to a corresponding index within component_...
Definition: get_index_table.hpp:59
constexpr bool index
An object describing a collection of /ref values::index objects.
Definition: index.hpp:75
Definition for coordinates::dimension_of.