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 object_traits<Eigen::CwiseUnaryView<ViewOp, MatrixType>>
26  : Eigen3::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_pattern_collection(const Arg& arg, N n)
38  {
39  return OpenKalman::get_pattern_collection(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_value {arg.nestedExpression()});
74 #else
75  else if constexpr (Eigen3::constexpr_unary_operation_defined<ViewOp> and values::fixed<constant_value<MatrixType>>)
76  return values::operation(Traits::constexpr_operation(), constant_value<MatrixType>{});
77 #endif
78  else
79  return values::operation(arg.functor(), constant_value {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_value{arg.nestedExpression()});
108  else
109  return values::operation(arg.functor(), constant_diagonal_value{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<triangle_type t>
125  static constexpr bool triangle_type_value = 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 }
133 
134 #endif
constexpr bool one_dimensional
Specifies that a type is one-dimensional in every index.
Definition: one_dimensional.hpp:56
Definition: basics.hpp:41
Definition: eigen-forward-declarations.hpp:41
Definition: eigen-comma-initializers.hpp:20
decltype(auto) constexpr get_pattern_collection(T &&t)
Get the coordinates::pattern_collection associated with indexible object T.
Definition: get_pattern_collection.hpp:59
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
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
decltype(auto) constexpr nested_object(Arg &&arg)
Retrieve a nested object of Arg, if it exists.
Definition: nested_object.hpp:35
constexpr auto operation(Operation &&op, Args &&...args)
A potentially constant-evaluated operation involving some number of values.
Definition: operation.hpp:98