TensorStorage.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2013 Christian Seiler <christian@iwakd.de>
5 // Copyright (C) 2014-2015 Benoit Steiner <benoit.steiner.goog@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_CXX11_TENSOR_TENSORSTORAGE_H
12 #define EIGEN_CXX11_TENSOR_TENSORSTORAGE_H
13 
14 #ifdef EIGEN_TENSOR_STORAGE_CTOR_PLUGIN
15  #define EIGEN_INTERNAL_TENSOR_STORAGE_CTOR_PLUGIN EIGEN_TENSOR_STORAGE_CTOR_PLUGIN;
16 #else
17  #define EIGEN_INTERNAL_TENSOR_STORAGE_CTOR_PLUGIN
18 #endif
19 
20 namespace Eigen {
21 
34 template<typename T, typename Dimensions, int Options> class TensorStorage;
35 
36 
37 // Pure fixed-size storage
38 template<typename T, typename FixedDimensions, int Options_>
39 class TensorStorage
40 {
41  private:
42  static const std::size_t Size = FixedDimensions::total_size;
43 
44  // Allocate an array of size at least one to prevent compiler warnings.
47 
48  public:
51  }
52 
56  EIGEN_STRONG_INLINE const T *data() const { return m_data; }
57 
58  static EIGEN_DEVICE_FUNC
59  EIGEN_STRONG_INLINE const FixedDimensions& dimensions()
60  {
61  static const FixedDimensions* singleton_dimensions = new FixedDimensions();
62  return *singleton_dimensions;
63  }
64 
67 };
68 
69 // pure dynamic
70 template<typename T, typename IndexType, int NumIndices_, int Options_>
71 class TensorStorage<T, DSizes<IndexType, NumIndices_>, Options_>
72 {
73  public:
74  typedef IndexType Index;
77 
78  EIGEN_DEVICE_FUNC TensorStorage() : m_data(0), m_dimensions() {
79  if (NumIndices_ == 0) {
80  m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(1);
81  }
82  }
84  : m_data(0), m_dimensions(internal::template repeat<NumIndices_, Index>(0)) {}
86  : m_data(internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(size)), m_dimensions(dimensions)
88 
89 #if EIGEN_HAS_VARIADIC_TEMPLATES
90  template <typename... DenseIndex>
92  m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(internal::array_prod(m_dimensions));
93  }
94 #endif
95 
98  , m_dimensions(other.m_dimensions)
99  {
100  internal::smart_copy(other.m_data, other.m_data+internal::array_prod(other.m_dimensions), m_data);
101  }
103  {
104  if (this != &other) {
105  Self tmp(other);
106  this->swap(tmp);
107  }
108  return *this;
109  }
110 
111 #if EIGEN_HAS_RVALUE_REFERENCES
113  {
114  *this = std::move(other);
115  }
116 
117  EIGEN_DEVICE_FUNC Self& operator=(Self&& other)
118  {
119  numext::swap(m_data, other.m_data);
120  numext::swap(m_dimensions, other.m_dimensions);
121  return *this;
122  }
123 #endif
124 
125  EIGEN_DEVICE_FUNC ~TensorStorage() { internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, internal::array_prod(m_dimensions)); }
127  { numext::swap(m_data,other.m_data); numext::swap(m_dimensions,other.m_dimensions); }
128 
129  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const {return m_dimensions;}
130 
132  {
133  const Index currentSz = internal::array_prod(m_dimensions);
134  if(size != currentSz)
135  {
136  internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, currentSz);
137  if (size)
138  m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(size);
139  else if (NumIndices_ == 0) {
140  m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(1);
141  }
142  else
143  m_data = 0;
145  }
146  m_dimensions = nbDimensions;
147  }
148 
150  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T *data() const { return m_data; }
151 
152  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const { return m_dimensions.TotalSize(); }
153 
154  private:
157 };
158 
159 } // end namespace Eigen
160 
161 #endif // EIGEN_CXX11_TENSOR_TENSORSTORAGE_H
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen::TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ >::TensorStorage
EIGEN_DEVICE_FUNC TensorStorage(internal::constructor_without_unaligned_array_assert)
Definition: TensorStorage.h:83
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::TensorStorage::Size
static const std::size_t Size
Definition: TensorStorage.h:42
Eigen::array
Definition: EmulateArray.h:21
Eigen::TensorStorage::MinSize
static const std::size_t MinSize
Definition: TensorStorage.h:45
Eigen::TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ >::TensorStorage
EIGEN_DEVICE_FUNC TensorStorage(const Self &other)
Definition: TensorStorage.h:96
Eigen::TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ >::TensorStorage
EIGEN_DEVICE_FUNC TensorStorage(Index size, const array< Index, NumIndices_ > &dimensions)
Definition: TensorStorage.h:85
Eigen::TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ >
Definition: TensorStorage.h:71
Eigen::TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ >::m_dimensions
Dimensions m_dimensions
Definition: TensorStorage.h:156
Eigen::TensorStorage::TensorStorage
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorStorage()
Definition: TensorStorage.h:50
Eigen::TensorStorage::dimensions
static EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE FixedDimensions & dimensions()
Definition: TensorStorage.h:59
Eigen::TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ >::Self
TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ > Self
Definition: TensorStorage.h:76
Eigen::TensorStorage::data
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE T * data() const
Definition: TensorStorage.h:56
Eigen::TensorStorage
Definition: TensorStorage.h:34
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
#define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X)
Definition: DenseStorage.h:18
Eigen::internal::constructor_without_unaligned_array_assert
Definition: DenseStorage.h:25
EIGEN_INTERNAL_TENSOR_STORAGE_CTOR_PLUGIN
#define EIGEN_INTERNAL_TENSOR_STORAGE_CTOR_PLUGIN
Definition: TensorStorage.h:17
Eigen::DontAlign
@ DontAlign
Definition: Constants.h:325
Eigen::DSizes
Definition: TensorDimensions.h:263
test_eigen_tensor.indices
indices
Definition: test_eigen_tensor.py:33
Eigen::TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ >::m_data
T * m_data
Definition: TensorStorage.h:155
EIGEN_ALIGN_MAX
#define EIGEN_ALIGN_MAX
Definition: ConfigureVectorization.h:157
Eigen::TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ >::data
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE T * data() const
Definition: TensorStorage.h:150
Eigen::TensorStorage::size
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex size() const
Definition: TensorStorage.h:66
Eigen::TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ >::TensorStorage
EIGEN_DEVICE_FUNC TensorStorage()
Definition: TensorStorage.h:78
Eigen::TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ >::~TensorStorage
EIGEN_DEVICE_FUNC ~TensorStorage()
Definition: TensorStorage.h:125
Eigen::max_n_1
Definition: TensorMeta.h:40
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
Eigen::TensorStorage::data
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T * data()
Definition: TensorStorage.h:54
Eigen::internal::repeat
constexpr array< t, n > repeat(t v)
Definition: CXX11Meta.h:483
Eigen::TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ >::resize
EIGEN_DEVICE_FUNC void resize(Index size, const array< Index, NumIndices_ > &nbDimensions)
Definition: TensorStorage.h:131
Eigen::Triplet< double >
size_t
std::size_t size_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:490
Eigen::TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ >::size
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const
Definition: TensorStorage.h:152
Eigen::internal::array_prod
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes< Indices... > &)
Definition: TensorDimensions.h:140
Eigen::TensorStorage::m_data
EIGEN_ALIGN_MAX T m_data[MinSize]
Definition: TensorStorage.h:46
Eigen::numext::swap
EIGEN_STRONG_INLINE void swap(T &a, T &b)
Definition: Meta.h:766
Eigen::DenseIndex
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
Definition: Meta.h:66
Eigen::TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ >::dimensions
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE Dimensions & dimensions() const
Definition: TensorStorage.h:129
Eigen::TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ >::swap
EIGEN_DEVICE_FUNC void swap(Self &other)
Definition: TensorStorage.h:126
Eigen::TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ >::Index
IndexType Index
Definition: TensorStorage.h:74
internal
Definition: BandTriangularSolver.h:13
Eigen::internal::smart_copy
EIGEN_DEVICE_FUNC void smart_copy(const T *start, const T *end, T *target)
Definition: Memory.h:515
Eigen::TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ >::data
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T * data()
Definition: TensorStorage.h:149
swap
int EIGEN_BLAS_FUNC() swap(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:130
Eigen::TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ >::operator=
EIGEN_DEVICE_FUNC Self & operator=(const Self &other)
Definition: TensorStorage.h:102
Eigen::TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ >::Dimensions
DSizes< IndexType, NumIndices_ > Dimensions
Definition: TensorStorage.h:75
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
Eigen::internal::conditional_aligned_new_auto
EIGEN_DEVICE_FUNC T * conditional_aligned_new_auto(std::size_t size)
Definition: Memory.h:399


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:39:17