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-2024 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 namespace OpenKalman
20 {
26 #ifdef __cpp_concepts
27  template<indexible Arg> requires (index_count_v<Arg> == dynamic_size) or (index_count_v<Arg> <= 2)
28  constexpr indexible decltype(auto)
29 #else
30  template<typename Arg, std::enable_if_t<(index_count_v<Arg> == dynamic_size or index_count_v<Arg> <= 2), int> = 0>
31  constexpr decltype(auto)
32 #endif
33  diagonal_of(Arg&& arg)
34  {
35  if constexpr (diagonal_adapter<Arg>)
36  {
37  return nested_object(std::forward<Arg>(arg));
38  }
39  else if constexpr (diagonal_adapter<Arg, 1>)
40  {
41  return transpose(nested_object(std::forward<Arg>(arg)));
42  }
43  else if constexpr (one_dimensional<Arg>)
44  {
45  return std::forward<Arg>(arg);
46  }
47  else if constexpr (constant_matrix<Arg>)
48  {
49  auto ds = all_vector_space_descriptors(std::forward<Arg>(arg));
50  if constexpr (pattern_tuple<decltype(ds)>)
51  {
52  return internal::make_constant_diagonal_from_descriptors<Arg>(
53  constant_coefficient {std::forward<Arg>(arg)},
54  std::tuple_cat(ds, std::tuple{coordinates::Axis{}, coordinates::Axis{}}));
55  }
56  else
57  {
58  return internal::make_constant_diagonal_from_descriptors<Arg>(constant_coefficient {std::forward<Arg>(arg)}, ds);
59  }
60  }
61  else if constexpr (constant_diagonal_matrix<Arg>)
62  {
63  auto ds = all_vector_space_descriptors(std::forward<Arg>(arg));
64  if constexpr (pattern_tuple<decltype(ds)>)
65  {
66  return internal::make_constant_diagonal_from_descriptors<Arg>(
67  constant_diagonal_coefficient {std::forward<Arg>(arg)},
68  std::tuple_cat(all_vector_space_descriptors(std::forward<Arg>(arg)), std::tuple{coordinates::Axis{}, coordinates::Axis{}}));
69  }
70  else
71  {
72  return internal::make_constant_diagonal_from_descriptors<Arg>(constant_diagonal_coefficient {std::forward<Arg>(arg)}, ds);
73  }
74  }
75  else
76  {
77  return interface::library_interface<std::decay_t<Arg>>::diagonal_of(std::forward<Arg>(arg));
78  }
79  }
80 
81 
82 } // namespace OpenKalman
83 
84 #endif //OPENKALMAN_DIAGONAL_OF_HPP
constexpr bool indexible
T is a generalized tensor type.
Definition: indexible.hpp:32
The root namespace for OpenKalman.
Definition: basics.hpp:34
constexpr std::size_t dynamic_size
A constant indicating that a size or index is dynamic.
Definition: global-definitions.hpp:33