OpenKalman
mdspan-object.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-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 
16 #ifndef OPENKALMAN_INTERFACES_MDSPAN_OBJECT_TRAITS_HPP
17 #define OPENKALMAN_INTERFACES_MDSPAN_OBJECT_TRAITS_HPP
18 
19 #include "basics/basics.hpp"
24 
25 namespace OpenKalman::interface
26 {
31  template<typename T, typename Extents, typename LayoutPolicy, typename AccessorPolicy>
32  struct object_traits<stdex::mdspan<T, Extents, LayoutPolicy, AccessorPolicy>>
33  {
34  //private:
35 
36  template<typename>
37  struct is_diagonal_layout : std::false_type {};
38 
39  template<typename N, typename E>
40  struct is_diagonal_layout<layout_to_diagonal<N, E>> : std::true_type {};
41 
42  template<typename>
43  struct is_constant_accessor : std::false_type {};
44 
45  template<typename E>
46  struct is_constant_accessor<constant_accessor<E>> : std::true_type {};
47 
48  template<typename>
49  struct is_constant_diagonal_accessor : std::false_type {};
50 
51  template<typename E>
52  struct is_constant_diagonal_accessor<to_diagonal_accessor<constant_accessor<E>>> : std::true_type {};
53 
54  public:
55 
56  static const bool is_specialized = true;
57 
58 
59  template<typename M>
60  static constexpr decltype(auto)
61  get_mdspan(M&& m)
62  {
63  return std::forward<M>(m);
64  };
65 
66 
67  static constexpr triangle_type
69 
70 
74 #ifdef __cpp_concepts
75  template<typename M> requires
78 #else
79  template<typename M, std::enable_if_t<
82 #endif
83  static constexpr auto
84  get_constant(const M& m)
85  {
87  return m.data_handle();
88  else
89  return std::get<0>(m.data_handle());
90  }
91 
92  };
93 
94 }
95 
96 
97 #endif
static constexpr auto get_constant(const M &m)
If AccessorPolicy indicates that the mdspan is constant, return the constant value.
Definition: mdspan-object.hpp:84
Definition: basics.hpp:41
triangle_type
The type of a triangular matrix.
Definition: enumerations.hpp:26
Definition: to_diagonal_mdspan_policies.hpp:29
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
A diagonal matrix (both a lower-left and an upper-right triangular matrix).
Enumerations relating to linear algebra.
static const bool is_specialized
Identifies types for which object_traits is specialized.
Definition: object_traits.hpp:44
Definition: constant_mdspan_policies.hpp:96
Forward declaration of object_traits, which must be defined for all objects used in OpenKalman...
Definition: object_traits.hpp:38
Definition: to_diagonal_mdspan_policies.hpp:177
Basic definitions for OpenKalman as a whole.
decltype(auto) constexpr get_mdspan(T &&t)
Get the mdspan associated with indexible object T.
Definition: get_mdspan.hpp:35