OpenKalman
get_index_pattern.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) 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_INDEX_PATTERN_HPP
17 #define OPENKALMAN_GET_INDEX_PATTERN_HPP
18 
19 #include "coordinates/coordinates.hpp"
25 
26 namespace OpenKalman
27 {
33 #ifdef __cpp_concepts
34  template<indexible T, values::index I = std::integral_constant<std::size_t, 0>>
35  constexpr coordinates::pattern decltype(auto)
36 #else
37  template<typename T, typename I = std::integral_constant<std::size_t, 0>,
38  std::enable_if_t<indexible<T> and values::index<I>, int> = 0>
39  constexpr decltype(auto)
40 #endif
41  get_index_pattern(T&& t, I i = {})
42  {
43  if constexpr (values::size_compares_with<I, index_count<T>, &stdex::is_gteq>)
44  {
46  }
47  else if constexpr (interface::get_pattern_collection_defined_for<std::remove_reference_t<T>>)
48  {
49  decltype(auto) pat = get_pattern_collection(std::forward<T>(t));
50  using Pat = decltype(pat);
51  if constexpr (values::size_compares_with<I, collections::size_of<Pat>, &stdex::is_lt>)
52  return collections::get_element(std::forward<Pat>(pat), i);
53  else if constexpr (values::size_compares_with<I, collections::size_of<Pat>, &stdex::is_gteq>)
55  else if (i < collections::get_size(pat))
56  return coordinates::Any {collections::get_element(std::forward<Pat>(pat), i)};
57  else
58  return coordinates::Any {1_uz};
59  }
60  else if constexpr (values::size_compares_with<I, index_count<T>, &stdex::is_lt>)
61  {
62  constexpr auto ex = std::decay_t<decltype(get_mdspan(t))>::static_extent(i);
63  if constexpr (ex == stdex::dynamic_extent)
64  return get_mdspan(t).extent(static_cast<std::size_t>(i));
65  else
67  }
68  else if (i < count_indices(t))
69  {
70  return get_mdspan(t).extent(static_cast<std::size_t>(i));
71  }
72  else
73  {
74  return 1_uz;
75  }
76  }
77 
78 
82 #ifdef __cpp_concepts
83  template<std::size_t i, indexible T>
84  constexpr coordinates::pattern auto
85 #else
86  template<std::size_t i, typename T, std::enable_if_t<indexible<T>, int> = 0>
87  constexpr auto
88 #endif
90  {
91  return get_index_pattern(t, std::integral_constant<std::size_t, i>{});
92  }
93 
94 }
95 
96 #endif
constexpr auto get_mdspan(T &t)
Get the coordinates::pattern_collection associated with indexible object T.
Definition: get_mdspan.hpp:35
constexpr auto count_indices(const T &)
Get the number of indices necessary to address all the components of an indexible object...
Definition: count_indices.hpp:51
constexpr bool pattern
An object describing the set of coordinates associated with a tensor index.
Definition: pattern.hpp:31
decltype(auto) constexpr get_pattern_collection(T &&t)
Get the coordinates::pattern_collection associated with indexible object T.
Definition: get_pattern_collection.hpp:59
The size of a sized object (including a collection).
Definition: size_of.hpp:33
Definition of count_indices.
The root namespace for OpenKalman.
Definition: basics.hpp:34
Definition of get_mdspan function.
constexpr bool size_compares_with
T and U are sizes that compare in a particular way based on parameter comp.
Definition: size_compares_with.hpp:98
Definition for index_count.
A structure representing the dimensions associated with of a particular index.
Definition: Dimensions.hpp:42
Definition of get_pattern_collection function.
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 get_index_pattern(T &&t, I i={})
Get the coordinates::pattern associated with indexible object T at a given index. ...
Definition: get_index_pattern.hpp:41
The minimum number of indices needed to access all the components of an object (i.e., the rank or order).
Definition: index_count.hpp:34
Concepts for testing whether object_traits or library_interface definitions exist for a particular ob...
constexpr auto get_size(Arg &&arg)
Get the size of a sized object (e.g, a collection)
Definition: get_size.hpp:188
Definition: Any.hpp:42