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,
int Options_,
typename FixedDimensions>
39 class TensorStorage<T, FixedDimensions, 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];
48 FixedDimensions m_dimensions;
52 EIGEN_STRONG_INLINE TensorStorage() {
56 EIGEN_STRONG_INLINE T *data() {
return m_data; }
58 EIGEN_STRONG_INLINE
const T *data()
const {
return m_data; }
61 EIGEN_STRONG_INLINE
const FixedDimensions& dimensions()
const {
return m_dimensions; }
64 EIGEN_STRONG_INLINE DenseIndex size()
const {
return m_dimensions.TotalSize(); }
69 template<
typename T,
int Options_,
typename IndexType,
int NumIndices_>
70 class TensorStorage<T, DSizes<IndexType, NumIndices_>, Options_>
73 typedef IndexType Index;
74 typedef DSizes<IndexType, NumIndices_> Dimensions;
75 typedef TensorStorage<T, DSizes<IndexType, NumIndices_>, Options_> Self;
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);
82 EIGEN_DEVICE_FUNC TensorStorage(internal::constructor_without_unaligned_array_assert)
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)
86 { EIGEN_INTERNAL_TENSOR_STORAGE_CTOR_PLUGIN }
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));
95 EIGEN_DEVICE_FUNC TensorStorage(
const Self& other)
96 : m_data(internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(internal::array_prod(other.m_dimensions)))
97 , m_dimensions(other.m_dimensions)
99 internal::smart_copy(other.m_data, other.m_data+internal::array_prod(other.m_dimensions), m_data);
101 EIGEN_DEVICE_FUNC Self& operator=(
const Self& other)
103 if (
this != &other) {
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)
112 { numext::swap(m_data,other.m_data); numext::swap(m_dimensions,other.m_dimensions); }
114 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions;}
116 EIGEN_DEVICE_FUNC
void resize(Index size,
const array<Index, NumIndices_>& nbDimensions)
118 const Index currentSz = internal::array_prod(m_dimensions);
119 if(size != currentSz)
121 internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, currentSz);
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);
129 EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({})
131 m_dimensions = nbDimensions;
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; }
137 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size()
const {
return m_dimensions.TotalSize(); }
141 Dimensions m_dimensions;
146 #endif // EIGEN_CXX11_TENSOR_TENSORSTORAGE_H Namespace containing all symbols from the Eigen library.
Definition: AdolcForward:45