OpenKalman
TensorRef.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_TENSORREF_HPP
17 #define OPENKALMAN_EIGEN_TRAITS_TENSORREF_HPP
18 
19 
20 namespace OpenKalman::interface
21 {
22  template<typename PlainObjectType>
23  struct indexible_object_traits<Eigen::TensorRef<PlainObjectType>>
24  : Eigen3::indexible_object_traits_tensor_base<Eigen::TensorRef<PlainObjectType>>
25  {
26  private:
27 
29  using Base::max_indices;
30  using Dimensions = typename PlainObjectType::Dimensions;
31  using Scalar = typename Eigen::internal::traits<PlainObjectType>::Scalar;
32  using Index = typename Eigen::internal::traits<PlainObjectType>::Index;
33 
34  public:
35 
36  template<typename Arg, typename N>
37  static constexpr std::size_t get_index_descriptor(const Arg& arg, N n) { return arg.dimension(n); }
38 
39  // get_nested_object() not defined
40 
41  // get_constant() not defined
42 
43  // get_constant_diagonal() not defined
44 
45 
46 #ifdef __cpp_lib_concepts
47  template<typename Arg, std::convertible_to<Index>...I> requires (sizeof...(I) == index_count_v<PlainObjectType>)
48 #else
49  template<typename Arg, typename...I, std::enable_if_t<(std::is_convertible_v<I, Index> and ...) and
50  (sizeof...(I) == index_count<PlainObjectType>::value), int> = 0>
51 #endif
52  static constexpr decltype(auto) get(Arg&& arg, I...i)
53  {
54  if constexpr ((Eigen::internal::traits<std::decay_t<Arg>>::Flags & Eigen::LvalueBit) != 0)
55  return std::forward<Arg>(arg).coeffRef(std::array<Index, sizeof...(I)>{static_cast<Index>(i)...});
56  else
57  return std::forward<Arg>(arg).coeff(std::array<Index, sizeof...(I)>{static_cast<Index>(i)...});
58  }
59 
60 
61 #ifdef __cpp_lib_concepts
62  template<typename Arg, std::convertible_to<Index>...I> requires (sizeof...(I) == index_count_v<PlainObjectType>) and
63  ((Eigen::internal::traits<std::decay_t<Arg>>::Flags & Eigen::LvalueBit) != 0x0)
64 #else
65  template<typename Arg, typename...I, std::enable_if_t<(std::is_convertible_v<I, Index> and ...) and
66  (sizeof...(I) == index_count<PlainObjectType>::value) and ((Eigen::internal::traits<std::decay_t<Arg>>::Flags & Eigen::LvalueBit) != 0x0), int> = 0>
67 #endif
68  static void set(Arg& arg, const scalar_type_of_t<Arg>& s, I...i)
69  {
70  arg.coeffRef(std::array<Index, sizeof...(I)>{static_cast<Index>(i)...}) = s;
71  }
72 
73  static constexpr bool is_writable = true;
74 
75  // data() not defined
76 
77  static constexpr Layout layout = layout_of_v<PlainObjectType>;
78 
79  };
80 
81 } // namespace OpenKalman::interface
82 
83 #endif //OPENKALMAN_EIGEN_TRAITS_TENSORREF_HPP
Definition: indexible_object_traits.hpp:36
Definition: basics.hpp:41
typename scalar_type_of< T >::type scalar_type_of_t
helper template for scalar_type_of.
Definition: scalar_type_of.hpp:54
Definition: eigen-comma-initializers.hpp:20
Trait object providing get and set routines for Eigen tensors.
Definition: eigen-tensor-forward-declarations.hpp:114
Layout
The layout format of a multidimensional array.
Definition: global-definitions.hpp:47
The minimum number of indices need to access all the components of an object.
Definition: index_count.hpp:33