OpenKalman
diagonal_of.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-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_DIAGONAL_OF_HPP
17 #define OPENKALMAN_DIAGONAL_OF_HPP
18 
19 #include "patterns/patterns.hpp"
27 #include "linear-algebra/functions/internal/make_wrapped_mdspan.hpp"
29 
30 namespace OpenKalman
31 {
37 #ifdef __cpp_concepts
38  template<indexible Arg>
39  constexpr indexible decltype(auto)
40 #else
41  template<typename Arg, std::enable_if_t<indexible<Arg>, int> = 0>
42  constexpr decltype(auto)
43 #endif
44  diagonal_of(Arg&& arg)
45  {
47  {
48  return std::forward<Arg>(arg);
49  }
50  else if constexpr (interface::diagonal_of_defined_for<Arg&&>)
51  {
53  }
54  else
55  {
57  if constexpr (constant_object<Arg> or constant_diagonal_object<Arg>)
58  {
59  return make_constant(constant_value(arg), std::move(p));
60  }
61  else
62  {
63  decltype(auto) n = get_mdspan(arg);
64  using N = std::decay_t<decltype(n)>;
65  using nested_extents_type = typename N::extents_type;
66  using nested_layout = typename N::layout_type;
67 
69  using extents_type = decltype(patterns::to_extents(p));
70  using mapping_type = typename layout_type::template mapping<extents_type>;
71  auto map = mapping_type {n.mapping(), patterns::to_extents(p)};
72 
73  return internal::make_wrapped_mdspan(
74  std::forward<Arg>(arg),
76  std::move(map),
77  n.accessor(),
78  std::move(p));
79  }
80  }
81  }
82 
83 
84 }
85 
86 #endif
Definition: language-features.hpp:228
Definitions for attach_patterns.
constexpr bool indexible
T is a multidimensional array type.
Definition: indexible.hpp:32
decltype(auto) constexpr get_pattern_collection(T &&t)
Get the patterns::pattern_collection associated with indexible object T.
Definition: get_pattern_collection.hpp:36
A structure representing the dimensions associated with of a particular index.
Definition: Dimensions.hpp:42
Definition for diagonal_matrix.
constexpr bool compares_with_pattern_collection
Compares the associated pattern collection of indexible T with pattern_collection D...
Definition: compares_with_pattern_collection.hpp:50
The root namespace for OpenKalman.
Definition: basics.hpp:34
An interface to various routines from the linear algebra library associated with indexible object T...
Definition: library_interface.hpp:42
decltype(auto) constexpr diagonal_of(Arg &&arg)
Extract a column vector (or column slice for rank>2 tensors) comprising the diagonal elements...
Definition: diagonal_of.hpp:44
Definition of get_mdspan function.
constexpr auto make_constant(C c, P &&p)
Make an indexible object in which every element is a constant value.
Definition: make_constant.hpp:41
Definition for pattern_collection_for.
Definition: diagonal_of_mdspan_policies.hpp:30
constexpr auto constant_value(T &&t)
The constant value associated with a constant_object or constant_diagonal_object. ...
Definition: constant_value.hpp:37
constexpr detail::diagonal_of_adapter diagonal_of
A RangeAdapterObject that converts one pattern_collection to another corresponding to the diagonal_ma...
Definition: diagonal_of.hpp:153
Definition for indexible.
Definition for compares_with_pattern_collection.
Definitions for make_constant.
constexpr auto to_extents(P &&p)
Convert a pattern_collection to std::extents.
Definition: to_extents.hpp:78
decltype(auto) constexpr get_mdspan(T &&t)
Get the mdspan associated with indexible object T.
Definition: get_mdspan.hpp:35