OpenKalman
TensorFixedSize.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_TENSORFIXEDSIZE_HPP
17 #define OPENKALMAN_EIGEN_TRAITS_TENSORFIXEDSIZE_HPP
18 
19 
20 namespace OpenKalman::interface
21 {
22  template<typename S, typename Dims, int options, typename IndexType>
23  struct indexible_object_traits<Eigen::TensorFixedSize<S, Dims, options, IndexType>>
24  : Eigen3::indexible_object_traits_tensor_base<Eigen::TensorFixedSize<S, Dims, options, IndexType>>
25  {
26  private:
27 
29 
30  public:
31 
32  template<typename Arg, typename N>
33  static constexpr auto get_vector_space_descriptor(const Arg& arg, N n)
34  {
35  if constexpr (values::fixed<N>)
37  else
38  return static_cast<std::size_t>(arg.dimension(n));
39  }
40 
41  // nested_object() not defined
42 
43  // get_constant() not defined
44 
45  // get_constant_diagonal() not defined
46 
47 
48 #ifdef __cpp_lib_concepts
49  template<typename Arg, std::convertible_to<IndexType>...I> requires (sizeof...(I) == Dims::count)
50 #else
51  template<typename Arg, typename...I, std::enable_if_t<(std::is_convertible_v<I, IndexType> and ...) and
52  (sizeof...(I) == Dims::count), int> = 0>
53 #endif
54  static constexpr decltype(auto)
55  get(Arg&& arg, I...i)
56  {
57  if constexpr ((Eigen::internal::traits<std::decay_t<Arg>>::Flags & Eigen::LvalueBit) != 0)
58  return std::forward<Arg>(arg).coeffRef(static_cast<IndexType>(i)...);
59  else
60  return std::forward<Arg>(arg).coeff(static_cast<IndexType>(i)...);
61  }
62 
63 
64 #ifdef __cpp_lib_concepts
65  template<typename Arg, std::convertible_to<IndexType>...I> requires (sizeof...(I) == Dims::count) and
66  ((Eigen::internal::traits<std::decay_t<Arg>>::Flags & Eigen::LvalueBit) != 0x0)
67 #else
68  template<typename Arg, typename...I, std::enable_if_t<(std::is_convertible_v<I, IndexType> and ...) and
69  (sizeof...(I) == Dims::count) and ((Eigen::internal::traits<std::decay_t<Arg>>::Flags & Eigen::LvalueBit) != 0x0), int> = 0>
70 #endif
71  static void
72  set(Arg& arg, const scalar_type_of_t<Arg>& s, I...i)
73  {
74  arg.coeffRef(static_cast<IndexType>(i)...) = s;
75  }
76 
77 
78  static constexpr bool is_writable = true;
79 
80  template<typename Arg>
81  static constexpr auto * const
82  raw_data(Arg& arg) { return arg.data(); }
83 
84  static constexpr Layout layout = options & Eigen::RowMajor ? Layout::right : Layout::left;
85 
86  };
87 
88 } // namespace OpenKalman::interface
89 
90 #endif //OPENKALMAN_EIGEN_TRAITS_TENSORFIXEDSIZE_HPP
Definition: indexible_object_traits.hpp:36
Definition: basics.hpp:41
Row-major storage (C or C++ style): contiguous storage in which the right-most index has a stride of ...
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
Column-major storage (Fortran, Matlab, or Eigen style): contiguous storage in which the left-most ext...
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