OpenKalman
Replicate.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_REPLICATE_HPP
17 #define OPENKALMAN_EIGEN_TRAITS_REPLICATE_HPP
18 
19 #include <type_traits>
20 
21 
22 namespace OpenKalman::interface
23 {
24  template<typename MatrixType, int RowFactor, int ColFactor>
25  struct indexible_object_traits<Eigen::Replicate<MatrixType, RowFactor, ColFactor>>
26  : Eigen3::indexible_object_traits_base<Eigen::Replicate<MatrixType, RowFactor, ColFactor>>
27  {
28  private:
29 
30  using Xpr = Eigen::Replicate<MatrixType, RowFactor, ColFactor>;
32 
33  public:
34 
35  using typename Base::scalar_type;
36 
37 
38  template<typename Arg>
39  static decltype(auto) nested_object(Arg&& arg)
40  {
41  return std::forward<Arg>(arg).nestedExpression();
42  }
43 
44 
45  template<typename Arg>
46  static constexpr auto get_constant(const Arg& arg)
47  {
48  return constant_coefficient {arg.nestedExpression()};
49  }
50 
51 
52  template<typename Arg>
53  static constexpr auto get_constant_diagonal(const Arg& arg)
54  {
55  if constexpr (RowFactor == 1 and ColFactor == 1) return constant_diagonal_coefficient {arg.nestedExpression()};
56  else return std::monostate {};
57  }
58 
59 
60  template<Applicability b>
61  static constexpr bool one_dimensional =
62  (b != Applicability::guaranteed or (RowFactor == 1 and ColFactor == 1)) and
63  (RowFactor == 1 or RowFactor == Eigen::Dynamic) and
64  (ColFactor == 1 or ColFactor == Eigen::Dynamic) and
65  OpenKalman::one_dimensional<MatrixType, b>;
66 
67 
68  template<Applicability b>
69  static constexpr bool is_square =
70  (b != Applicability::guaranteed or not has_dynamic_dimensions<Eigen::Replicate<MatrixType, RowFactor, ColFactor>>) and
71  (RowFactor == Eigen::Dynamic or ColFactor == Eigen::Dynamic or
72  ((RowFactor != ColFactor or square_shaped<MatrixType, b>) and
73  (dynamic_dimension<MatrixType, 0> or RowFactor * index_dimension_of_v<MatrixType, 0> % ColFactor == 0) and
74  (dynamic_dimension<MatrixType, 1> or ColFactor * index_dimension_of_v<MatrixType, 1> % RowFactor == 0))) and
75  (has_dynamic_dimensions<MatrixType> or
76  ((RowFactor == Eigen::Dynamic or index_dimension_of_v<MatrixType, 0> * RowFactor % index_dimension_of_v<MatrixType, 1> == 0) and
77  (ColFactor == Eigen::Dynamic or index_dimension_of_v<MatrixType, 1> * ColFactor % index_dimension_of_v<MatrixType, 0> == 0)));
78 
79 
80  template<TriangleType t>
81  static constexpr bool is_triangular = triangular_matrix<MatrixType, t> and
82  ((RowFactor == 1 and ColFactor != 0 and (t == TriangleType::upper or t == TriangleType::any)) or
83  (ColFactor == 1 and RowFactor != 0 and (t == TriangleType::lower or t == TriangleType::any)) or
84  (RowFactor == 1 and ColFactor == 1 and t == TriangleType::diagonal));
85 
86 
87  static constexpr bool is_triangular_adapter = false;
88 
89 
90  static constexpr bool is_hermitian = hermitian_matrix<MatrixType, Applicability::permitted> and
91  ((RowFactor == 1 and ColFactor == 1) or not values::complex<scalar_type> or
93 
94  };
95 
96 } // namespace OpenKalman::interface
97 
98 #endif //OPENKALMAN_EIGEN_TRAITS_REPLICATE_HPP
constexpr bool one_dimensional
Specifies that a type is one-dimensional in every index.
Definition: one_dimensional.hpp:83
Definition: indexible_object_traits.hpp:36
Definition: basics.hpp:41
Trait object providing get and set routines.
Definition: eigen-forward-declarations.hpp:502
Lower, upper, or diagonal matrix.
Definition: eigen-comma-initializers.hpp:20
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
An upper-right triangular matrix.
The constant associated with T, assuming T is a constant_matrix.
Definition: constant_coefficient.hpp:36
The constant associated with T, assuming T is a constant_diagonal_matrix.
Definition: constant_diagonal_coefficient.hpp:32
A diagonal matrix (both a lower-left and an upper-right triangular matrix).
decltype(auto) constexpr nested_object(Arg &&arg)
Retrieve a nested object of Arg, if it exists.
Definition: nested_object.hpp:34
The concept, trait, or restraint represents a compile-time guarantee.
A lower-left triangular matrix.