OpenKalman
nullary.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) 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_EIGEN_NULLARYFUNCTORTRAITS_HPP
17 #define OPENKALMAN_EIGEN_NULLARYFUNCTORTRAITS_HPP
18 
19 #include <type_traits>
20 
21 namespace OpenKalman::Eigen3
22 {
23  // Default nullary traits, if NullaryOp is not specifically matched.
24  template<typename NullaryOp, typename PlainObjectType>
25  struct NullaryFunctorTraits
26  {
27  template<typename Arg>
28  static constexpr auto get_constant(const Arg& arg) { return arg.functor()(); }
29 
30  template<typename Arg>
31  static constexpr auto get_constant_diagonal(const Arg&) { return std::monostate {}; }
32 
33  template<TriangleType t>
34  static constexpr bool is_triangular = false;
35 
36  static constexpr bool is_hermitian = false;
37  };
38 
39 
40  template<typename Scalar, typename PlainObjectType>
41  struct NullaryFunctorTraits<Eigen::internal::scalar_identity_op<Scalar>, PlainObjectType>
42  {
43  template<typename Arg>
44  static constexpr auto get_constant(const Arg&) { return std::monostate {}; }
45 
46  template<typename Arg>
47  static constexpr auto get_constant_diagonal(const Arg&) { return values::Fixed<Scalar, 1>{}; }
48 
49  template<TriangleType t>
50  static constexpr bool is_triangular = true;
51 
52  static constexpr bool is_hermitian = true;
53  };
54 
55 
56  template<typename Scalar, typename PlainObjectType>
57  struct NullaryFunctorTraits<Eigen::internal::linspaced_op<Scalar>, PlainObjectType>
58  {
59  template<typename Arg>
60  static constexpr auto get_constant(const Arg&) { return std::monostate {}; }
61 
62  template<typename Arg>
63  static constexpr auto get_constant_diagonal(const Arg&) { return std::monostate {}; }
64 
65  template<TriangleType t>
66  static constexpr bool is_triangular = false;
67 
68  static constexpr bool is_hermitian = false;
69  };
70 
71 
72  template<typename Scalar, typename PlainObjectType>
73  struct NullaryFunctorTraits<Eigen::internal::scalar_constant_op<Scalar>, PlainObjectType>
74  {
75  template<typename Arg>
76  static constexpr auto get_constant(const Arg& arg) { return arg.functor()(); }
77 
78  template<typename Arg>
79  static constexpr auto get_constant_diagonal(const Arg&) { return std::monostate {}; }
80 
81  template<TriangleType t>
82  static constexpr bool is_triangular = false;
83 
84  static constexpr bool is_hermitian = not values::complex<Scalar>;
85  };
86 
87 } // namespace OpenKalman::Eigen3
88 
89 #endif //OPENKALMAN_EIGEN_NULLARYFUNCTORTRAITS_HPP
Definition: eigen-forward-declarations.hpp:32
Definition: eigen-comma-initializers.hpp:20
Definition: eigen-forward-declarations.hpp:22
Definition: Fixed.hpp:36