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
This commit is contained in:
Gabriel Nützi
2015-10-09 18:52:48 +02:00
parent b4c79ee1d3
commit 6edae2d30d
6 changed files with 205 additions and 3 deletions

View File

@@ -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