OpenKalman
to_extents.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) 2024-2026 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_TO_EXTENTS_HPP
18 #define OPENKALMAN_TO_EXTENTS_HPP
19 
23 
24 namespace OpenKalman::patterns
25 {
26  namespace detail
27  {
28  template<typename P, std::size_t curr_rank = collections::size_of_v<P>>
29  struct derive_rank
30  : std::integral_constant<
31  std::size_t,
32  dimension_of_v<pattern_collection_element_t<curr_rank - 1, P>> == 1 ?
33  derive_rank<P, curr_rank - 1>::value :
34  curr_rank>
35  {};
36 
37  template<typename P>
38  struct derive_rank<P, 0> : std::integral_constant<std::size_t, 0> {};
39 
40 
41  template<std::size_t previous_i, std::size_t...SDs, typename P, typename...Ds>
42  constexpr auto
43  derive_extents(const P& p, Ds...ds)
44  {
45  if constexpr (previous_i == 0)
46  {
47  return stdex::extents<std::size_t, SDs...>{std::move(ds)...};
48  }
49  else
50  {
51  constexpr std::size_t i = previous_i - 1;
52  auto d = patterns::get_dimension(get_pattern<i>(p));
53  if constexpr (values::fixed<decltype(d)>)
54  return derive_extents<i, values::fixed_value_of_v<decltype(d)>, SDs...>(p, std::move(ds)...);
55  else
56  return derive_extents<i, stdex::dynamic_extent, SDs...>(p, std::move(d), std::move(ds)...);
57  }
58  }
59 
60  }
61 
62 
69 #ifdef __cpp_lib_constexpr_vector
70  template<std::size_t rank, pattern_collection P> requires
71  values::fixed_value_compares_with<collections::size_of<P>, stdex::dynamic_extent, &stdex::is_neq>
72 #else
73  template<std::size_t rank, typename P, std::enable_if_t<
74  pattern_collection<P> and
75  values::fixed_value_compares_with<collections::size_of<P>, stdex::dynamic_extent, &stdex::is_neq>, int> = 0>
76 #endif
77  constexpr auto
78  to_extents(P&& p)
79  {
80  static_assert(rank >= detail::derive_rank<P>::value, "Rank must be large enough to hold all non-unitary extents.");
81  return detail::derive_extents<rank>(p);
82  }
83 
84 
88  template<std::size_t rank, typename IndexType, std::size_t...Extents>
89  constexpr decltype(auto)
90  to_extents(const stdex::extents<IndexType, Extents...>& p)
91  {
92  constexpr std::size_t N = detail::derive_rank<stdex::extents<IndexType, Extents...>>::value;
93  static_assert(rank >= N);
94  if constexpr (rank > N)
95  return detail::derive_extents<rank>(p);
96  else
97  return p;
98  }
99 
100 
104  template<std::size_t rank, typename IndexType, std::size_t...Extents>
105  constexpr auto
107  {
108  constexpr std::size_t N = detail::derive_rank<stdex::extents<IndexType, Extents...>>::value;
109  static_assert(rank >= N);
110  if constexpr (rank > N)
111  return detail::derive_extents<rank>(std::move(p));
112  else
113  return std::move(p);
114  }
115 
116 
121 #ifdef __cpp_lib_constexpr_vector
122  template<pattern_collection P> requires
123  values::fixed_value_compares_with<collections::size_of<P>, stdex::dynamic_extent, &stdex::is_neq>
124 #else
125  template<typename P, std::enable_if_t<
126  pattern_collection<P> and
127  values::fixed_value_compares_with<collections::size_of<P>, stdex::dynamic_extent, &stdex::is_neq>, int> = 0>
128 #endif
129  constexpr auto
130  to_extents(P&& p)
131  {
133  }
134 
135 
136 }
137 
138 
139 #endif
Definition for pattern_collection.
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
The namespace for features relating to patterns::pattern object.
Definition: collection_compares_with.hpp:24
Definition: to_extents.hpp:29
Definition for patterns::get_dimension.
constexpr bool fixed
T has a value that is determinable at compile time.
Definition: fixed.hpp:65
Definition for collections::pattern_collection_element.
constexpr auto get_dimension(const Arg &arg)
Get the vector dimension of patterns::pattern Arg.
Definition: get_dimension.hpp:53
constexpr auto to_extents(P &&p)
Convert a pattern_collection to std::extents.
Definition: to_extents.hpp:78
Definition: extents.hpp:372