OpenKalman
TensorMap.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_TENSORMAP_HPP
17 #define OPENKALMAN_EIGEN_TRAITS_TENSORMAP_HPP
18 
19 
20 namespace OpenKalman::interface
21 {
22  template<typename PlainObjectType, int Options, template<typename> typename MakePointer>
23  struct indexible_object_traits<Eigen::TensorMap<PlainObjectType, Options, MakePointer>>
24  : Eigen3::indexible_object_traits_tensor_base<Eigen::TensorMap<PlainObjectType, Options, MakePointer>>
25  {
26  private:
27 
28  using Xpr = Eigen::TensorMap<PlainObjectType, Options, MakePointer>;
30  using StorageRefType = typename Xpr::StorageRefType;
31  using IndexType = typename Xpr::Index;
32 
33  public:
34 
35  template<typename Arg, typename N>
36  static constexpr std::size_t get_vector_space_descriptor(const Arg& arg, N n) { return arg.dimension(n); }
37 
38  // nested_object() not defined
39 
40  // get_constant() not defined
41 
42  // get_constant_diagonal() not defined
43 
44 
45 #ifdef __cpp_lib_concepts
46  template<typename Arg, std::convertible_to<IndexType>...I> requires (sizeof...(I) == PlainObjectType::NumDimensions)
47 #else
48  template<typename Arg, typename...I, std::enable_if_t<(std::is_convertible_v<I, IndexType> and ...) and
49  (sizeof...(I) == PlainObjectType::NumDimensions), int> = 0>
50 #endif
51  static constexpr decltype(auto) get(Arg&& arg, I...i)
52  {
53  return std::forward<Arg>(arg)(static_cast<IndexType>(i)...);
54  }
55 
56 
57 #ifdef __cpp_lib_concepts
58  template<typename Arg, std::convertible_to<IndexType>...I> requires (sizeof...(I) == PlainObjectType::NumDimensions) and
59  std::is_lvalue_reference_v<StorageRefType> and (not std::is_const_v<std::remove_reference_t<StorageRefType>>)
60 #else
61  template<typename Arg, typename...I, std::enable_if_t<(std::is_convertible_v<I, IndexType> and ...) and
62  (sizeof...(I) == PlainObjectType::NumDimensions) and std::is_lvalue_reference<StorageRefType>::value and
63  not std::is_const<typename std::remove_reference<StorageRefType>::type>::value, int> = 0>
64 #endif
65  static void set(Arg& arg, const scalar_type_of_t<Arg>& s, I...i)
66  {
67  arg(static_cast<IndexType>(i)...) = s;
68  }
69 
70  static constexpr bool is_writable = false;
71 
72  template<typename Arg>
73  static constexpr auto * const
74  raw_data(Arg& arg) { return arg.data(); }
75 
76  static constexpr Layout layout = layout_of_v<PlainObjectType>;
77 
78  };
79 
80 } // namespace OpenKalman::interface
81 
82 #endif //OPENKALMAN_EIGEN_TRAITS_TENSORMAP_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
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
Layout
The layout format of a multidimensional array.
Definition: global-definitions.hpp:47
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