OpenKalman
get_stat_dimension.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_GET_EUCLIDEAN_DIMENSION_HPP
17 #define OPENKALMAN_GET_EUCLIDEAN_DIMENSION_HPP
18 
19 #include <functional>
20 #include "basics/basics.hpp"
25 
27 {
28  namespace detail
29  {
30 #ifndef __cpp_lib_ranges
31  template<typename T, typename = void>
32  struct range_value_has_fixed_stat_dimension : std::false_type {};
33 
34  template<typename T>
35  struct range_value_has_fixed_stat_dimension<T, std::enable_if_t<stdex::ranges::range<T>>>
36  : std::bool_constant<values::fixed_value_compares_with<decltype(internal::get_descriptor_stat_dimension(
37  std::declval<stdex::ranges::range_value_t<T>>())), 0>> {};
38 #endif
39 
40 
41  template<std::size_t i = 0, typename T>
42  static constexpr auto get_stat_dimension_fixed(const T& t)
43  {
44  if constexpr (i < collections::size_of_v<T>)
45  {
46  return values::operation(
47  std::plus{},
48  internal::get_descriptor_stat_dimension(collections::get<i>(t)),
49  get_stat_dimension_fixed<i + 1>(t));
50  }
51  else return std::integral_constant<std::size_t, 0_uz>{};
52  }
53  }
54 
55 
60 #ifdef __cpp_concepts
61  template<pattern Arg> requires descriptor<Arg> or collections::sized<Arg> or
62  values::fixed_value_compares_with<decltype(internal::get_descriptor_stat_dimension(std::declval<stdex::ranges::range_value_t<Arg>>())), 0>
63  constexpr values::index auto
64 #else
65  template<typename Arg, std::enable_if_t<descriptor<Arg> or
66  (descriptor_collection<Arg> and (collections::sized<Arg> or detail::range_value_has_fixed_stat_dimension<Arg>::value)), int> = 0>
67  constexpr auto
68 #endif
69  get_stat_dimension(const Arg& arg)
70  {
71  if constexpr (descriptor<Arg>)
72  {
73  return internal::get_descriptor_stat_dimension(arg);
74  }
75  else if constexpr (collections::size_of_v<Arg> == 0)
76  {
77  return std::integral_constant<std::size_t, 0_uz>{};
78  }
79  else if constexpr (not collections::sized<Arg> or collections::size_of_v<Arg> == stdex::dynamic_extent)
80  {
81  using C = decltype(internal::get_descriptor_stat_dimension(std::declval<stdex::ranges::range_value_t<Arg>>()));
82  if constexpr (not values::fixed<C>)
83 #ifdef __cpp_lib_ranges_fold
84  return std::ranges::fold_left(collections::views::all(arg), 0_uz,
85  [](const auto& a, const auto& b) { return a + internal::get_descriptor_stat_dimension(b); });
86 #else
87  {
88  std::size_t ret = 0_uz;
89  for (const auto& c : collections::views::all(arg)) ret += internal::get_descriptor_stat_dimension(c);
90  return ret;
91  }
92 #endif
93  else if constexpr (values::fixed_value_of_v<C> == 0)
94  return std::integral_constant<std::size_t, 0_uz>{};
95  else // collections::sized<Arg>
96  return values::operation(std::multiplies{}, values::fixed_value_of<C>{}, collections::get_size(arg));
97  }
98  else
99  {
100  return detail::get_stat_dimension_fixed(arg);
101  }
102  }
103 
104 
105 }
106 
107 #endif
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
The fixed value associated with a fixed.
Definition: fixed_value_of.hpp:44
Definition for coordinates::pattern.
Definition for coordinates::descriptor.
The namespace for features relating to coordinates::pattern object.
Definition: compares_with.hpp:25
constexpr detail::all_closure all
a std::ranges::range_adaptor_closure which returns a view to all members of its collection argument...
Definition: all.hpp:72
constexpr bool index
T is an index value.
Definition: index.hpp:62
Basic definitions for OpenKalman as a whole.
Definition for collections::uniformly_gettable.
constexpr auto get_size(Arg &&arg)
Get the size of a sized object (e.g, a collection)
Definition: get_size.hpp:188
constexpr auto operation(Operation &&op, Args &&...args)
A potentially constant-evaluated operation involving some number of values.
Definition: operation.hpp:98