From 7a1316fcc564b709b361592c6897591d9747c401 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Thu, 12 Nov 2015 11:05:54 -0800 Subject: Fixed compilation error with xcode. --- .../Eigen/CXX11/src/Tensor/TensorIndexList.h | 184 ++++++++++++++++----- 1 file changed, 139 insertions(+), 45 deletions(-) (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorIndexList.h') diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorIndexList.h b/unsupported/Eigen/CXX11/src/Tensor/TensorIndexList.h index 78e1d2bd1..dcd2464f1 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorIndexList.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorIndexList.h @@ -77,38 +77,128 @@ struct is_compile_time_constant& > { static constexpr bool value = true; }; + + + +template +struct IndexTuple; + +template +struct IndexTuple { + constexpr IndexTuple() : head(), others() { } + constexpr IndexTuple(const T& v, const O... o) : head(v), others(o...) { } + + constexpr static int count = 1 + sizeof...(O); + T head; + IndexTuple others; + typedef T Head; + typedef IndexTuple Other; +}; + +template + struct IndexTuple { + constexpr IndexTuple() : head() { } + constexpr IndexTuple(const T& v) : head(v) { } + + constexpr static int count = 1; + T head; + typedef T Head; +}; + + +template +struct IndexTupleExtractor; + +template +struct IndexTupleExtractor { + + typedef typename IndexTupleExtractor::ValType ValType; + + static constexpr ValType& get_val(IndexTuple& val) { + return IndexTupleExtractor::get_val(val.others); + } + + static constexpr const ValType& get_val(const IndexTuple& val) { + return IndexTupleExtractor::get_val(val.others); + } + template + static void set_val(IndexTuple& val, V& new_val) { + IndexTupleExtractor::set_val(val.others, new_val); + } + +}; + + template + struct IndexTupleExtractor<0, T, O...> { + + typedef T ValType; + + static constexpr ValType& get_val(IndexTuple& val) { + return val.head; + } + static constexpr const ValType& get_val(const IndexTuple& val) { + return val.head; + } + template + static void set_val(IndexTuple& val, V& new_val) { + val.head = new_val; + } +}; + + + +template +constexpr typename IndexTupleExtractor::ValType& array_get(IndexTuple& tuple) { + return IndexTupleExtractor::get_val(tuple); +} +template +constexpr const typename IndexTupleExtractor::ValType& array_get(const IndexTuple& tuple) { + return IndexTupleExtractor::get_val(tuple); +} +template + struct array_size > { + static const size_t value = IndexTuple::count; +}; +template + struct array_size > { + static const size_t value = IndexTuple::count; +}; + + + + template struct tuple_coeff { template - static constexpr DenseIndex get(const DenseIndex i, const std::tuple& t) { - return std::get(t) * (i == Idx) + tuple_coeff::get(i, t) * (i != Idx); + static constexpr DenseIndex get(const DenseIndex i, const IndexTuple& t) { + return array_get(t) * (i == Idx) + tuple_coeff::get(i, t) * (i != Idx); } template - static void set(const DenseIndex i, std::tuple& t, const DenseIndex value) { + static void set(const DenseIndex i, IndexTuple& t, const DenseIndex value) { if (i == Idx) { - update_value(std::get(t), value); + update_value(array_get(t), value); } else { tuple_coeff::set(i, t, value); } } template - static constexpr bool value_known_statically(const DenseIndex i, const std::tuple& t) { - return ((i == Idx) & is_compile_time_constant >::type>::value) || + static constexpr bool value_known_statically(const DenseIndex i, const IndexTuple& t) { + return ((i == Idx) & is_compile_time_constant::ValType>::value) || tuple_coeff::value_known_statically(i, t); } template - static constexpr bool values_up_to_known_statically(const std::tuple& t) { - return is_compile_time_constant >::type>::value && + static constexpr bool values_up_to_known_statically(const IndexTuple& t) { + return is_compile_time_constant::ValType>::value && tuple_coeff::values_up_to_known_statically(t); } template - static constexpr bool values_up_to_statically_known_to_increase(const std::tuple& t) { - return is_compile_time_constant >::type>::value && - is_compile_time_constant >::type>::value && - std::get(t) > std::get(t) && + static constexpr bool values_up_to_statically_known_to_increase(const IndexTuple& t) { + return is_compile_time_constant::ValType>::value && + is_compile_time_constant::ValType>::value && + array_get(t) > array_get(t) && tuple_coeff::values_up_to_statically_known_to_increase(t); } }; @@ -116,62 +206,66 @@ struct tuple_coeff { template <> struct tuple_coeff<0> { template - static constexpr DenseIndex get(const DenseIndex i, const std::tuple& t) { + static constexpr DenseIndex get(const DenseIndex i, const IndexTuple& t) { // eigen_assert (i == 0); // gcc fails to compile assertions in constexpr - return std::get<0>(t) * (i == 0); + return array_get<0>(t) * (i == 0); } template - static void set(const DenseIndex i, std::tuple& t, const DenseIndex value) { + static void set(const DenseIndex i, IndexTuple& t, const DenseIndex value) { eigen_assert (i == 0); - update_value(std::get<0>(t), value); + update_value(array_get<0>(t), value); } template - static constexpr bool value_known_statically(const DenseIndex i, const std::tuple&) { - // eigen_assert (i == 0); // gcc fails to compile assertions in constexpr - return is_compile_time_constant >::type>::value & (i == 0); + static constexpr bool value_known_statically(const DenseIndex i, const IndexTuple&) { + return is_compile_time_constant::ValType>::value & (i == 0); } template - static constexpr bool values_up_to_known_statically(const std::tuple&) { - return is_compile_time_constant >::type>::value; + static constexpr bool values_up_to_known_statically(const IndexTuple&) { + return is_compile_time_constant::ValType>::value; } template - static constexpr bool values_up_to_statically_known_to_increase(const std::tuple&) { + static constexpr bool values_up_to_statically_known_to_increase(const IndexTuple&) { return true; } }; } // namespace internal + template -struct IndexList : std::tuple { + struct IndexList : internal::IndexTuple { EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC constexpr DenseIndex operator[] (const DenseIndex i) const { - return internal::tuple_coeff >::value-1>::get(i, *this); + return internal::tuple_coeff >::value-1>::get(i, *this); + } + EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC constexpr DenseIndex get(const DenseIndex i) const { + return internal::tuple_coeff >::value-1>::get(i, *this); } EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC void set(const DenseIndex i, const DenseIndex value) { - return internal::tuple_coeff >::value-1>::set(i, *this, value); + return internal::tuple_coeff >::value-1>::set(i, *this, value); } - constexpr IndexList(const std::tuple& other) : std::tuple(other) { } - constexpr IndexList() : std::tuple() { } + constexpr IndexList(const internal::IndexTuple& other) : internal::IndexTuple(other) { } + constexpr IndexList(FirstType& first, OtherTypes... other) : internal::IndexTuple(first, other...) { } + constexpr IndexList() : internal::IndexTuple() { } constexpr bool value_known_statically(const DenseIndex i) const { - return internal::tuple_coeff >::value-1>::value_known_statically(i, *this); + return internal::tuple_coeff >::value-1>::value_known_statically(i, *this); } constexpr bool all_values_known_statically() const { - return internal::tuple_coeff >::value-1>::values_up_to_known_statically(*this); + return internal::tuple_coeff >::value-1>::values_up_to_known_statically(*this); } constexpr bool values_statically_known_to_increase() const { - return internal::tuple_coeff >::value-1>::values_up_to_statically_known_to_increase(*this); + return internal::tuple_coeff >::value-1>::values_up_to_statically_known_to_increase(*this); } }; template constexpr IndexList make_index_list(FirstType val1, OtherTypes... other_vals) { - return std::make_tuple(val1, other_vals...); + return IndexList(val1, other_vals...); } @@ -186,17 +280,17 @@ template size_t array_prod(const Ind } template struct array_size > { - static const size_t value = std::tuple_size >::value; + static const size_t value = array_size >::value; }; template struct array_size > { - static const size_t value = std::tuple_size >::value; + static const size_t value = array_size >::value; }; -template constexpr DenseIndex array_get(IndexList& a) { - return std::get(a); +template constexpr DenseIndex array_get(IndexList& a) { + return IndexTupleExtractor::get_val(a); } -template constexpr DenseIndex array_get(const IndexList& a) { - return std::get(a); +template constexpr DenseIndex array_get(const IndexList& a) { + return IndexTupleExtractor::get_val(a); } template @@ -273,7 +367,7 @@ template struct index_statically_eq > { constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { return IndexList().value_known_statically(i) & - (IndexList()[i] == value); + (IndexList().get(i) == value); } }; @@ -281,7 +375,7 @@ template struct index_statically_eq > { constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { return IndexList().value_known_statically(i) & - (IndexList()[i] == value); + (IndexList().get(i) == value); } }; @@ -296,7 +390,7 @@ template struct index_statically_ne > { constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { return IndexList().value_known_statically(i) & - (IndexList()[i] != value); + (IndexList().get(i) != value); } }; @@ -304,7 +398,7 @@ template struct index_statically_ne > { constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { return IndexList().value_known_statically(i) & - (IndexList()[i] != value); + (IndexList().get(i) != value); } }; @@ -320,7 +414,7 @@ template struct index_statically_gt > { constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { return IndexList().value_known_statically(i) & - (IndexList()[i] > value); + (IndexList().get(i) > value); } }; @@ -328,7 +422,7 @@ template struct index_statically_gt > { constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { return IndexList().value_known_statically(i) & - (IndexList()[i] > value); + (IndexList().get(i) > value); } }; @@ -343,7 +437,7 @@ template struct index_statically_lt > { constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { return IndexList().value_known_statically(i) & - (IndexList()[i] < value); + (IndexList().get(i) < value); } }; @@ -351,7 +445,7 @@ template struct index_statically_lt > { constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { return IndexList().value_known_statically(i) & - (IndexList()[i] < value); + (IndexList().get(i) < value); } }; -- cgit v1.2.3