OpenKalman
get_pattern_collection.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) 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 
16 #ifndef OPENKALMAN_GET_PATTERN_COLLECTION_HPP
17 #define OPENKALMAN_GET_PATTERN_COLLECTION_HPP
18 
19 #include "coordinates/coordinates.hpp"
23 
24 namespace OpenKalman
25 {
26  namespace detail
27  {
28  template<std::size_t i, typename Mdspan>
29  static constexpr auto
30  get_extent(const Mdspan& m)
31  {
32  constexpr auto ex = Mdspan::static_extent(i);
33  if constexpr (ex == stdex::dynamic_extent)
34  return m.extent(i);
35  else
36  return std::integral_constant<std::size_t, ex>{};
37  }
38 
39  template<typename Mdspan, std::size_t...i>
40  static constexpr auto
41  get_pattern_collection_impl(const Mdspan& m, std::index_sequence<i...>)
42  {
43  return std::tuple {get_extent<i>(m)...};
44  }
45 
46  }
47 
48 
52 #ifdef __cpp_concepts
53  template<indexible T>
54  constexpr coordinates::pattern_collection decltype(auto)
55 #else
56  template<typename T, std::enable_if_t<indexible<T>, int> = 0>
57  constexpr decltype(auto)
58 #endif
60  {
61  using Td = stdex::remove_cvref_t<T>;
62  if constexpr (interface::get_pattern_collection_defined_for<Td>)
63  {
64  auto pat = stdex::invoke(interface::object_traits<Td>::get_pattern_collection, std::forward<T>(t));
65  static_assert(not values::size_compares_with<coordinates::dimension_of<decltype(pat)>, index_count<T>, &stdex::is_neq>);
66  return pat;
67  }
68  else
69  {
70  return detail::get_pattern_collection_impl(get_mdspan(t), std::make_index_sequence<index_count_v<T>>{});
71  }
72  }
73 
74 }
75 
76 #endif
constexpr auto get_mdspan(T &t)
Get the coordinates::pattern_collection associated with indexible object T.
Definition: get_mdspan.hpp:35
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 coordinates::pattern.
Definition: dimension_of.hpp:36
The root namespace for OpenKalman.
Definition: basics.hpp:34
Definition: object_traits.hpp:38
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.
constexpr bool pattern_collection
An object describing a collection of /ref pattern objects.
Definition: pattern_collection.hpp:65
Definition: trait_backports.hpp:64
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...