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  FixedDimensions m_dimensions;
49 
50  public:
51  EIGEN_DEVICE_FUNC
53  }
54 
55  EIGEN_DEVICE_FUNC
57  EIGEN_DEVICE_FUNC
58  EIGEN_STRONG_INLINE const T *data() const { return m_data; }
59 
60  EIGEN_DEVICE_FUNC
61  EIGEN_STRONG_INLINE const FixedDimensions& dimensions() const { return m_dimensions; }
62 
63  EIGEN_DEVICE_FUNC
64  EIGEN_STRONG_INLINE DenseIndex size() const { return m_dimensions.TotalSize(); }
65 };
66 
67 
68 // pure dynamic
69 template<typename T, typename IndexType, int NumIndices_, int Options_>
70 class TensorStorage<T, DSizes<IndexType, NumIndices_>, Options_>
71 {
72  public:
73  typedef IndexType Index;
76 
77  EIGEN_DEVICE_FUNC TensorStorage() : m_data(0), m_dimensions() {
78  if (NumIndices_ == 0) {
79  m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(1);
80  }
81  }
83  : m_data(0), m_dimensions(internal::template repeat<NumIndices_, Index>(0)) {}
84  EIGEN_DEVICE_FUNC TensorStorage(Index size, const array<Index, NumIndices_>& dimensions)
85  : m_data(internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(size)), m_dimensions(dimensions)
87 
88 #if EIGEN_HAS_VARIADIC_TEMPLATES
89  template <typename... DenseIndex>
90  EIGEN_DEVICE_FUNC TensorStorage(DenseIndex... indices) : m_dimensions(indices...) {
91  m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(internal::array_prod(m_dimensions));
92  }
93 #endif
94 
95  EIGEN_DEVICE_FUNC TensorStorage(const Self& other)
97  , m_dimensions(other.m_dimensions)
98  {
100  }
101  EIGEN_DEVICE_FUNC Self& operator=(const Self& other)
102  {
103  if (this != &other) {
104  Self tmp(other);
105  this->swap(tmp);
106  }
107  return *this;
108  }
109 
110  EIGEN_DEVICE_FUNC ~TensorStorage() { internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, internal::array_prod(m_dimensions)); }
111  EIGEN_DEVICE_FUNC void swap(Self& other)
113 
114  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const {return m_dimensions;}
115 
116  EIGEN_DEVICE_FUNC void resize(Index size, const array<Index, NumIndices_>& nbDimensions)
117  {
118  const Index currentSz = internal::array_prod(m_dimensions);
119  if(size != currentSz)
120  {
121  internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, currentSz);
122  if (size)
123  m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(size);
124  else if (NumIndices_ == 0) {
125  m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(1);
126  }
127  else
128  m_data = 0;
130  }
131  m_dimensions = nbDimensions;
132  }
133 
134  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T *data() { return m_data; }
135  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T *data() const { return m_data; }
136 
137  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const { return m_dimensions.TotalSize(); }
138 
139  private:
141  Dimensions m_dimensions;
142 };
143 
144 } // end namespace Eigen
145 
146 #endif // EIGEN_CXX11_TENSOR_TENSORSTORAGE_H
EIGEN_DEVICE_FUNC T * conditional_aligned_new_auto(std::size_t size)
Definition: Memory.h:369
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes< Indices... > &)
#define EIGEN_STRONG_INLINE
Definition: Macros.h:494
EIGEN_ALIGN_MAX T m_data[MinSize]
Definition: TensorStorage.h:46
FixedDimensions m_dimensions
Definition: TensorStorage.h:48
array< t, n > repeat(t v)
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
EIGEN_DEVICE_FUNC void resize(Index size, const array< Index, NumIndices_ > &nbDimensions)
#define EIGEN_INTERNAL_TENSOR_STORAGE_CTOR_PLUGIN
Definition: TensorStorage.h:17
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T * data() const
EIGEN_DEVICE_FUNC TensorStorage(Index size, const array< Index, NumIndices_ > &dimensions)
Definition: TensorStorage.h:84
EIGEN_DEVICE_FUNC void smart_copy(const T *start, const T *end, T *target)
Definition: Memory.h:485
EIGEN_STRONG_INLINE void swap(T &a, T &b)
Definition: Meta.h:493
int EIGEN_BLAS_FUNC() swap(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:152
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const FixedDimensions & dimensions() const
Definition: TensorStorage.h:61
static const std::size_t Size
Definition: TensorStorage.h:42
#define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X)
Definition: DenseStorage.h:18
TensorStorage< T, DSizes< IndexType, NumIndices_ >, Options_ > Self
Definition: TensorStorage.h:75
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorStorage()
Definition: TensorStorage.h:52
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex size() const
Definition: TensorStorage.h:64
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
Definition: Meta.h:25
#define EIGEN_ALIGN_MAX
Definition: Macros.h:757
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T * data() const
Definition: TensorStorage.h:58
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T * data()
Definition: TensorStorage.h:56
EIGEN_DEVICE_FUNC TensorStorage(internal::constructor_without_unaligned_array_assert)
Definition: TensorStorage.h:82
static const std::size_t MinSize
Definition: TensorStorage.h:45


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:46:00