11 #ifndef EIGEN_CXX11_TENSOR_TENSORSTORAGE_H 12 #define EIGEN_CXX11_TENSOR_TENSORSTORAGE_H 14 #ifdef EIGEN_TENSOR_STORAGE_CTOR_PLUGIN 15 #define EIGEN_INTERNAL_TENSOR_STORAGE_CTOR_PLUGIN EIGEN_TENSOR_STORAGE_CTOR_PLUGIN; 17 #define EIGEN_INTERNAL_TENSOR_STORAGE_CTOR_PLUGIN 34 template<
typename T,
typename Dimensions,
int Options>
class TensorStorage;
38 template<
typename T,
typename FixedDimensions,
int Options_>
42 static const std::size_t Size = FixedDimensions::total_size;
45 static const std::size_t MinSize = max_n_1<Size>::size;
46 EIGEN_ALIGN_MAX T m_data[MinSize];
50 EIGEN_STRONG_INLINE TensorStorage() {
54 EIGEN_STRONG_INLINE T *data() {
return m_data; }
56 EIGEN_STRONG_INLINE
const T *data()
const {
return m_data; }
58 static EIGEN_DEVICE_FUNC
59 EIGEN_STRONG_INLINE
const FixedDimensions& dimensions()
61 static const FixedDimensions* singleton_dimensions =
new FixedDimensions();
62 return *singleton_dimensions;
66 EIGEN_STRONG_INLINE DenseIndex size()
const {
return Size; }
70 template<
typename T,
typename IndexType,
int NumIndices_,
int Options_>
71 class TensorStorage<T, DSizes<IndexType, NumIndices_>, Options_>
74 typedef IndexType
Index;
75 typedef DSizes<IndexType, NumIndices_> Dimensions;
76 typedef TensorStorage<T, DSizes<IndexType, NumIndices_>, Options_> Self;
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);
83 EIGEN_DEVICE_FUNC TensorStorage(internal::constructor_without_unaligned_array_assert)
84 : m_data(0), m_dimensions(internal::template repeat<NumIndices_, Index>(0)) {}
85 EIGEN_DEVICE_FUNC TensorStorage(Index size,
const array<Index, NumIndices_>& dimensions)
86 : m_data(internal::conditional_aligned_new_auto<T,(Options_&
DontAlign)==0>(size)), m_dimensions(dimensions)
87 { EIGEN_INTERNAL_TENSOR_STORAGE_CTOR_PLUGIN }
89 #if EIGEN_HAS_VARIADIC_TEMPLATES 90 template <
typename... DenseIndex>
91 EIGEN_DEVICE_FUNC TensorStorage(DenseIndex... indices) : m_dimensions(indices...) {
92 m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(internal::array_prod(m_dimensions));
96 EIGEN_DEVICE_FUNC TensorStorage(
const Self& other)
97 : m_data(internal::conditional_aligned_new_auto<T,(Options_&
DontAlign)==0>(internal::array_prod(other.m_dimensions)))
98 , m_dimensions(other.m_dimensions)
100 internal::smart_copy(other.m_data, other.m_data+internal::array_prod(other.m_dimensions), m_data);
102 EIGEN_DEVICE_FUNC Self& operator=(
const Self& other)
104 if (
this != &other) {
111 #if EIGEN_HAS_RVALUE_REFERENCES 112 EIGEN_DEVICE_FUNC TensorStorage(Self&& other) : TensorStorage()
114 *
this = std::move(other);
117 EIGEN_DEVICE_FUNC Self& operator=(Self&& other)
119 numext::swap(m_data, other.m_data);
120 numext::swap(m_dimensions, other.m_dimensions);
125 EIGEN_DEVICE_FUNC ~TensorStorage() { internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, internal::array_prod(m_dimensions)); }
126 EIGEN_DEVICE_FUNC
void swap(Self& other)
127 { numext::swap(m_data,other.m_data); numext::swap(m_dimensions,other.m_dimensions); }
129 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions;}
131 EIGEN_DEVICE_FUNC
void resize(Index size,
const array<Index, NumIndices_>& nbDimensions)
133 const Index currentSz = internal::array_prod(m_dimensions);
134 if(size != currentSz)
136 internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, currentSz);
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);
144 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
146 m_dimensions = nbDimensions;
149 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T *data() {
return m_data; }
150 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const T *data()
const {
return m_data; }
152 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size()
const {
return m_dimensions.TotalSize(); }
156 Dimensions m_dimensions;
161 #endif // EIGEN_CXX11_TENSOR_TENSORSTORAGE_H
Namespace containing all symbols from the Eigen library.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index