OpenKalman
packed_triangle_mdspan_policies.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) 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_PACKED_TRIANGLE_MDSPAN_POLICIES_HPP
18 #define OPENKALMAN_PACKED_TRIANGLE_MDSPAN_POLICIES_HPP
19 
20 #include <iostream>
21 #include "patterns/patterns.hpp"
22 
23 namespace OpenKalman::interface
24 {
29  template<typename Triangle, typename StorageOrder>
31  {
32  template<class Extents>
33  struct mapping
34  {
35  using extents_type = Extents;
36  using index_type = typename extents_type::index_type;
37  using size_type = typename extents_type::size_type;
38  using rank_type = typename extents_type::rank_type;
40 
41  constexpr explicit
42  mapping(const extents_type& e) : extents_(e) {}
43 
44  constexpr const extents_type&
45  extents() const noexcept { return extents_; }
46 
47 #ifdef __cpp_concepts
48  constexpr index_type
49  operator() () const requires (extents_type::rank() == 0)
50 #else
51  template<bool Enable = true, std::enable_if_t<Enable and (extents_type::rank() == 0), int> = 0>
52  constexpr index_type
53  operator() () const
54 #endif
55  {
56  return access_with_padded_indices();
57  }
58 
59 #ifdef __cpp_concepts
60  constexpr index_type
61  operator() (
62  std::convertible_to<index_type> auto i0,
63  std::convertible_to<index_type> auto...is) const requires (1 + sizeof...(is) == extents_type::rank())
64 #else
65  template<typename IndexType0, typename...IndexTypes, std::enable_if_t<
66  std::is_convertible_v<IndexType0, index_type> and
67  (... and std::is_convertible_v<IndexTypes, index_type>) and
68  (1 + sizeof...(IndexTypes) == extents_type::rank()), int> = 0>
69  constexpr index_type
70  operator() (IndexType0 i0, IndexTypes...is) const
71 #endif
72  {
73  return access_with_padded_indices(i0, i0, is...);
74  }
75 
76  constexpr index_type
77  required_span_size() const noexcept { return nested_mapping_.required_span_size(); }
78 
79  static constexpr bool is_always_unique() noexcept { return nested_mapping_type::is_always_unique(); }
80 
81  static constexpr bool
82  is_always_exhaustive() noexcept
83  {
84  if constexpr (not nested_mapping_type::is_always_exhaustive()) return false;
85  else if constexpr (nested_extents_type::rank() == 0) return true;
86  else if constexpr (nested_extents_type::rank() == 1) return nested_extents_type::static_extent(0) == 1;
87  else return nested_extents_type::static_extent(0) == 1 and nested_extents_type::static_extent(1) == 1;
88  }
89 
90  static constexpr bool
91  is_always_strided() noexcept { return nested_mapping_type::is_always_strided(); }
92 
93  constexpr bool
94  is_unique() const { return nested_mapping_type::is_unique(); }
95 
96  constexpr bool
97  is_exhaustive() const
98  {
99  if (not nested_mapping_type::is_exhaustive()) return false;
100  if constexpr (nested_extents_type::rank() == 0) return true;
101  else if constexpr (nested_extents_type::rank() == 1) return nested_mapping_.extents().extent(0) == 1;
102  else return nested_mapping_.extents().extent(0) == 1 and nested_mapping_.extents().extent(1) == 1;
103  }
104 
105  constexpr bool
106  is_strided() const { return nested_mapping_type::is_strided(); }
107 
108  constexpr index_type
109  stride(std::size_t r) const
110  {
111  if (r == 0) return nested_mapping_.stride(0) + nested_mapping_.stride(1);
112  return nested_mapping_.stride(r - 1);
113  }
114 
115  template<class OtherExtents>
116  friend constexpr bool
117  operator==(const mapping& lhs, const mapping<OtherExtents>& rhs) noexcept
118  {
119  return patterns::compare_pattern_collections(lhs.extents(), rhs.extents());
120  }
121 
122  private:
123 
124  extents_type extents_;
125 
126  };
127  };
128 
129 
130 }
131 
132 #endif
Definition: basics.hpp:41
Definition: packed_triangle_mdspan_policies.hpp:33
constexpr auto compare_pattern_collections(const A &a, const B &b)
Compare each element of two pattern_collection objects lexicographically.
Definition: compare_pattern_collections.hpp:137
Definition: packed_triangle_mdspan_policies.hpp:30