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 
20 
21 namespace OpenKalman
22 {
29 #ifdef __cpp_concepts
30  template<indexible Arg> requires (index_count_v<Arg> == stdex::dynamic_extent) or (index_count_v<Arg> <= 2)
31  constexpr indexible decltype(auto)
32 #else
33  template<typename Arg, std::enable_if_t<(index_count_v<Arg> == stdex::dynamic_extent or index_count_v<Arg> <= 2), int> = 0>
34  constexpr decltype(auto)
35 #endif
36  diagonal_of(Arg&& arg)
37  {
38  if constexpr (diagonal_matrix<Arg> and internal::has_nested_vector<Arg>)
39  {
40  return nested_object(std::forward<Arg>(arg));
41  }
42  else if constexpr (diagonal_matrix<Arg> and internal::has_nested_vector<Arg, 1>)
43  {
44  return transpose(nested_object(std::forward<Arg>(arg)));
45  }
46  else if constexpr (one_dimensional<Arg>)
47  {
48  return std::forward<Arg>(arg);
49  }
50  else if constexpr (constant_object<Arg>)
51  {
52  auto ds = get_pattern_collection(std::forward<Arg>(arg));
53  if constexpr (pattern_collection<decltype(ds)>)
54  {
55  return internal::make_constant_diagonal_from_descriptors<Arg>(
56  constant_value {std::forward<Arg>(arg)},
57  std::tuple_cat(ds, std::tuple{coordinates::Axis{}, coordinates::Axis{}}));
58  }
59  else
60  {
61  return internal::make_constant_diagonal_from_descriptors<Arg>(constant_value {std::forward<Arg>(arg)}, ds);
62  }
63  }
64  else if constexpr (constant_diagonal_object<Arg>)
65  {
66  auto ds = get_pattern_collection(std::forward<Arg>(arg));
67  if constexpr (pattern_collection<decltype(ds)>)
68  {
69  return internal::make_constant_diagonal_from_descriptors<Arg>(
70  constant_diagonal_value {std::forward<Arg>(arg)},
71  std::tuple_cat(get_pattern_collection(std::forward<Arg>(arg)), std::tuple{coordinates::Axis{}, coordinates::Axis{}}));
72  }
73  else
74  {
75  return internal::make_constant_diagonal_from_descriptors<Arg>(constant_diagonal_value {std::forward<Arg>(arg)}, ds);
76  }
77  }
78  else
79  {
80  return interface::library_interface<stdex::remove_cvref_t<Arg>>::diagonal_of(std::forward<Arg>(arg));
81  }
82  }
83 
84 
85 }
86 
87 #endif
Definition for constant_object.
constexpr bool indexible
T is a multidimensional array type.
Definition: indexible.hpp:32
The root namespace for OpenKalman.
Definition: basics.hpp:34