OpenKalman
set_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_SET_WRAPPED_COMPONENT_HPP
17 #define OPENKALMAN_SET_WRAPPED_COMPONENT_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::value X, values::index L>
46  constexpr void
47  set_wrapped_component(const T& t, const auto& s, const auto& g, const X& x, const L& local_index)
48  requires requires(std::size_t i) { s(x, i); s(g(i), i); }
49 #else
50  template<typename T, typename Setter, typename Getter, typename X, typename L, std::enable_if_t<
51  pattern<T> and values::value<X> and values::index<L> and
53  std::is_invocable<const Setter&, typename std::invoke_result<const Getter&, std::size_t>::type, std::size_t>::value, int> = 0>
54  constexpr void
55  set_wrapped_component(const T& t, const Setter& s, const Getter& g, const X& x, const L& local_index)
56 #endif
57  {
58  if constexpr (dimension_of_v<T> != dynamic_size and values::fixed<L>)
59  static_assert(values::to_number(local_index) < dimension_of_v<T>);
60 
61  if constexpr (euclidean_pattern<T>)
62  {
63  s(x, local_index);
64  }
65  else if constexpr (descriptor<T>)
66  {
68  }
69  else // if constexpr (descriptor_collection<T>)
70  {
71  using Scalar = std::decay_t<decltype(x)>;
72  auto component_ix = collections::get(internal::get_index_table(t), local_index);
73  auto component = internal::get_descriptor_collection_element(t, component_ix);
74  auto start_i = collections::get(internal::get_component_start_indices(t), component_ix);
75  auto new_g = [&g, start_i](auto i) { return g(values::operation {std::plus{}, start_i, i}); };
76  auto new_s = [&s, start_i](const Scalar& x, auto i) { s(x, values::operation {std::plus{}, start_i, i}); };
77  auto new_local_index = values::operation {std::minus{}, local_index, start_i};
78  set_wrapped_component(component, new_s, new_g, x, new_local_index);
79  }
80  }
81 
82 
83 } // namespace OpenKalman::coordinates
84 
85 
86 #endif //OPENKALMAN_SET_WRAPPED_COMPONENT_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 void set_wrapped_component(const T &t, const Setter &s, const Getter &g, const X &x, const L &local_index)
Set a component and then perform any required wrapping.
Definition: set_wrapped_component.hpp:55
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.