OpenKalman
adjoint.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-2023 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_ADJOINT_HPP
17 #define OPENKALMAN_ADJOINT_HPP
18 
19 #include<complex>
20 
21 
22 namespace OpenKalman
23 {
28 #ifdef __cpp_concepts
29  template<indexible Arg> requires (max_tensor_order_v<Arg> <= 2)
30 #else
31  template<typename Arg, std::enable_if_t<indexible<Arg> and (max_tensor_order_v<Arg> <= 2), int> = 0>
32 #endif
33  constexpr decltype(auto) adjoint(Arg&& arg)
34  {
35  if constexpr (hermitian_matrix<Arg>)
36  {
37  return std::forward<Arg>(arg);
38  }
39  else if constexpr (diagonal_matrix<Arg> and square_shaped<Arg>)
40  {
41  return conjugate(std::forward<Arg>(arg));
42  }
43  else if constexpr (zero<Arg>)
44  {
45  return transpose(std::forward<Arg>(arg));
46  }
47  else if constexpr (constant_matrix<Arg>)
48  {
49  if constexpr (values::not_complex<constant_coefficient<Arg>>)
50  return transpose(std::forward<Arg>(arg));
51  else if constexpr (not has_dynamic_dimensions<Arg> and index_dimension_of_v<Arg, 0> == index_dimension_of_v<Arg, 1>)
52  return conjugate(std::forward<Arg>(arg));
53  else
54  {
55  constexpr std::make_index_sequence<std::max({index_count_v<Arg>, 2_uz}) - 2_uz> seq;
56  return internal::transpose_constant(values::conj(constant_coefficient{arg}), std::forward<Arg>(arg), seq);
57  }
58  }
59  else if constexpr (interface::adjoint_defined_for<Arg, Arg&&>)
60  {
61  return interface::library_interface<std::decay_t<Arg>>::adjoint(std::forward<Arg>(arg));
62  }
63  else
64  {
65  return transpose(conjugate(std::forward<Arg>(arg)));
66  }
67  }
68 
69 } // namespace OpenKalman
70 
71 #endif //OPENKALMAN_ADJOINT_HPP
The root namespace for OpenKalman.
Definition: basics.hpp:34