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
33template <
typename T,
typename Dimensions,
int Options>
37template<
typename T,
typename FixedDimensions,
int Options_>
41 static const std::size_t Size = FixedDimensions::total_size;
44 static const std::size_t MinSize = max_n_1<Size>::size;
45 EIGEN_ALIGN_MAX T m_data[MinSize];
49 EIGEN_STRONG_INLINE TensorStorage() {
53 EIGEN_STRONG_INLINE T *data() {
return m_data; }
55 EIGEN_STRONG_INLINE
const T *data()
const {
return m_data; }
58 EIGEN_STRONG_INLINE
const FixedDimensions dimensions()
const {
return FixedDimensions(); }
61 EIGEN_STRONG_INLINE DenseIndex size()
const {
return Size; }
66template<
typename T,
typename IndexType,
int NumIndices_,
int Options_>
67class TensorStorage<T, DSizes<IndexType, NumIndices_>, Options_>
70 typedef IndexType
Index;
71 typedef DSizes<IndexType, NumIndices_> Dimensions;
72 typedef TensorStorage<T, DSizes<IndexType, NumIndices_>, Options_> Self;
74 EIGEN_DEVICE_FUNC TensorStorage() : m_data(0), m_dimensions() {
75 if (NumIndices_ == 0) {
76 m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(1);
79 EIGEN_DEVICE_FUNC TensorStorage(internal::constructor_without_unaligned_array_assert)
80 : m_data(0), m_dimensions(internal::template repeat<NumIndices_,
Index>(0)) {}
81 EIGEN_DEVICE_FUNC TensorStorage(
Index size,
const array<Index, NumIndices_>& dimensions)
82 : m_data(internal::conditional_aligned_new_auto<T,(Options_&
DontAlign)==0>(size)), m_dimensions(dimensions)
83 { EIGEN_INTERNAL_TENSOR_STORAGE_CTOR_PLUGIN }
85#if EIGEN_HAS_VARIADIC_TEMPLATES
86 template <
typename... DenseIndex>
87 EIGEN_DEVICE_FUNC TensorStorage(DenseIndex... indices) : m_dimensions(indices...) {
88 m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(internal::array_prod(m_dimensions));
92 EIGEN_DEVICE_FUNC TensorStorage(
const Self& other)
93 : m_data(internal::conditional_aligned_new_auto<T,(Options_&
DontAlign)==0>(internal::array_prod(other.m_dimensions)))
94 , m_dimensions(other.m_dimensions)
96 internal::smart_copy(other.m_data, other.m_data+internal::array_prod(other.m_dimensions), m_data);
98 EIGEN_DEVICE_FUNC Self& operator=(
const Self& other)
100 if (
this != &other) {
107#if EIGEN_HAS_RVALUE_REFERENCES
108 EIGEN_DEVICE_FUNC TensorStorage(Self&& other) : TensorStorage()
110 *
this = std::move(other);
113 EIGEN_DEVICE_FUNC Self& operator=(Self&& other)
115 numext::swap(m_data, other.m_data);
116 numext::swap(m_dimensions, other.m_dimensions);
121 EIGEN_DEVICE_FUNC ~TensorStorage() { internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, internal::array_prod(m_dimensions)); }
122 EIGEN_DEVICE_FUNC
void swap(Self& other)
123 { numext::swap(m_data,other.m_data); numext::swap(m_dimensions,other.m_dimensions); }
125 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions;}
127 EIGEN_DEVICE_FUNC
void resize(
Index size,
const array<Index, NumIndices_>& nbDimensions)
129 const Index currentSz = internal::array_prod(m_dimensions);
130 if(size != currentSz)
132 internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, currentSz);
134 m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(size);
135 else if (NumIndices_ == 0) {
136 m_data = internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(1);
140 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
142 m_dimensions = nbDimensions;
145 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T *data() {
return m_data; }
146 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const T *data()
const {
return m_data; }
148 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
Index size()
const {
return m_dimensions.TotalSize(); }
152 Dimensions m_dimensions;
Namespace containing all symbols from the Eigen library.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index