17 #ifndef OPENKALMAN_DESCRIPTOR_ANY_HPP 18 #define OPENKALMAN_DESCRIPTOR_ANY_HPP 22 #include "coordinates/interfaces/coordinate_descriptor_traits.hpp" 38 template<values::number S =
double> requires std::same_as<S, std::decay_t<S>>
40 template<
typename S =
double>
59 template<values::number S> requires std::same_as<S, std::decay_t<S>>
67 using Getter = std::function<S(std::size_t)>;
71 virtual ~Base() =
default;
72 [[nodiscard]]
virtual std::size_t dimension()
const = 0;
73 [[nodiscard]]
virtual std::size_t stat_dimension()
const = 0;
74 [[nodiscard]]
virtual bool is_euclidean()
const = 0;
75 [[nodiscard]]
virtual std::size_t hash_code()
const = 0;
76 [[nodiscard]]
virtual Getter
to_stat_space(Getter g)
const = 0;
78 [[nodiscard]]
virtual Getter
wrap(Getter g)
const = 0;
85 template<
typename Arg>
86 explicit Derived(Arg&& arg) : my_t(std::forward<Arg>(arg)) {}
88 [[nodiscard]] std::size_t dimension()
const final {
return internal::get_descriptor_dimension(my_t); }
90 [[nodiscard]] std::size_t stat_dimension()
const final {
return internal::get_descriptor_stat_dimension(my_t); }
92 [[nodiscard]]
bool is_euclidean()
const final {
return internal::get_descriptor_is_euclidean(my_t); }
94 [[nodiscard]] std::size_t hash_code()
const final {
return internal::get_descriptor_hash_code(my_t); }
98 if constexpr (euclidean_pattern<T>)
111 if constexpr (euclidean_pattern<T>)
122 [[nodiscard]] Getter
wrap(Getter g)
const final 124 if constexpr (euclidean_pattern<T>)
145 #ifdef __cpp_concepts 148 template<
typename Arg, std::enable_if_t<descriptor<Arg> and (not detail::is_Any<std::decay_t<Arg>>::value),
int> = 0>
151 Any(Arg&& arg) : mBase {std::make_shared<Derived<std::decay_t<Arg>>>(std::forward<Arg>(arg))} {}
154 #ifndef __cpp_concepts 156 constexpr
Any() : mBase {std::make_shared<Derived<std::integral_constant<std::size_t, 0>>>(std::integral_constant<std::size_t, 0>{})} {}
161 const std::shared_ptr<Base> mBase;
163 #ifdef __cpp_concepts 166 template<
typename T,
typename>
190 static constexpr
bool is_specialized =
true;
193 static constexpr
auto dimension = [](
const T& t) -> std::size_t {
return t.mBase->dimension(); };
196 static constexpr
auto stat_dimension = [](
const T& t) -> std::size_t {
return t.mBase->stat_dimension(); };
199 static constexpr
auto is_euclidean = [](
const T& t) ->
bool {
return t.mBase->is_euclidean(); };
202 static constexpr
auto hash_code = [](
const T& t) -> std::size_t {
return t.mBase->hash_code(); };
205 static constexpr
auto 208 auto d = std::make_tuple(std::forward<decltype(data_view)>(data_view));
210 t.mBase->to_stat_space([d](std::size_t i){ return collections::get_element(std::get<0>(d), i); }),
211 t.mBase->stat_dimension());
215 static constexpr
auto 218 auto d = std::make_tuple(std::forward<decltype(data_view)>(data_view));
220 t.mBase->from_stat_space([d](std::size_t i){ return collections::get_element(std::get<0>(d), i); }),
221 t.mBase->dimension());
225 static constexpr
auto 226 wrap = [](
const T& t,
auto&& data_view)
228 auto d = std::make_tuple(std::forward<decltype(data_view)>(data_view));
230 t.mBase->wrap([d](std::size_t i){ return collections::get_element(std::get<0>(d), i); }),
231 t.mBase->dimension());
241 template<
typename Scalar1,
typename Scalar2>
243 : std::conditional_t<
244 OpenKalman::stdex::common_with<Scalar1, Scalar2>,
245 OpenKalman::stdex::type_identity<OpenKalman::coordinates::Any<
246 typename std::conditional_t<
247 OpenKalman::stdex::common_with<Scalar1, Scalar2>,
248 common_type<Scalar1, Scalar2>,
249 OpenKalman::stdex::type_identity<double>>::type>>,
253 template<
typename S,
typename T>
254 struct common_type<OpenKalman::coordinates::Any<S>, T>
255 : std::conditional_t<
256 OpenKalman::coordinates::descriptor<T>,
257 OpenKalman::stdex::type_identity<OpenKalman::coordinates::Any<S>>,
constexpr auto get_stat_dimension(const Arg &arg)
Get the vector dimension of coordinates::pattern Arg when transformed into statistical space...
Definition: get_stat_dimension.hpp:69
Definition: basics.hpp:41
decltype(auto) constexpr to_stat_space(const T &t, R &&data_view)
Maps a range reflecting vector-space data to a corresponding range in a vector space for directional ...
Definition: to_stat_space.hpp:44
decltype(auto) constexpr wrap(const T &t, R &&data_view)
wraps a range reflecting vector-space data to its primary range.
Definition: wrap.hpp:59
constexpr Any(Arg &&arg)
Construct from a coordinates::descriptor.
Definition: Any.hpp:151
Definition for coordinates::to_stat_space.
Definition for coordinates::wrap.
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
Definition for collections::from_stat_space.
constexpr auto get_dimension(const Arg &arg)
Get the vector dimension of coordinates::pattern Arg.
Definition: get_dimension.hpp:54
The root namespace for OpenKalman.
Definition: basics.hpp:34
The namespace for features relating to coordinates::pattern object.
Definition: compares_with.hpp:25
Definition for get_descriptor_hash_code.
Inclusion file for collections.
Traits for coordinates::pattern objects.
Definition: coordinate_descriptor_traits.hpp:36
constexpr detail::generate_adaptor generate
a collection_view generator associated with generate_view.
Definition: generate.hpp:335
decltype(auto) constexpr get_element(Arg &&arg, I i)
A generalization of std::get and the range subscript operator.
Definition: get_element.hpp:122
decltype(auto) constexpr from_stat_space(const T &t, R &&stat_data_view)
Maps a range in a vector space for directional-statistics back to a range reflecting vector-space dat...
Definition: from_stat_space.hpp:44
Tests whether the argument is an instance of of type Any.
Definition: Any.hpp:51