OpenKalman
CwiseUnaryOp.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-2024 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_CWISEUNARYOP_HPP
17 #define OPENKALMAN_EIGEN_TRAITS_CWISEUNARYOP_HPP
18 
19 
20 namespace OpenKalman::interface
21 {
22  template<typename UnaryOp, typename XprType>
23  struct indexible_object_traits<Eigen::CwiseUnaryOp<UnaryOp, XprType>>
24  : Eigen3::indexible_object_traits_base<Eigen::CwiseUnaryOp<UnaryOp, XprType>>
25  {
26  private:
27 
28  using Xpr = Eigen::CwiseUnaryOp<UnaryOp, XprType>;
31 
32  template<typename T>
33  struct is_bind_operator : std::false_type {};
34 
35  template<typename BinaryOp>
36  struct is_bind_operator<Eigen::internal::bind1st_op<BinaryOp>> : std::true_type {};
37 
38  template<typename BinaryOp>
39  struct is_bind_operator<Eigen::internal::bind2nd_op<BinaryOp>> : std::true_type {};
40 
41  public:
42 
43  template<typename Arg, typename N>
44  static constexpr auto
45  get_vector_space_descriptor(const Arg& arg, N n)
46  {
47  return OpenKalman::get_vector_space_descriptor(arg.nestedExpression(), n);
48  }
49 
50 
51  template<typename Arg>
52  static decltype(auto)
53  nested_object(Arg&& arg)
54  {
55  return std::as_const(arg).nestedExpression(); // There seems to be a bug in CwiseUnaryOp when the argument is non-const.
56  }
57 
58  private:
59 
60 #ifndef __cpp_concepts
61  template<typename T, typename = void>
62  struct custom_get_constant_defined : std::false_type {};
63 
64  template<typename T>
65  struct custom_get_constant_defined<T, std::void_t<decltype(T::get_constant(std::declval<const Xpr&>()))>>
66  : std::true_type {};
67 #endif
68 
69  public:
70 
71  static constexpr auto
72  get_constant(const Xpr& arg)
73  {
74 #ifdef __cpp_concepts
75  if constexpr (requires { Traits::get_constant(arg); })
76 #else
78 #endif
79  return Traits::get_constant(arg);
80  else if constexpr (Eigen3::constexpr_unary_operation_defined<UnaryOp>)
81  return values::operation {Traits::constexpr_operation(), constant_coefficient {arg.nestedExpression()}};
82  else
83  return values::operation {arg.functor(), constant_coefficient {arg.nestedExpression()}};
84  }
85 
86  private:
87 
88 #ifndef __cpp_concepts
89  template<typename T, typename = void>
90  struct custom_get_constant_diagonal_defined : std::false_type {};
91 
92  template<typename T>
93  struct custom_get_constant_diagonal_defined<T, std::void_t<decltype(T::get_constant_diagonal(std::declval<const Xpr&>()))>>
94  : std::true_type {};
95 #endif
96 
97  public:
98 
99  static constexpr auto
100  get_constant_diagonal(const Xpr& arg)
101  {
102 #ifdef __cpp_concepts
103  if constexpr (requires { Traits::get_constant_diagonal(arg); })
104 #else
106 #endif
107  return Traits::get_constant_diagonal(arg);
108  else if constexpr (not Traits::preserves_triangle)
109  return std::monostate{};
110  else if constexpr (Eigen3::constexpr_unary_operation_defined<UnaryOp>)
111  return values::operation {Traits::constexpr_operation(), constant_diagonal_coefficient{arg.nestedExpression()}};
112  else
113  return values::operation {arg.functor(), constant_diagonal_coefficient{arg.nestedExpression()}};
114  }
115 
116 
117  template<Applicability b>
118  static constexpr bool one_dimensional = OpenKalman::one_dimensional<XprType, b>;
119 
120 
121  template<Applicability b>
122  static constexpr bool is_square = square_shaped<XprType, b>;
123 
124 
125  static constexpr bool is_triangular_adapter = false;
126 
127 
128  template<TriangleType t>
129  static constexpr bool is_triangular = Traits::preserves_triangle and triangular_matrix<XprType, t>;
130 
131 
132  static constexpr bool is_hermitian = Traits::preserves_hermitian and hermitian_matrix<XprType, Applicability::permitted>;
133 
134  };
135 
136 
137 } // namespace OpenKalman::interface
138 
139 #endif //OPENKALMAN_EIGEN_TRAITS_CWISEUNARYOP_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
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