OpenKalman
LibraryWrapper.hpp
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 
17 #ifndef OPENKALMAN_EIGEN_NATIVE_EVALUATORS_LIBRARYWRAPPER_HPP
18 #define OPENKALMAN_EIGEN_NATIVE_EVALUATORS_LIBRARYWRAPPER_HPP
19 
20 
21 namespace OpenKalman::detail
22 {
23 
24 #ifdef __cpp_concepts
25  template<typename XprType, typename Nested>
26 #else
27  template<typename XprType, typename Nested, typename = void>
28 #endif
29  struct EigenWrapperEvaluatorBase : Eigen::internal::evaluator_base<XprType>
30  {
31  explicit EigenWrapperEvaluatorBase(const XprType& t) : m_xpr {const_cast<XprType&>(t)} {}
32 
33 
34  auto& coeffRef(Eigen::Index row, Eigen::Index col)
35  {
36  return OpenKalman::get_component(m_xpr.nested_object(), static_cast<std::size_t>(row), static_cast<std::size_t>(col));
37  }
38 
39 
40  constexpr decltype(auto) coeff(Eigen::Index row, Eigen::Index col) const
41  {
42  return OpenKalman::get_component(m_xpr.nested_object(), static_cast<std::size_t>(row), static_cast<std::size_t>(col));
43  }
44 
45 
46  enum {
47  CoeffReadCost = 0,
48  Flags = Eigen::internal::traits<XprType>::Flags,
49  Alignment = Eigen::AlignedMax
50  };
51 
52  protected:
53 
54  XprType& m_xpr;
55  };
56 
57 
58 #ifdef __cpp_concepts
59  template<typename XprType, OpenKalman::Eigen3::eigen_dense_general Nested> requires
60  requires { typename Eigen::internal::evaluator<std::decay_t<Nested>>; }
61  struct EigenWrapperEvaluatorBase<XprType, Nested>
62 #else
63  template<typename XprType, typename Nested>
64  struct EigenWrapperEvaluatorBase<XprType, Nested, std::enable_if_t<OpenKalman::Eigen3::eigen_dense_general<Nested>>>
65 #endif
66  : Eigen::internal::evaluator<std::decay_t<Nested>>
67  {
68  explicit EigenWrapperEvaluatorBase(const XprType& t)
69  : Eigen::internal::evaluator<std::decay_t<Nested>> {t.nested_object()} {}
70  };
71 
72 } // namespace OpenKalman::detail
73 
74 
75 namespace Eigen::internal
76 {
77 
78  template<typename T, typename L>
79  struct evaluator<OpenKalman::internal::LibraryWrapper<T, L>>
80  : OpenKalman::detail::EigenWrapperEvaluatorBase<OpenKalman::internal::LibraryWrapper<T, L>, T>
81  {
82  static_assert(OpenKalman::Eigen3::eigen_general<L>);
85  explicit evaluator(const XprType& t) : Base {t} {}
86  };
87 
88 } // Eigen::internal
89 
90 #endif //OPENKALMAN_EIGEN_NATIVE_EVALUATORS_LIBRARYWRAPPER_HPP
T is an acceptable noise perturbation input to a tests.
Definition: common_reference.hpp:24
Definition: tuple_reverse.hpp:103
Definition: LibraryWrapper.hpp:29
The root namespace for OpenKalman.
Definition: basics.hpp:34
decltype(auto) constexpr get_component(Arg &&arg, const Indices &indices)
Get a component of an object at a particular set of indices.
Definition: get_component.hpp:54
Definition: ConstantAdapter.hpp:21