OpenKalman
get_euclidean_component_start_indices.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_COMPONENT_START_INDICES_HPP
17 #define OPENKALMAN_DESCRIPTORS_GET_EUCLIDEAN_COMPONENT_START_INDICES_HPP
18 
19 #include <type_traits>
20 #include <functional>
27 
29 {
30  namespace detail
31  {
32  template<std::size_t i = 0, typename Tup, typename CurrLoc = std::integral_constant<std::size_t, 0>, typename...Locs>
33  static constexpr auto euclidean_component_start_indices_tuple(const Tup& tup, CurrLoc currloc = {}, Locs...locs)
34  {
35  if constexpr (i < std::tuple_size_v<Tup>)
36  {
37  auto next_loc = values::operation {std::plus{}, currloc, get_descriptor_stat_dimension(std::get<i>(tup))};
38  return euclidean_component_start_indices_tuple<i + 1>(tup, std::move(next_loc), std::move(locs)..., std::move(currloc));
39  }
40  else return std::tuple {std::move(locs)...};
41  }
42  } // namespace detail
43 
44 
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
60  {
61  if constexpr (descriptor<Arg>)
62  {
63  return std::array {std::integral_constant<std::size_t, 0>{}};
64  }
65  else if constexpr (descriptor_tuple<Arg>)
66  {
67  return detail::euclidean_component_start_indices_tuple(arg);
68  }
69  else
70  {
71  std::size_t i = 0, loc = 0;
72  std::vector<std::size_t> indices(get_size(arg));
73  for (auto& c : arg)
74  {
75  indices[i++] = loc;
76  loc += get_descriptor_stat_dimension(c);
77  }
78  return indices;
79  }
80  }
81 
82 
83 } // namespace OpenKalman::coordinates::internal
84 
85 
86 #endif //OPENKALMAN_DESCRIPTORS_GET_EUCLIDEAN_COMPONENT_START_INDICES_HPP
Definition: get_component_start_indices.hpp:29
Definition for coordinates::pattern.
Definition for coordinates::descriptor_tuple.
Definition for coordinates::descriptor.
auto get_euclidean_component_start_indices(Arg &&arg)
A collections::index mapping a component of T to an index within a vector.
Definition: get_euclidean_component_start_indices.hpp:59
Definition for collections::index.
operation(const Operation &, const Args &...) -> operation< Operation, Args... >
Deduction guide.
constexpr auto get_size(Arg &&arg)
Get the size of a sized object (e.g, a collection)
Definition: get_size.hpp:191
constexpr bool index
An object describing a collection of /ref values::index objects.
Definition: index.hpp:75