diff options
author | Gabriel Nützi <gnuetzi@gmx.ch> | 2015-10-09 18:52:48 +0200 |
---|---|---|
committer | Gabriel Nützi <gnuetzi@gmx.ch> | 2015-10-09 18:52:48 +0200 |
commit | 6edae2d30d5a74a3234f6a91adb5ffdb1b86bbfc (patch) | |
tree | 0f447071700ea86c3ee83422ca1d024132fc03cf /unsupported/Eigen/CXX11/src/Tensor/TensorMeta.h | |
parent | b4c79ee1d3d7b44e58f2bea48cd597aa0fa7e007 (diff) |
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<Index,NumIndices>
user: Gabriel Nützi <gnuetzi@gmx.ch>
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
Diffstat (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorMeta.h')
-rw-r--r-- | unsupported/Eigen/CXX11/src/Tensor/TensorMeta.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorMeta.h b/unsupported/Eigen/CXX11/src/Tensor/TensorMeta.h index 7dfa04760..60a6c1469 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorMeta.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorMeta.h @@ -34,6 +34,9 @@ template <> struct max_n_1<0> { + + + #if defined(EIGEN_HAS_CONSTEXPR) #define EIGEN_CONSTEXPR constexpr #else @@ -83,6 +86,54 @@ bool operator!=(const Tuple<U, V>& x, const Tuple<U, V>& y) { return !(x == y); } + + + +namespace internal{ + + template<typename IndexType, Index... Is> + EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + array<Index,sizeof...(Is)> customIndex2Array(const IndexType & idx, numeric_list<Index,Is...>) { + return { idx(Is)... }; + } + + /** Make an array (for index/dimensions) out of a custom index */ + template<typename Index, int NumIndices, typename IndexType> + EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + array<Index,NumIndices> customIndex2Array(const IndexType & idx) { + return customIndex2Array(idx, typename gen_numeric_list<Index,NumIndices>::type{}); + } + + + template <typename B, typename D> + struct is_base_of + { + + typedef char (&yes)[1]; + typedef char (&no)[2]; + + template <typename BB, typename DD> + struct Host + { + operator BB*() const; + operator DD*(); + }; + + template<typename T> + static yes check(D*, T); + static no check(B*, int); + + static const bool value = sizeof(check(Host<B,D>(), int())) == sizeof(yes); + }; + +} + + + + + + + #undef EIGEN_CONSTEXPR } // namespace Eigen |