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-2025 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 "conjugate.hpp"
20 #include "transpose.hpp"
21 
22 namespace OpenKalman
23 {
28 #ifdef __cpp_concepts
29  template<std::size_t indexa = 0, std::size_t indexb = 1, indexible Arg> requires (indexa < indexb)
30 #else
31  template<std::size_t indexa = 0, std::size_t indexb = 1, typename Arg, std::enable_if_t<
32  indexible<Arg> and (indexa < indexb), int> = 0>
33 #endif
34  constexpr decltype(auto)
35  adjoint(Arg&& arg)
36  {
37  if constexpr (hermitian_matrix<Arg>)
38  {
39  return std::forward<Arg>(arg);
40  }
41  else if constexpr ((diagonal_matrix<Arg> or constant_object<Arg>) and
43  {
44  return conjugate(std::forward<Arg>(arg));
45  }
47  {
48  return transpose(std::forward<Arg>(arg));
49  }
50  else if constexpr (indexb == 1 and interface::matrix_adjoint_defined_for<Arg&&>)
51  {
53  }
54  else if constexpr (interface::adjoint_defined_for<Arg&&, indexa, indexb>)
55  {
56  return interface::library_interface<stdex::remove_cvref_t<Arg>>::template adjoint<indexa, indexb>(std::forward<Arg>(arg));
57  }
58  else if constexpr (std::is_lvalue_reference_v<Arg> and index_count_v<Arg> <= 2)
59  {
60  return adjoint(get_mdspan(arg));
61  }
62  else
63  {
64  return transpose(conjugate(std::forward<Arg>(arg)));
65  }
66  }
67 
68 }
69 
70 #endif
constexpr auto get_mdspan(T &t)
Get the coordinates::pattern_collection associated with indexible object T.
Definition: get_mdspan.hpp:35
decltype(auto) constexpr conjugate(Arg &&arg)
Take the complex conjugate of an indexible object.
Definition: conjugate.hpp:44
constexpr bool complex
T is a value that reduces to std::complex or a custom complex type.
Definition: complex.hpp:47
constexpr bool not_complex
T is a value in which either its type is not complex or its imaginary component is 0...
Definition: not_complex.hpp:48
Definition of transpose function.
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 transpose(Arg &&arg)
Swap any two indices of an indexible_object.
Definition: transpose.hpp:163
constexpr bool size_compares_with
T and U are sizes that compare in a particular way based on parameter comp.
Definition: size_compares_with.hpp:98
The dimension of an index for a matrix, expression, or array.
Definition: index_dimension_of.hpp:35
The static constant value of an indexible object, if it exists.
Definition: constant_value_of.hpp:31
decltype(auto) constexpr adjoint(Arg &&arg)
Take the conjugate-transpose of an indexible_object.
Definition: adjoint.hpp:35
Definition of conjugate function.
typename element_type_of< T >::type element_type_of_t
helper template for element_type_of.
Definition: element_type_of.hpp:54