OpenKalman
get_wrapped_component.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) 2020-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_WRAP_GET_ELEMENT_HPP
17 #define OPENKALMAN_WRAP_GET_ELEMENT_HPP
18 
19 #include <type_traits>
20 #include <functional>
24 #include "linear-algebra/coordinates/interfaces/coordinate_descriptor_traits.hpp"
32 
34 {
44 #ifdef __cpp_concepts
45  template<pattern T, values::index L>
46  constexpr values::value auto
47  get_wrapped_component(const T& t, const auto& g, const L& local_index)
48  requires requires(std::size_t i) { {g(i)} -> values::value; }
49 #else
50  template<typename T, typename Getter, typename L, std::enable_if_t<pattern<T> and values::index<L> and
51  values::value<typename std::invoke_result<Getter, std::size_t>::type>, int> = 0>
52  constexpr auto
53  get_wrapped_component(const T& t, const Getter& g, const L& local_index)
54 #endif
55  {
56  if constexpr (dimension_of_v<T> != dynamic_size and values::fixed<L>)
57  static_assert(values::to_number(local_index) < dimension_of_v<T>);
58 
59  if constexpr (euclidean_pattern<T>)
60  {
61  return g(local_index);
62  }
63  else if constexpr (descriptor<T>)
64  {
66  }
67  else // if constexpr (descriptor_collection<T>)
68  {
69  auto component_ix = collections::get(internal::get_index_table(t), local_index);
70  auto component = internal::get_descriptor_collection_element(t, component_ix);
71  auto start_i = collections::get(internal::get_component_start_indices(t), component_ix);
72  auto new_g = [&g, start_i](auto i) { return g(values::operation {std::plus{}, start_i, i}); };
73  auto new_local_index = values::operation {std::minus{}, local_index, start_i};
74  return get_wrapped_component(component, new_g, new_local_index);
75  }
76  }
77 
78 
79 } // namespace OpenKalman::coordinates
80 
81 
82 #endif //OPENKALMAN_WRAP_GET_ELEMENT_HPP
Definition for coordinates::euclidean_pattern.
Definition for collections::get.
decltype(auto) constexpr get(Arg &&arg, I i)
A generalization of std::get.
Definition: get.hpp:62
An operation involving some number of values.
Definition: operation.hpp:69
constexpr auto get_wrapped_component(const T &t, const Getter &g, const L &local_index)
Gets an element from a matrix or tensor object and wraps the result.
Definition: get_wrapped_component.hpp:53
Definition for coordinates::internal::get_component_start_indices.
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
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::internal::get_index_table.
Definition for coordinates::descriptor.
Definition: compares_with.hpp:28
Traits for coordinates::pattern objects.
Definition: coordinate_descriptor_traits.hpp:41
constexpr std::size_t dynamic_size
A constant indicating that a size or index is dynamic.
Definition: global-definitions.hpp:33
Definition for ::value.
Definition for coordinates::dimension_of.