OpenKalman
diagonal_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) 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 
17 #ifndef OPENKALMAN_DIAGONAL_MDSPAN_POLICIES_HPP
18 #define OPENKALMAN_DIAGONAL_MDSPAN_POLICIES_HPP
19 
20 #include "basics/basics.hpp"
21 
22 namespace OpenKalman::internal
23 {
29  {
30  template<class Extents>
31  struct mapping
32  {
33  using extents_type = Extents;
34  using index_type = typename extents_type::index_type;
35  using size_type = typename extents_type::size_type;
36  using rank_type = typename extents_type::rank_type;
38 
39  constexpr explicit
40  mapping(const extents_type& e) : extents_(e) {}
41 
42  constexpr const extents_type&
43  extents() const noexcept { return extents_; }
44 
45  constexpr index_type
46 #ifdef __cpp_concepts
47  operator() (std::convertible_to<index_type> auto...i) const
48 #else
49  template<typename...IndexTypes, std::enable_if_t<
50  (... and std::is_convertible_v<IndexTypes, index_type>), int> = 0>
51  operator() (IndexTypes...i) const
52 #endif
53  {
54  return 0;
55  }
56 
57  constexpr index_type
58  required_span_size() const noexcept { return 0; }
59 
60  static constexpr bool is_always_unique() noexcept { return false; }
61  static constexpr bool is_always_exhaustive() noexcept { return false; }
62  static constexpr bool is_always_strided() noexcept { return false; }
63 
64  constexpr bool is_unique() const { return false; }
65  constexpr bool is_exhaustive() const { return false; }
66  constexpr bool is_strided() const { return false; }
67 
68  constexpr index_type
69  stride(std::size_t) const { return 0; }
70 
71  template<class OtherExtents>
72  friend constexpr bool
73  operator==(const mapping& lhs, const mapping<OtherExtents>& rhs) noexcept
74  {
75  return lhs.extents() == rhs.extents();
76  }
77 
78  private:
79 
80  extents_type extents_;
81 
82  };
83  };
84 
85 
91  template<typename ElementType>
94  using element_type = ElementType;
95  using reference = const element_type&;
96  using data_handle_type = const element_type*;
97 
98  constexpr accessor_diagonal() noexcept = default;
99 
100 #ifdef __cpp_concepts
101  template<stdex::convertible_to<element_type> OtherElementType>
102 #else
103  template<typename OtherElementType, std::enable_if_t<stdex::convertible_to<OtherElementType, element_type>, int> = 0>
104 #endif
105  constexpr accessor_diagonal(const accessor_diagonal<OtherElementType>& other) noexcept
106  : element_ {other.element_} {}
107 
108 #ifdef __cpp_concepts
109  template<stdex::convertible_to<element_type> OtherElementType>
110 #else
111  template<typename OtherElementType, std::enable_if_t<stdex::convertible_to<OtherElementType, element_type>, int> = 0>
112 #endif
113  constexpr accessor_diagonal(accessor_diagonal<OtherElementType>&& other) noexcept
114  : element_ {std::move(other).element_} {}
115 
116  constexpr accessor_diagonal(ElementType e) : element_ {std::move(e)} {}
117 
118  constexpr reference
119  access(data_handle_type p, std::size_t i) const noexcept { return element_; }
120 
121  constexpr data_handle_type
122  offset(data_handle_type p, std::size_t i) const noexcept { return &element_; }
123 
124  constexpr data_handle_type
125  data_handle() const noexcept { return &element_; }
126 
127  private:
128 
129  nested_mapping_type nested_mapping_;
130  const ElementType element_;
131 
132  template<typename OtherElementType>
133  friend struct accessor_diagonal;
134 
135  };
136 
137 
138 }
139 
140 #endif
Definition: diagonal_mdspan_policies.hpp:31
Definition: diagonal_mdspan_policies.hpp:92
decltype(auto) constexpr access(Arg &&arg, const Indices &indices)
Access a component of an indexible object at a given set of indices.
Definition: access.hpp:74
Definition: diagonal_mdspan_policies.hpp:28
Basic definitions for OpenKalman as a whole.
Definition: basics.hpp:48