OpenKalman
CwiseUnaryView.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_TRAITS_CWISEUNARYVIEW_HPP
17 #define OPENKALMAN_EIGEN_TRAITS_CWISEUNARYVIEW_HPP
18 
19 #include <type_traits>
20 
21 
22 namespace OpenKalman::interface
23 {
24  template<typename ViewOp, typename MatrixType>
25  struct indexible_object_traits<Eigen::CwiseUnaryView<ViewOp, MatrixType>>
26  : Eigen3::indexible_object_traits_base<Eigen::CwiseUnaryView<ViewOp, MatrixType>>
27  {
28  private:
29 
30  using Xpr = Eigen::CwiseUnaryView<ViewOp, MatrixType>;
33 
34  public:
35 
36  template<typename Arg, typename N>
37  static constexpr auto get_vector_space_descriptor(const Arg& arg, N n)
38  {
39  return OpenKalman::get_vector_space_descriptor(arg.nestedExpression(), n);
40  }
41 
42 
43  template<typename Arg>
44  static decltype(auto) nested_object(Arg&& arg)
45  {
46  return std::forward<Arg>(arg).nestedExpression();
47  }
48 
49  private:
50 
51 #ifndef __cpp_concepts
52  template<typename T, typename = void>
53  struct custom_get_constant_defined : std::false_type {};
54 
55  template<typename T>
56  struct custom_get_constant_defined<T, std::void_t<decltype(T::template get_constant(std::declval<const Xpr&>()))>>
57  : std::true_type {};
58 #endif
59 
60  public:
61 
62  static constexpr auto
63  get_constant(const Xpr& arg)
64  {
65 #ifdef __cpp_concepts
66  if constexpr (requires { Traits::get_constant(arg); })
67 #else
69 #endif
70  return Traits::template get_constant(arg);
71 #ifdef __cpp_concepts
72  else if constexpr (Eigen3::constexpr_unary_operation_defined<ViewOp>)
73  return values::operation {Traits::constexpr_operation(), constant_coefficient {arg.nestedExpression()}};
74 #else
75  else if constexpr (Eigen3::constexpr_unary_operation_defined<ViewOp> and values::fixed<constant_coefficient<MatrixType>>)
76  return values::operation {Traits::constexpr_operation(), constant_coefficient<MatrixType>{}};
77 #endif
78  else
79  return values::operation {arg.functor(), constant_coefficient {arg.nestedExpression()}};
80  }
81 
82  private:
83 
84 #ifndef __cpp_concepts
85  template<typename T, typename = void>
86  struct custom_get_constant_diagonal_defined : std::false_type {};
87 
88  template<typename T>
89  struct custom_get_constant_diagonal_defined<T, std::void_t<decltype(T::template get_constant_diagonal<MatrixType>(std::declval<const Xpr&>()))>>
90  : std::true_type {};
91 #endif
92 
93  public:
94 
95  static constexpr auto
96  get_constant_diagonal(const Xpr& arg)
97  {
98 #ifdef __cpp_concepts
99  if constexpr (requires { Traits::get_constant_diagonal(arg); })
100 #else
102 #endif
103  return Traits::template get_constant_diagonal<MatrixType>(arg);
104  else if constexpr (not Traits::preserves_triangle)
105  return std::monostate{};
106  else if constexpr (Eigen3::constexpr_unary_operation_defined<ViewOp>)
107  return values::operation {Traits::constexpr_operation(), constant_diagonal_coefficient{arg.nestedExpression()}};
108  else
109  return values::operation {arg.functor(), constant_diagonal_coefficient{arg.nestedExpression()}};
110  }
111 
112 
113  template<Applicability b>
114  static constexpr bool one_dimensional = OpenKalman::one_dimensional<MatrixType, b>;
115 
116 
117  template<Applicability b>
118  static constexpr bool is_square = square_shaped<MatrixType, b>;
119 
120 
121  static constexpr bool is_triangular_adapter = false;
122 
123 
124  template<TriangleType t>
125  static constexpr bool is_triangular = Traits::preserves_triangle and triangular_matrix<MatrixType, t>;
126 
127 
128  static constexpr bool is_hermitian = Traits ::preserves_hermitian and hermitian_matrix<MatrixType, Applicability::permitted>;
129  };
130 
131 
132 } // namespace OpenKalman::interface
133 
134 #endif //OPENKALMAN_EIGEN_TRAITS_CWISEUNARYVIEW_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
An operation involving some number of values.
Definition: operation.hpp:69
Trait object providing get and set routines.
Definition: eigen-forward-declarations.hpp:502
Definition: eigen-forward-declarations.hpp:41
Definition: eigen-comma-initializers.hpp:20
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
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
constexpr bool fixed
T is a values::value that is determinable at compile time.
Definition: fixed.hpp:60
decltype(auto) constexpr nested_object(Arg &&arg)
Retrieve a nested object of Arg, if it exists.
Definition: nested_object.hpp:34
constexpr auto get_vector_space_descriptor(const T &t, const N &n)
Get the coordinates::pattern object for index N of indexible object T.
Definition: get_vector_space_descriptor.hpp:56