OpenKalman
Product.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) 2019-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_TRAITS_PRODUCT_HPP
17 #define OPENKALMAN_EIGEN_TRAITS_PRODUCT_HPP
18 
19 #include <type_traits>
20 
21 
22 namespace OpenKalman::interface
23 {
24  template<typename LhsType, typename RhsType, int Option>
25  struct object_traits<Eigen::Product<LhsType, RhsType, Option>>
26  : Eigen3::object_traits_base<Eigen::Product<LhsType, RhsType, Option>>
27  {
28  private:
29 
30  using Xpr = Eigen::Product<LhsType, RhsType, Option>;
32 
33  public:
34 
35  using typename Base::scalar_type;
36 
37 
38  // nested_object not defined
39 
40 
41  template<typename Arg>
42  static constexpr auto get_constant(const Arg& arg)
43  {
44  if constexpr (zero<LhsType>)
45  {
46  return constant_value{arg.lhs()};
47  }
48  else if constexpr (zero<RhsType>)
49  {
50  return constant_value{arg.rhs()};
51  }
52  else if constexpr (constant_diagonal_matrix<LhsType> and constant_matrix<RhsType>)
53  {
54  return values::operation(
55  std::multiplies<scalar_type>{},
56  constant_diagonal_value{arg.lhs()},
57  constant_value{arg.rhs()});
58  }
59  else if constexpr (constant_matrix<LhsType> and constant_diagonal_matrix<RhsType>)
60  {
61  return values::operation(
62  std::multiplies<scalar_type>{},
63  constant_value{arg.lhs()},
64  constant_diagonal_value{arg.rhs()});
65  }
66  else
67  {
68  constexpr auto dim = dynamic_dimension<LhsType, 1> ? index_dimension_of_v<RhsType, 0> : index_dimension_of_v<LhsType, 1>;
69  if constexpr (dim == stdex::dynamic_extent)
70  {
71  return values::operation(
72  std::multiplies<scalar_type>{},
73  get_index_dimension_of<1>(arg.lhs()),
74  values::operation(std::multiplies<scalar_type>{}, constant_value{arg.lhs()}, constant_value{arg.rhs()}));
75  }
76  else if constexpr (values::fixed<constant_value<LhsType>>)
77  {
78  return values::operation(
79  std::multiplies<scalar_type>{},
80  values::operation(std::multiplies<scalar_type>{}, std::integral_constant<std::size_t, dim>{}, constant_value{arg.lhs()}),
81  constant_value{arg.rhs()});
82  }
83  else
84  {
85  return values::operation(
86  std::multiplies<scalar_type>{},
87  values::operation(std::multiplies<scalar_type>{}, std::integral_constant<std::size_t, dim>{}, constant_value{arg.rhs()}),
88  constant_value{arg.lhs()});
89  }
90  }
91  }
92 
93 
94  template<typename Arg>
95  static constexpr auto get_constant_diagonal(const Arg& arg)
96  {
97  return values::operation(std::multiplies<scalar_type>{},
98  constant_diagonal_value{arg.lhs()}, constant_diagonal_value{arg.rhs()});
99  }
100 
101 
102  template<triangle_type t>
103  static constexpr bool triangle_type_value = triangular_matrix<LhsType, t> and triangular_matrix<RhsType, t>;
104 
105 
106  static constexpr bool is_triangular_adapter = false;
107 
108 
110  static constexpr bool is_hermitian =
111  (constant_diagonal_matrix<LhsType> and
112  (not values::complex<scalar_type_of_t<LhsType>> or values::not_complex<constant_diagonal_value<LhsType>>) and
114  (constant_diagonal_matrix<RhsType> and
115  (not values::complex<scalar_type_of_t<RhsType>> or values::not_complex<constant_diagonal_value<RhsType>>) and
117 
118  };
119 
120 
121 }
122 
123 #endif
Definition: basics.hpp:41
applicability
The applicability of a concept, trait, or restraint.
Definition: constants.hpp:35
The concept, trait, or restraint is permitted, but whether it applies is not necessarily known at com...
constexpr bool complex
T is a value that reduces to std::complex or a custom complex type.
Definition: complex.hpp:47
Definition: eigen-comma-initializers.hpp:20
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
constexpr bool hermitian_matrix
Specifies that a type is a hermitian matrix.
Definition: hermitian_matrix.hpp:59
Definition: object_traits.hpp:38
Trait object providing get and set routines.
Definition: eigen-forward-declarations.hpp:502
constexpr auto constant_value(T &&t)
The constant value associated with a constant_object or constant_diagonal_object. ...
Definition: constant_value.hpp:37
constexpr bool fixed
T is a value that is determinable at compile time.
Definition: fixed.hpp:66
constexpr auto operation(Operation &&op, Args &&...args)
A potentially constant-evaluated operation involving some number of values.
Definition: operation.hpp:98