From 6edae2d30d5a74a3234f6a91adb5ffdb1b86bbfc Mon Sep 17 00:00:00 2001 From: Gabriel Nützi Date: Fri, 9 Oct 2015 18:52:48 +0200 Subject: added CustomIndex capability only to Tensor and not yet to TensorBase. using Sfinae and is_base_of to select correct template which converts to array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit user: Gabriel Nützi branch 'default' added unsupported/Eigen/CXX11/src/Tensor/TensorMetaMacros.h added unsupported/test/cxx11_tensor_customIndex.cpp changed unsupported/Eigen/CXX11/Tensor changed unsupported/Eigen/CXX11/src/Tensor/Tensor.h changed unsupported/Eigen/CXX11/src/Tensor/TensorMeta.h changed unsupported/test/CMakeLists.txt --- unsupported/Eigen/CXX11/src/Tensor/Tensor.h | 81 +++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 3 deletions(-) (limited to 'unsupported/Eigen/CXX11/src/Tensor/Tensor.h') diff --git a/unsupported/Eigen/CXX11/src/Tensor/Tensor.h b/unsupported/Eigen/CXX11/src/Tensor/Tensor.h index 6c16e0faa..f9d367e0e 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/Tensor.h +++ b/unsupported/Eigen/CXX11/src/Tensor/Tensor.h @@ -88,6 +88,11 @@ class Tensor : public TensorBase m_storage; + template + struct isOfNormalIndex{ + static const bool value = internal::is_base_of< array, CustomIndex >::value; + }; + public: // Metadata EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank() const { return NumIndices; } @@ -111,14 +116,29 @@ class Tensor : public TensorBase{{firstIndex, secondIndex, otherIndices...}}); } + + #endif + + /** Normal Index */ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& coeff(const array& indices) const { eigen_internal_assert(checkIndexRange(indices)); return m_storage.data()[linearizedIndex(indices)]; } + /** Custom Index */ + template::value) ) + > + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& coeff(const CustomIndex & indices) const + { + return coeff(internal::customIndex2Array(indices)); + } + + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& coeff(Index index) const { eigen_internal_assert(index >= 0 && index < size()); @@ -135,12 +155,23 @@ class Tensor : public TensorBase& indices) { eigen_internal_assert(checkIndexRange(indices)); return m_storage.data()[linearizedIndex(indices)]; } + /** Custom Index */ + template::value) ) + > + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(const CustomIndex & indices) + { + return coeffRef(internal::customIndex2Array(indices)); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) { eigen_internal_assert(index >= 0 && index < size()); @@ -178,9 +209,20 @@ class Tensor : public TensorBase::value) ) + > + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& operator()(const CustomIndex & indices) const + { + //eigen_assert(checkIndexRange(indices)); /* already in coeff */ + return coeff(internal::customIndex2Array(indices)); + } + + /** Normal Index */ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& operator()(const array& indices) const { - eigen_assert(checkIndexRange(indices)); + //eigen_assert(checkIndexRange(indices)); /* already in coeff */ return coeff(indices); } @@ -228,12 +270,23 @@ class Tensor : public TensorBase& indices) { - eigen_assert(checkIndexRange(indices)); + //eigen_assert(checkIndexRange(indices)); /* already in coeff */ return coeffRef(indices); } + /** Custom Index */ + template::value) ) + > + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(const CustomIndex & indices) + { + //eigen_assert(checkIndexRange(indices)); /* already in coeff */ + return coeffRef(internal::customIndex2Array(indices)); + } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(Index index) { eigen_assert(index >= 0 && index < size()); @@ -295,12 +348,20 @@ class Tensor : public TensorBase& dimensions) : m_storage(internal::array_prod(dimensions), dimensions) { EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED } + /** Custom Dimension (delegating constructor c++11) */ + template::value) ) + > + inline explicit Tensor(const CustomDimension & dimensions) : Tensor(internal::customIndex2Array(dimensions)) + {} + template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor(const TensorBase& other) @@ -341,7 +402,7 @@ class Tensor : public TensorBase EIGEN_DEVICE_FUNC + template EIGEN_DEVICE_FUNC void resize(Index firstDimension, IndexTypes... otherDimensions) { // The number of dimensions used to resize a tensor must be equal to the rank of the tensor. @@ -350,6 +411,7 @@ class Tensor : public TensorBase& dimensions) { std::size_t i; @@ -367,6 +429,8 @@ class Tensor : public TensorBase& dimensions) { array dims; for (std::size_t i = 0; i < NumIndices; ++i) { @@ -375,6 +439,17 @@ class Tensor : public TensorBase::value) ) + > + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(const CustomDimension & dimensions) + { + //eigen_assert(checkIndexRange(indices)); /* already in coeff */ + return coeffRef(internal::customIndex2Array(dimensions)); + } + + #ifndef EIGEN_EMULATE_CXX11_META_H template EIGEN_DEVICE_FUNC -- cgit v1.2.3