From 35722fa0222a7f99a8179d75244177a9801ea36b Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Mon, 30 Mar 2015 14:55:54 -0700 Subject: Made the index type a template parameter of the tensor class instead of encoding it in the options. --- unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h | 49 +++++++--------------- 1 file changed, 15 insertions(+), 34 deletions(-) (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h') diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h b/unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h index c1d004678..f567b8c03 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h @@ -2,6 +2,7 @@ // for linear algebra. // // Copyright (C) 2013 Christian Seiler +// Copyright (C) 2014-2015 Benoit Steiner // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed @@ -30,21 +31,22 @@ namespace Eigen { * * \sa Tensor */ -template class TensorStorage; +template class TensorStorage; // Pure fixed-size storage -template -class TensorStorage +template +class TensorStorage { private: + static const std::size_t Size = FixedDimensions::total_size; + EIGEN_ALIGN_DEFAULT T m_data[Size]; FixedDimensions m_dimensions; public: EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorStorage() { - EIGEN_STATIC_ASSERT(Size == FixedDimensions::total_size, YOU_MADE_A_PROGRAMMING_MISTAKE) } EIGEN_DEVICE_FUNC @@ -60,35 +62,14 @@ class TensorStorage }; - -// pure-dynamic, but without specification of all dimensions explicitly -template -class TensorStorage - : public TensorStorage(Options_ & Index32Bit)>::type, NumIndices_, Dynamic>::type> -{ - typedef typename internal::compute_index_type(Options_ & Index32Bit)>::type Index; - typedef DSizes Dimensions; - typedef TensorStorage::type> Base_; - - public: - EIGEN_DEVICE_FUNC TensorStorage() { } - EIGEN_DEVICE_FUNC TensorStorage(const TensorStorage& other) : Base_(other) { } - - EIGEN_DEVICE_FUNC TensorStorage(internal::constructor_without_unaligned_array_assert) : Base_(internal::constructor_without_unaligned_array_assert()) {} - EIGEN_DEVICE_FUNC TensorStorage(Index size, const array& dimensions) : Base_(size, dimensions) {} - - // TensorStorage& operator=(const TensorStorage&) = default; -}; - // pure dynamic -template -class TensorStorage(Options_ & Index32Bit)>::type, NumIndices_, Dynamic>::type> +template +class TensorStorage, Options_> { public: - typedef typename internal::compute_index_type(Options_&Index32Bit)>::type Index; - typedef DSizes Dimensions; - - typedef TensorStorage::type> Self_; + typedef IndexType Index; + typedef DSizes Dimensions; + typedef TensorStorage, Options_> Self; EIGEN_DEVICE_FUNC TensorStorage() : m_data(0), m_dimensions() {} EIGEN_DEVICE_FUNC TensorStorage(internal::constructor_without_unaligned_array_assert) @@ -97,23 +78,23 @@ class TensorStorage(size)), m_dimensions(dimensions) { EIGEN_INTERNAL_TENSOR_STORAGE_CTOR_PLUGIN } - EIGEN_DEVICE_FUNC TensorStorage(const Self_& other) + EIGEN_DEVICE_FUNC TensorStorage(const Self& other) : m_data(internal::conditional_aligned_new_auto(internal::array_prod(other.m_dimensions))) , m_dimensions(other.m_dimensions) { internal::smart_copy(other.m_data, other.m_data+internal::array_prod(other.m_dimensions), m_data); } - EIGEN_DEVICE_FUNC Self_& operator=(const Self_& other) + EIGEN_DEVICE_FUNC Self& operator=(const Self& other) { if (this != &other) { - Self_ tmp(other); + Self tmp(other); this->swap(tmp); } return *this; } EIGEN_DEVICE_FUNC ~TensorStorage() { internal::conditional_aligned_delete_auto(m_data, internal::array_prod(m_dimensions)); } - EIGEN_DEVICE_FUNC void swap(Self_& other) + EIGEN_DEVICE_FUNC void swap(Self& other) { std::swap(m_data,other.m_data); std::swap(m_dimensions,other.m_dimensions); } EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const {return m_dimensions;} -- cgit v1.2.3