OpenKalman
conjugate.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_CONJUGATE_HPP
17 #define OPENKALMAN_CONJUGATE_HPP
18 
19 #include<complex>
20 
21 
22 namespace OpenKalman
23 {
28 #ifdef __cpp_concepts
29  template<indexible Arg>
30 #else
31  template<typename Arg, std::enable_if_t<indexible<Arg>, int> = 0>
32 #endif
33  constexpr decltype(auto) conjugate(Arg&& arg)
34  {
35  if constexpr (not values::complex<scalar_type_of_t<Arg>> or zero<Arg> or identity_matrix<Arg>)
36  {
37  return std::forward<Arg>(arg);
38  }
39  else if constexpr (constant_matrix<Arg>)
40  {
42  return std::forward<Arg>(arg);
43  else
44  return make_constant(values::conj(constant_coefficient{arg}), std::forward<Arg>(arg));
45  }
46  else if constexpr (constant_diagonal_matrix<Arg>)
47  {
49  return std::forward<Arg>(arg);
50  else
52  diagonal_of(std::forward<Arg>(arg))));
53  }
54  else if constexpr (diagonal_matrix<Arg>)
55  {
56  return to_diagonal(conjugate(diagonal_of(std::forward<Arg>(arg))));
57  }
58  else
59  {
60  return interface::library_interface<std::decay_t<Arg>>::conjugate(std::forward<Arg>(arg));
61  }
62  }
63 
64 } // namespace OpenKalman
65 
66 #endif //OPENKALMAN_CONJUGATE_HPP
decltype(auto) constexpr conjugate(Arg &&arg)
Take the conjugate of a matrix.
Definition: conjugate.hpp:33
typename scalar_type_of< T >::type scalar_type_of_t
helper template for scalar_type_of.
Definition: scalar_type_of.hpp:54
constexpr bool complex
T is a values::value that reduces to std::complex or a custom complex type.
Definition: complex.hpp:46
constexpr bool not_complex
T is a values::value in which either its type is not a values::complex or its imaginary component is ...
Definition: not_complex.hpp:47
decltype(auto) constexpr to_diagonal(Arg &&arg)
Convert an indexible object into a diagonal matrix.
Definition: to_diagonal.hpp:32
The constant associated with T, assuming T is a constant_matrix.
Definition: constant_coefficient.hpp:36
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:37
The constant associated with T, assuming T is a constant_diagonal_matrix.
Definition: constant_diagonal_coefficient.hpp:32
constexpr auto conj(const Arg &arg)
A constexpr function for the complex conjugate of a (complex) number.
Definition: conj.hpp:39
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:33
constexpr auto make_constant(C &&c, Descriptors &&descriptors)
Make a constant object based on a particular library object.
Definition: make_constant.hpp:37