OpenKalman
get_euclidean_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_EUCLIDEAN_INDEX_TABLE_HPP
17 #define OPENKALMAN_DESCRIPTORS_GET_EUCLIDEAN_INDEX_TABLE_HPP
18 
19 #include <vector>
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  euclidean_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 < stat_dimension_of_v<std::tuple_element_t<c, Tup>>)
38  return euclidean_index_table_tuple<c, local + 1>(tup, std::index_sequence<is..., c>{});
39  else
40  return euclidean_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 
53 #ifdef __cpp_lib_constexpr_vector
54  template<pattern Arg>
55  constexpr collections::index auto
56 #else
57  template<typename Arg, std::enable_if_t<pattern<Arg>, int> = 0>
58  auto
59 #endif
61  {
62  if constexpr (stat_dimension_of_v<Arg> != dynamic_size)
63  {
64  if constexpr (descriptor<Arg>)
65  {
66  constexpr std::size_t N = values::to_number(get_euclidean_descriptor_size(arg));
68  }
69  else
70  {
71  return detail::euclidean_index_table_tuple(arg);
72  }
73  }
74  else
75  {
76  std::vector<std::size_t> table;
77  std::size_t c = 0;
78  for (auto& comp : arg)
79  {
80  for (std::size_t local = 0; local < get_descriptor_stat_dimension(comp); ++local) table.emplace_back(c);
81  ++c;
82  }
83  return table;
84  }
85  }
86 
87 
88 } // namespace OpenKalman::coordinates::internal
89 
90 
91 #endif //OPENKALMAN_DESCRIPTORS_GET_EUCLIDEAN_INDEX_TABLE_HPP
Definition: get_component_start_indices.hpp:29
auto get_euclidean_index_table(Arg &&arg)
A collection mapping each index of an indexible vector, transformed to statistical space) to a corres...
Definition: get_euclidean_index_table.hpp:60
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 coordinates::stat_dimension_of.
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
constexpr bool index
An object describing a collection of /ref values::index objects.
Definition: index.hpp:75