OpenKalman
eigen-forward-declarations.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-2021 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_FORWARD_DECLARATIONS_HPP
17 #define OPENKALMAN_EIGEN_FORWARD_DECLARATIONS_HPP
18 
19 #include <type_traits>
20 
21 
22 namespace OpenKalman::Eigen3
23 {
24 
31  template<typename NullaryOp, typename PlainObjectType>
33 
34 
40  template<typename Operation>
42 
43 
48  enum struct BinaryFunctorType: int {
49  normal,
50  sum,
51  product,
52  };
53 
54 
60  template<typename Operation>
62 
63 
69  template<typename Operation, typename Arg1, typename Arg2, typename Arg3>
71 
72 
79  struct EigenCustomBase {};
80 
81 
89  template<typename Derived, typename Base>
91 
92 
93  // -------------------------------------- //
94  // concepts for specific Eigen classes //
95  // -------------------------------------- //
96 
97  namespace detail
98  {
99  template<typename T>
100  struct is_ArrayWrapper : std::false_type {};
101 
102  template<typename XprType>
103  struct is_ArrayWrapper<Eigen::ArrayWrapper<XprType>> : std::true_type {};
104  }
105 
106 
110  template<typename T>
111 #ifdef __cpp_concepts
112  concept eigen_ArrayWrapper =
113 #else
114  constexpr bool eigen_ArrayWrapper =
115 #endif
117 
118 
119  namespace detail
120  {
121  template<typename T>
122  struct is_Block : std::false_type {};
123 
124  template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
125  struct is_Block<Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel>> : std::true_type {};
126  }
127 
128 
132  template<typename T>
133 #ifdef __cpp_concepts
134  concept eigen_Block =
135 #else
136  constexpr bool eigen_Block =
137 #endif
139 
140 
141  namespace detail
142  {
143  template<typename T>
144  struct is_CwiseUnaryOp : std::false_type {};
145 
146  template<typename UnaryOp, typename XprType>
147  struct is_CwiseUnaryOp<Eigen::CwiseUnaryOp<UnaryOp, XprType>> : std::true_type {};
148  }
149 
150 
154  template<typename T>
155 #ifdef __cpp_concepts
156  concept eigen_CwiseUnaryOp =
157 #else
158  constexpr bool eigen_CwiseUnaryOp =
159 #endif
161 
162 
163  namespace detail
164  {
165  template<typename T>
166  struct is_CwiseUnaryView : std::false_type {};
167 
168  template<typename ViewOp, typename XprType>
169  struct is_CwiseUnaryView<Eigen::CwiseUnaryView<ViewOp, XprType>> : std::true_type {};
170  }
171 
172 
176  template<typename T>
177 #ifdef __cpp_concepts
178  concept eigen_CwiseUnaryView =
179 #else
180  constexpr bool eigen_CwiseUnaryView =
181 #endif
183 
184 
185  namespace detail
186  {
187  template<typename T>
188  struct is_DiagonalMatrix : std::false_type {};
189 
190  template<typename Scalar, int SizeAtCompileTime, int MaxSizeAtCompileTime>
191  struct is_DiagonalMatrix<Eigen::DiagonalMatrix<Scalar, SizeAtCompileTime, MaxSizeAtCompileTime>>
192  : std::true_type {};
193  }
194 
195 
199  template<typename T>
200 #ifdef __cpp_concepts
201  concept eigen_DiagonalMatrix =
202 #else
203  constexpr bool eigen_DiagonalMatrix =
204 #endif
206 
207 
208  namespace detail
209  {
210  template<typename T>
211  struct is_DiagonalWrapper : std::false_type {};
212 
213  template<typename DiagonalVectorType>
214  struct is_DiagonalWrapper<Eigen::DiagonalWrapper<DiagonalVectorType>> : std::true_type {};
215  }
216 
217 
221  template<typename T>
222 #ifdef __cpp_concepts
223  concept eigen_DiagonalWrapper =
224 #else
225  constexpr bool eigen_DiagonalWrapper =
226 #endif
228 
229 
230  namespace detail
231  {
232  template<typename T>
233  struct is_eigen_Identity : std::false_type {};
234 
235  template<typename Scalar, typename Arg>
236  struct is_eigen_Identity<Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<Scalar>, Arg>>
237  : std::true_type {};
238  }
239 
240 
244  template<typename T>
245 #ifdef __cpp_concepts
247 #else
248  constexpr bool eigen_Identity = detail::is_eigen_Identity<std::decay_t<T>>::value;
249 #endif
250 
251 
252  namespace detail
253  {
254  template<typename T>
255  struct is_eigen_MatrixWrapper : std::false_type {};
256 
257  template<typename XprType>
258  struct is_eigen_MatrixWrapper<Eigen::MatrixWrapper<XprType>> : std::true_type {};
259  }
260 
261 
265  template<typename T>
266 #ifdef __cpp_concepts
268 #else
269  constexpr bool eigen_MatrixWrapper = detail::is_eigen_MatrixWrapper<std::decay_t<T>>::value;
270 #endif
271 
272 
273  namespace detail
274  {
275  template<typename T>
276  struct is_eigen_Replicate : std::false_type {};
277 
278  template<typename MatrixType, int RowFactor, int ColFactor>
279  struct is_eigen_Replicate<Eigen::Replicate<MatrixType, RowFactor, ColFactor>> : std::true_type
280  {
281  private:
282 
283  template<std::size_t direction>
284  static constexpr std::size_t efactor = direction == 1 ? ColFactor : RowFactor;
285 
286  public:
287 
288  template<std::size_t direction>
289  static constexpr std::size_t factor = efactor<direction> == Eigen::Dynamic ? dynamic_size : efactor<direction>;
290  };
291  }
292 
293 
297  template<typename T>
298 #ifdef __cpp_concepts
299  concept eigen_Replicate =
300 #else
301  constexpr bool eigen_Replicate =
302 #endif
304 
305 
309  template<typename T, std::size_t direction>
311  : std::integral_constant<std::size_t, detail::is_eigen_Replicate<std::decay_t<T>>::template factor<direction>> {};
312 
313 
317  template<typename T, std::size_t direction>
319 
320 
321  namespace detail
322  {
323  template<typename T>
324  struct is_eigen_SelfAdjointView : std::false_type {};
325 
326  template<typename MatrixType, unsigned int UpLo>
327  struct is_eigen_SelfAdjointView<Eigen::SelfAdjointView<MatrixType, UpLo>> : std::true_type {};
328  }
329 
330 
334  template<typename T>
335 #ifdef __cpp_concepts
337 #else
338  constexpr bool eigen_SelfAdjointView = detail::is_eigen_SelfAdjointView<std::decay_t<T>>::value;
339 #endif
340 
341 
342  namespace detail
343  {
344  template<typename T>
345  struct is_eigen_TriangularView : std::false_type {};
346 
347  template<typename MatrixType, unsigned int UpLo>
348  struct is_eigen_TriangularView<Eigen::TriangularView<MatrixType, UpLo>> : std::true_type {};
349  }
350 
351 
355  template<typename T>
356 #ifdef __cpp_concepts
358 #else
359  constexpr bool eigen_TriangularView = detail::is_eigen_TriangularView<std::decay_t<T>>::value;
360 #endif
361 
362 
363  namespace detail
364  {
365  template<typename T>
366  struct is_eigen_VectorBlock : std::false_type {};
367 
368  template<typename T, int Size>
369  struct is_eigen_VectorBlock<Eigen::VectorBlock<T, Size>> : std::true_type {};
370  }
371 
372 
376  template<typename T>
377 #ifdef __cpp_concepts
378  concept eigen_VectorBlock =
379 #else
380  constexpr bool eigen_VectorBlock =
381 #endif
383 
384 
389  template<typename T, bool must_be_native = false>
390 #ifdef __cpp_concepts
391  concept eigen_general =
392 #else
393  constexpr bool eigen_general =
394 #endif
395  (std::is_base_of_v<Eigen::EigenBase<std::decay_t<T>>, std::decay_t<T>> or eigen_VectorBlock<T>) and
396  (not must_be_native or not std::is_base_of_v<EigenCustomBase, std::decay_t<T>>);
397 
398 
399  namespace detail
400  {
401  template<typename T>
402  struct is_derived_eigen_matrix : std::false_type {};
403 
404  template<typename T, int Size>
405  struct is_derived_eigen_matrix<Eigen::VectorBlock<T, Size>>
406  : std::is_base_of<Eigen::MatrixBase<std::decay_t<T>>, std::decay_t<T>> {};
407  }
408 
409 
414  template<typename T, bool must_be_native = false>
415 #ifdef __cpp_concepts
416  concept eigen_matrix_general =
417 #else
418  constexpr bool eigen_matrix_general =
419 #endif
420  (eigen_general<T, must_be_native> and std::is_base_of_v<Eigen::MatrixBase<std::decay_t<T>>, std::decay_t<T>>) or
421  detail::is_derived_eigen_matrix<std::decay_t<T>>::value;
422 
423 
424  namespace detail
425  {
426  template<typename T>
427  struct is_derived_eigen_array : std::false_type {};
428 
429  template<typename T, int Size>
430  struct is_derived_eigen_array<Eigen::VectorBlock<T, Size>>
431  : std::is_base_of<Eigen::ArrayBase<std::decay_t<T>>, std::decay_t<T>> {};
432  }
433 
434 
439  template<typename T, bool must_be_native = false>
440 #ifdef __cpp_concepts
441  concept eigen_array_general =
442 #else
443  constexpr bool eigen_array_general =
444 #endif
445  (eigen_general<T, must_be_native> and std::is_base_of_v<Eigen::ArrayBase<std::decay_t<T>>, std::decay_t<T>>) or
446  detail::is_derived_eigen_array<std::decay_t<T>>::value;
447 
448 
453  template<typename T, bool must_be_native = false>
454 #ifdef __cpp_concepts
455  concept eigen_dense_general =
456 #else
457  constexpr bool eigen_dense_general =
458 #endif
459  eigen_matrix_general<T, must_be_native> or eigen_array_general<T, must_be_native>;
460 
461 
467  template<typename NestedMatrix>
468  using IdentityMatrix = Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<
469  typename Eigen::internal::traits<std::decay_t<NestedMatrix>>::Scalar>, NestedMatrix>;
470 
471 
472  // ---------------- //
473  // eigen_matrix_t //
474  // ---------------- //
475 
476  namespace detail
477  {
478  template<std::size_t size>
479  constexpr auto eigen_index_convert = size == dynamic_size ? Eigen::Dynamic : static_cast<Eigen::Index>(size);
480  }
481 
488  template<typename Scalar, std::size_t...dims>
489  using eigen_matrix_t = std::conditional_t<sizeof...(dims) == 1,
490  Eigen::Matrix<Scalar, detail::eigen_index_convert<dims>..., detail::eigen_index_convert<1>>,
491  Eigen::Matrix<Scalar, detail::eigen_index_convert<dims>...>>;
492 
493 
497 #ifdef __cpp_concepts
498  template<typename T>
500 #else
501  template<typename T, typename = void>
503 #endif
504 
505 
509  template<typename Op> static decltype(auto) native_operation(Op&& op) { return std::forward<Op>(op); };
510  template<typename S> static auto native_operation(const std::plus<S>& op) { return Eigen::internal::scalar_sum_op<S, S> {}; };
511  template<typename S> static auto native_operation(const std::minus<S>& op) { return Eigen::internal::scalar_difference_op<S, S> {}; };
512  template<typename S> static auto native_operation(const std::multiplies<S>& op) {return Eigen::internal::scalar_product_op<S, S> {}; };
513  template<typename S> static auto native_operation(const std::divides<S>& op) { return Eigen::internal::scalar_quotient_op<S, S> {}; };
514  template<typename S> static auto native_operation(const std::negate<S>& op) { return Eigen::internal::scalar_opposite_op<S> {}; };
515 
516  using EIC = Eigen::internal::ComparisonName;
517  template<typename S> static auto native_operation(const std::equal_to<S>& op) { return Eigen::internal::scalar_cmp_op<S, S, EIC::cmp_EQ> {}; };
518  template<typename S> static auto native_operation(const std::not_equal_to<S>& op) { return Eigen::internal::scalar_cmp_op<S, S, EIC::cmp_NEQ> {}; };
519  template<typename S> static auto native_operation(const std::greater<S>& op) { return Eigen::internal::scalar_cmp_op<S, S, EIC::cmp_GT> {}; };
520  template<typename S> static auto native_operation(const std::less<S>& op) { return Eigen::internal::scalar_cmp_op<S, S, EIC::cmp_LT> {}; };
521  template<typename S> static auto native_operation(const std::greater_equal<S>& op) { return Eigen::internal::scalar_cmp_op<S, S, EIC::cmp_GE> {}; };
522  template<typename S> static auto native_operation(const std::less_equal<S>& op) { return Eigen::internal::scalar_cmp_op<S, S, EIC::cmp_LE> {}; };
523 
524  template<typename S> static auto native_operation(const std::logical_and<S>& op) { return Eigen::internal::scalar_boolean_and_op {}; };
525  template<typename S> static auto native_operation(const std::logical_or<S>& op) { return Eigen::internal::scalar_boolean_or_op {}; };
526  template<typename S> static auto native_operation(const std::logical_not<S>& op) { return Eigen::internal::scalar_boolean_not_op<S> {}; };
527 
528 
529 } // namespace OpenKalman::Eigen3
530 
531 
532 #endif //OPENKALMAN_EIGEN_FORWARD_DECLARATIONS_HPP
Definition: eigen-forward-declarations.hpp:324
Eigen::CwiseNullaryOp< Eigen::internal::scalar_identity_op< typename Eigen::internal::traits< std::decay_t< NestedMatrix > >::Scalar >, NestedMatrix > IdentityMatrix
An alias for the Eigen identity matrix.
Definition: eigen-forward-declarations.hpp:469
Definition: eigen-forward-declarations.hpp:90
Trait object providing get and set routines.
Definition: eigen-forward-declarations.hpp:502
Definition: eigen-forward-declarations.hpp:41
Definition: eigen-forward-declarations.hpp:122
Definition: eigen-forward-declarations.hpp:32
constexpr bool eigen_matrix_general
Specifies a native Eigen3 matrix or expression class deriving from Eigen::MatrixBase.
Definition: eigen-forward-declarations.hpp:418
Definition: eigen-comma-initializers.hpp:20
constexpr bool eigen_TriangularView
T is of type Eigen::TriangularView.
Definition: eigen-forward-declarations.hpp:359
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
std::conditional_t< sizeof...(dims)==1, Eigen::Matrix< Scalar, detail::eigen_index_convert< dims >..., detail::eigen_index_convert< 1 > >, Eigen::Matrix< Scalar, detail::eigen_index_convert< dims >... > > eigen_matrix_t
An alias for a self-contained, writable, native Eigen matrix.
Definition: eigen-forward-declarations.hpp:491
constexpr auto eigen_Replicate_factor_v
Helper template for eigen_Replicate_factor.
Definition: eigen-forward-declarations.hpp:318
Definition: eigen-forward-declarations.hpp:144
Definition: eigen-forward-declarations.hpp:166
constexpr bool eigen_Replicate
T is of type Eigen::Replicate.
Definition: eigen-forward-declarations.hpp:301
constexpr bool eigen_Block
Specifies whether T is Eigen::Block.
Definition: eigen-forward-declarations.hpp:136
Definition: eigen-forward-declarations.hpp:22
Definition: eigen-forward-declarations.hpp:255
constexpr bool eigen_ArrayWrapper
T is of type Eigen::ArrayWrapper.
Definition: eigen-forward-declarations.hpp:114
constexpr bool eigen_array_general
Specifies a native Eigen3 array or expression class deriving from Eigen::ArrayBase.
Definition: eigen-forward-declarations.hpp:443
constexpr bool eigen_CwiseUnaryOp
Specifies whether T is Eigen::CwiseUnaryOp.
Definition: eigen-forward-declarations.hpp:158
Definition: eigen-forward-declarations.hpp:61
constexpr bool size
T is either an index representing a size, or void which represents that there is no size...
Definition: size.hpp:32
Definition: eigen-forward-declarations.hpp:366
constexpr bool eigen_dense_general
Specifies a native Eigen3 object deriving from Eigen::MatrixBase or Eigen::ArrayBase.
Definition: eigen-forward-declarations.hpp:457
decltype(auto) constexpr sum(Ts &&...ts)
Element-by-element sum of one or more objects.
Definition: sum.hpp:112
Definition: eigen-forward-declarations.hpp:345
Definition: eigen-forward-declarations.hpp:427
Definition: eigen-forward-declarations.hpp:211
constexpr bool eigen_DiagonalMatrix
T is of type Eigen::DiagonalMatrix.
Definition: eigen-forward-declarations.hpp:203
Definition: eigen-forward-declarations.hpp:100
Definition: eigen-forward-declarations.hpp:276
The replication factor for Eigen::Replicate in a given direction.
Definition: eigen-forward-declarations.hpp:310
constexpr bool eigen_CwiseUnaryView
Specifies whether T is Eigen::CwiseUnaryView.
Definition: eigen-forward-declarations.hpp:180
constexpr std::size_t dynamic_size
A constant indicating that a size or index is dynamic.
Definition: global-definitions.hpp:33
constexpr bool eigen_VectorBlock
Specifies whether T is Eigen::VectorBlock.
Definition: eigen-forward-declarations.hpp:380
constexpr bool eigen_general
Specifies any descendant of Eigen::EigenBase.
Definition: eigen-forward-declarations.hpp:393
Definition: eigen-forward-declarations.hpp:233
constexpr bool eigen_MatrixWrapper
T is of type Eigen::MatrixWrapper.
Definition: eigen-forward-declarations.hpp:269
Definition: eigen-forward-declarations.hpp:402
Definition: eigen-forward-declarations.hpp:79
constexpr bool eigen_Identity
T is an Eigen identity matrix (not necessarily an identity_matrix).
Definition: eigen-forward-declarations.hpp:248
Definition: eigen-forward-declarations.hpp:188
Definition: eigen-forward-declarations.hpp:70
constexpr bool eigen_SelfAdjointView
T is of type Eigen::SelfAdjointView.
Definition: eigen-forward-declarations.hpp:338
constexpr bool eigen_DiagonalWrapper
T is of type Eigen::DiagonalMatrix.
Definition: eigen-forward-declarations.hpp:225