diff options
author | Benoit Steiner <benoit.steiner.goog@gmail.com> | 2014-04-28 10:32:27 -0700 |
---|---|---|
committer | Benoit Steiner <benoit.steiner.goog@gmail.com> | 2014-04-28 10:32:27 -0700 |
commit | c0f2cb016e60b7dbde1d5946f42234a709a711f9 (patch) | |
tree | 346d5beb917ea586a6a463312606cf794c91da75 /unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h | |
parent | 450d0c3de044c9f32fa2f37fee821f6e390df382 (diff) |
Extended support for Tensors:
* Added ability to map a region of the memory to a tensor
* Added basic support for unary and binary coefficient wise expressions, such as addition or square root
* Provided an emulation layer to make it possible to compile the code with compilers (such as nvcc) that don't support cxx11.
Diffstat (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h')
-rw-r--r-- | unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h b/unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h index a34600ee6..503d7cfd6 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h @@ -37,14 +37,19 @@ template<typename T, std::size_t NumIndices_, int Options_> class TensorStorage<T, NumIndices_, Dynamic, Options_, void> : public TensorStorage<T, NumIndices_, Dynamic, Options_, typename internal::gen_numeric_list_repeated<DenseIndex, NumIndices_, Dynamic>::type> { - typedef TensorStorage<T, NumIndices_, Dynamic, Options_, typename internal::gen_numeric_list_repeated<DenseIndex, NumIndices_, Dynamic>::type> Base_; + typedef TensorStorage<T, NumIndices_, Dynamic, Options_, typename internal::gen_numeric_list_repeated<DenseIndex, NumIndices_, Dynamic>::type> Base_; + public: - TensorStorage() = default; - TensorStorage(const TensorStorage<T, NumIndices_, Dynamic, Options_, void>&) = default; - TensorStorage(TensorStorage<T, NumIndices_, Dynamic, Options_, void>&&) = default; + TensorStorage() { } + TensorStorage(const TensorStorage<T, NumIndices_, Dynamic, Options_, void>& other) : Base_(other) { } + +#ifdef EIGEN_HAVE_RVALUE_REFERENCES +// TensorStorage(TensorStorage<T, NumIndices_, Dynamic, Options_, void>&&) = default; +#endif TensorStorage(internal::constructor_without_unaligned_array_assert) : Base_(internal::constructor_without_unaligned_array_assert()) {} - TensorStorage(DenseIndex size, const std::array<DenseIndex, NumIndices_>& dimensions) : Base_(size, dimensions) {} - TensorStorage<T, NumIndices_, Dynamic, Options_, void>& operator=(const TensorStorage<T, NumIndices_, Dynamic, Options_, void>&) = default; + TensorStorage(DenseIndex size, const array<DenseIndex, NumIndices_>& dimensions) : Base_(size, dimensions) {} + + // TensorStorage<T, NumIndices_, Dynamic, Options_, void>& operator=(const TensorStorage<T, NumIndices_, Dynamic, Options_, void>&) = default; }; // pure dynamic @@ -52,17 +57,17 @@ template<typename T, std::size_t NumIndices_, int Options_> class TensorStorage<T, NumIndices_, Dynamic, Options_, typename internal::gen_numeric_list_repeated<DenseIndex, NumIndices_, Dynamic>::type> { T *m_data; - std::array<DenseIndex, NumIndices_> m_dimensions; + array<DenseIndex, NumIndices_> m_dimensions; typedef TensorStorage<T, NumIndices_, Dynamic, Options_, typename internal::gen_numeric_list_repeated<DenseIndex, NumIndices_, Dynamic>::type> Self_; public: - TensorStorage() : m_data(0), m_dimensions(internal::template repeat<NumIndices_, DenseIndex>(0)) {} + TensorStorage() : m_data(0), m_dimensions() {} TensorStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_dimensions(internal::template repeat<NumIndices_, DenseIndex>(0)) {} - TensorStorage(DenseIndex size, const std::array<DenseIndex, NumIndices_>& dimensions) - : m_data(internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(size)), m_dimensions(dimensions) - { EIGEN_INTERNAL_TENSOR_STORAGE_CTOR_PLUGIN } - TensorStorage(const Self_& other) + TensorStorage(DenseIndex size, const array<DenseIndex, NumIndices_>& dimensions) + : m_data(internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(size)), m_dimensions(dimensions) + { EIGEN_INTERNAL_TENSOR_STORAGE_CTOR_PLUGIN } + TensorStorage(const Self_& other) : m_data(internal::conditional_aligned_new_auto<T,(Options_&DontAlign)==0>(internal::array_prod(other.m_dimensions))) , m_dimensions(other.m_dimensions) { @@ -76,28 +81,34 @@ class TensorStorage<T, NumIndices_, Dynamic, Options_, typename internal::gen_nu } return *this; } - TensorStorage(Self_&& other) + +#ifdef EIGEN_HAVE_RVALUE_REFERENCES +/* TensorStorage(Self_&& other) : m_data(std::move(other.m_data)), m_dimensions(std::move(other.m_dimensions)) { other.m_data = nullptr; } +*/ Self_& operator=(Self_&& other) { using std::swap; swap(m_data, other.m_data); swap(m_dimensions, other.m_dimensions); return *this; - } + } +#endif + ~TensorStorage() { internal::conditional_aligned_delete_auto<T,(Options_&DontAlign)==0>(m_data, internal::array_prod(m_dimensions)); } void swap(Self_& other) { std::swap(m_data,other.m_data); std::swap(m_dimensions,other.m_dimensions); } - std::array<DenseIndex, NumIndices_> dimensions(void) const {return m_dimensions;} - void conservativeResize(DenseIndex size, const std::array<DenseIndex, NumIndices_>& nbDimensions) + const array<DenseIndex, NumIndices_>& dimensions() const {return m_dimensions;} + + void conservativeResize(DenseIndex size, const array<DenseIndex, NumIndices_>& nbDimensions) { m_data = internal::conditional_aligned_realloc_new_auto<T,(Options_&DontAlign)==0>(m_data, size, internal::array_prod(m_dimensions)); m_dimensions = nbDimensions; } - void resize(DenseIndex size, const std::array<DenseIndex, NumIndices_>& nbDimensions) + void resize(DenseIndex size, const array<DenseIndex, NumIndices_>& nbDimensions) { if(size != internal::array_prod(m_dimensions)) { @@ -110,8 +121,9 @@ class TensorStorage<T, NumIndices_, Dynamic, Options_, typename internal::gen_nu } m_dimensions = nbDimensions; } - const T *data() const { return m_data; } + T *data() { return m_data; } + const T *data() const { return m_data; } }; // TODO: implement fixed-size stuff @@ -119,7 +131,3 @@ class TensorStorage<T, NumIndices_, Dynamic, Options_, typename internal::gen_nu } // end namespace Eigen #endif // EIGEN_CXX11_TENSOR_TENSORSTORAGE_H - -/* - * kate: space-indent on; indent-width 2; mixedindent off; indent-mode cstyle; - */ |