OpenKalman
coordinate_descriptor_traits.hpp
1 /* This file is part of OpenKalman, a header-only C++ library for
2  * Kalman filters and other recursive filters.
3  *
4  * Copyright (c) 2022-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 
17 #ifndef OPENKALMAN_VECTOR_SPACE_TRAITS_HPP
18 #define OPENKALMAN_VECTOR_SPACE_TRAITS_HPP
19 
20 #include <type_traits>
21 #include <typeindex>
22 #ifdef __cpp_lib_ranges
23 #include <ranges>
24 #else
26 #endif
30 
31 namespace OpenKalman::interface
32 {
36 #ifdef __cpp_concepts
37  template<typename T>
38 #else
39  template<typename T, typename = void>
40 #endif
42  {
43  static constexpr bool
44  is_specialized = false;
45 
46 
50  static constexpr auto
52  [](const T&) noexcept
53 #ifdef __cpp_concepts
54  -> values::index auto
55 #endif
56  { return std::integral_constant<std::size_t, 0_uz>{}; };
57 
58 
62  static constexpr auto stat_dimension = [](const T&) noexcept -> values::index auto
63  { return std::integral_constant<std::size_t, 0_uz>{}; };
64 
65 
70  static constexpr auto
72  [](const T&) noexcept
73 #ifdef __cpp_concepts
74  -> std::convertible_to<bool> auto
75 #endif
76  { return std::false_type {}; };
77 
83  static constexpr auto
84  hash_code = [](const T&) noexcept -> std::size_t { return typeid(T).hash_code(); };
85 
86 
93  static constexpr auto
95 #ifdef __cpp_concepts
96  [](const T& t, collections::collection_view auto&& data_view) noexcept -> collections::collection_view decltype(auto)
97 #else
98  [](const T& t, auto&& data_view) noexcept
99 #endif
100  {
101  return std::forward<decltype(data_view)>(data_view);
102  };
103 
104 
111  static constexpr auto
113 #ifdef __cpp_concepts
114  [](const T& t, collections::collection_view auto&& data_view) noexcept -> collections::collection_view decltype(auto)
115 #else
116  [](const T& t, auto&& data_view) noexcept
117 #endif
118  {
119  return std::forward<decltype(data_view)>(data_view);
120  };
121 
122 
131  static constexpr auto
133 #ifdef __cpp_concepts
134  [](const T& t, collections::collection_view auto&& data_view) noexcept -> collections::collection_view decltype(auto)
135 #else
136  [](const T& t, auto&& data_view) noexcept
137 #endif
138  {
139  return std::forward<decltype(data_view)>(data_view);
140  };
141 
142  };
143 
144 
148 #ifdef __cpp_concepts
149  template<values::index T>
151 #else
152  template<typename T>
153  struct coordinate_descriptor_traits<T, std::enable_if_t<values::index<T>>>
154 #endif
155  {
156  static constexpr bool is_specialized = true;
157 
158  using scalar_type = values::number_type_of_t<T>;
159 
160  static constexpr auto
161  dimension = [](const T& t) { return t; };
162 
163  static constexpr auto
164  stat_dimension = [](const T& t) { return t; };
165 
166  static constexpr auto
167  is_euclidean = [](const T&) { return std::true_type {}; };
168 
169  static constexpr auto
170  hash_code = [](const T& t) -> std::size_t { return t; };
171 
172  };
173 
174 
175 } // namespace OpenKalman::interface
176 
177 
178 
179 #endif //OPENKALMAN_VECTOR_SPACE_TRAITS_HPP
Definition for values::index.
Definition: basics.hpp:41
static constexpr auto is_euclidean
A callable object returning a bool reflecting whether the coordinates::pattern object describes Eucli...
Definition: coordinate_descriptor_traits.hpp:71
Definition: tuple_reverse.hpp:103
Definition for collections::size_of.
static constexpr auto dimension
A callable object returning the number of dimensions at compile time (as a values::index).
Definition: coordinate_descriptor_traits.hpp:51
static constexpr auto stat_dimension
A callable object returning the number of dimensions after transforming to Euclidean space (as a valu...
Definition: coordinate_descriptor_traits.hpp:62
Definition for collections::collection_view.
static constexpr auto to_stat_space
A callable object mapping a range reflecting vector-space data to a corresponding range in a vector s...
Definition: coordinate_descriptor_traits.hpp:94
static constexpr auto from_stat_space
A callable object mapping a range in a vector space for directional statistics back to a range corres...
Definition: coordinate_descriptor_traits.hpp:112
constexpr bool collection_view
A view to a collection which is also a std::ranges:view.
Definition: collection_view.hpp:36
Traits for coordinates::pattern objects.
Definition: coordinate_descriptor_traits.hpp:41
Definitions implementing features of the c++ ranges library for compatibility.
constexpr bool index
T is an index value.
Definition: index.hpp:56
std::decay_t< decltype(values::to_number(std::declval< T >()))> number_type_of_t
Obtain the values::number type associated with avalues::value.
Definition: number_type_of_t.hpp:34
static constexpr auto hash_code
A callable object returning a unique hash code for type T, of type std::size_t.
Definition: coordinate_descriptor_traits.hpp:84
static constexpr auto wrap
A callable object that maps a range reflecting vector-space data to a wrapped range.
Definition: coordinate_descriptor_traits.hpp:132