mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 03:39:01 +08:00
Completed the IndexList rewrite
This commit is contained in:
parent
8037826367
commit
150c12e138
@ -46,27 +46,27 @@ template<DenseIndex n, typename Index, std::size_t Rank> const Index array_get(c
|
||||
|
||||
#if defined(EIGEN_HAS_CONSTEXPR)
|
||||
template <typename Index, std::size_t Rank>
|
||||
struct index_known_statically<DimensionList<Index, Rank> > {
|
||||
constexpr bool operator() (const DenseIndex) const {
|
||||
struct index_known_statically_impl<DimensionList<Index, Rank> > {
|
||||
static constexpr bool run(const DenseIndex) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
template <typename Index, std::size_t Rank>
|
||||
struct index_known_statically<const DimensionList<Index, Rank> > {
|
||||
constexpr bool operator() (const DenseIndex) const {
|
||||
struct index_known_statically_impl<const DimensionList<Index, Rank> > {
|
||||
static constexpr bool run(const DenseIndex) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Index, std::size_t Rank>
|
||||
struct all_indices_known_statically<DimensionList<Index, Rank> > {
|
||||
constexpr bool operator() () const {
|
||||
struct all_indices_known_statically_impl<DimensionList<Index, Rank> > {
|
||||
static constexpr bool run() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
template <typename Index, std::size_t Rank>
|
||||
struct all_indices_known_statically<const DimensionList<Index, Rank> > {
|
||||
constexpr bool operator() () const {
|
||||
struct all_indices_known_statically_impl<const DimensionList<Index, Rank> > {
|
||||
static constexpr bool run() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
@ -294,47 +294,57 @@ template<DenseIndex N, typename FirstType, typename... OtherTypes> constexpr Den
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct index_known_statically {
|
||||
constexpr bool operator() (DenseIndex) const {
|
||||
struct index_known_statically_impl {
|
||||
static constexpr bool run(const DenseIndex) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FirstType, typename... OtherTypes>
|
||||
struct index_known_statically<IndexList<FirstType, OtherTypes...> > {
|
||||
constexpr bool operator() (const DenseIndex i) const {
|
||||
struct index_known_statically_impl<IndexList<FirstType, OtherTypes...> > {
|
||||
static constexpr bool run(const DenseIndex i) {
|
||||
return IndexList<FirstType, OtherTypes...>().value_known_statically(i);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FirstType, typename... OtherTypes>
|
||||
struct index_known_statically<const IndexList<FirstType, OtherTypes...> > {
|
||||
constexpr bool operator() (const DenseIndex i) const {
|
||||
struct index_known_statically_impl<const IndexList<FirstType, OtherTypes...> > {
|
||||
static constexpr bool run(const DenseIndex i) {
|
||||
return IndexList<FirstType, OtherTypes...>().value_known_statically(i);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct all_indices_known_statically {
|
||||
constexpr bool operator() () const {
|
||||
static constexpr bool index_known_statically(const DenseIndex i) {
|
||||
return index_known_statically_impl<T>::run(i);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct all_indices_known_statically_impl {
|
||||
static constexpr bool run() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FirstType, typename... OtherTypes>
|
||||
struct all_indices_known_statically<IndexList<FirstType, OtherTypes...> > {
|
||||
constexpr bool operator() () const {
|
||||
struct all_indices_known_statically_impl<IndexList<FirstType, OtherTypes...> > {
|
||||
static constexpr bool run() {
|
||||
return IndexList<FirstType, OtherTypes...>().all_values_known_statically();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FirstType, typename... OtherTypes>
|
||||
struct all_indices_known_statically<const IndexList<FirstType, OtherTypes...> > {
|
||||
constexpr bool operator() () const {
|
||||
struct all_indices_known_statically_impl<const IndexList<FirstType, OtherTypes...> > {
|
||||
static constexpr bool run() {
|
||||
return IndexList<FirstType, OtherTypes...>().all_values_known_statically();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
static constexpr bool all_indices_known_statically() {
|
||||
return all_indices_known_statically_impl<T>::run();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct indices_statically_known_to_increase_impl {
|
||||
static constexpr bool run() {
|
||||
@ -491,18 +501,14 @@ namespace internal {
|
||||
|
||||
// No C++11 support
|
||||
template <typename T>
|
||||
struct index_known_statically {
|
||||
EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC bool operator() (DenseIndex) const{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
static EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC bool index_known_statically(DenseIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct all_indices_known_statically {
|
||||
EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC bool operator() () const {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
static EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC bool all_indices_known_statically() {
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC bool indices_statically_known_to_increase() {
|
||||
|
@ -58,11 +58,11 @@ static void test_type2index_list()
|
||||
typedef Eigen::IndexList<Eigen::type2index<0>, Eigen::type2index<1>, Eigen::type2index<2>, Eigen::type2index<3>, Eigen::type2index<4>> Dims4;
|
||||
|
||||
#if 0
|
||||
EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims0>()() == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims1>()() == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims2>()() == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims3>()() == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims4>()() == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims0>() == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims1>() == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims2>() == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims3>() == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims4>() == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
#endif
|
||||
|
||||
EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims0, 1, ColMajor>::value == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
@ -216,24 +216,24 @@ static void test_mixed_index_list()
|
||||
reduction_indices.set(3, 3);
|
||||
EIGEN_STATIC_ASSERT((internal::array_get<0>(reduction_indices) == 0), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::array_get<2>(reduction_indices) == 2), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::index_known_statically<ReductionIndices>()(0) == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::index_known_statically<ReductionIndices>()(2) == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionIndices>()(0, 0) == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionIndices>()(2, 2) == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::index_known_statically<ReductionIndices>(0) == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::index_known_statically<ReductionIndices>(2) == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionIndices>(0, 0) == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionIndices>(2, 2) == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
#if 0
|
||||
EIGEN_STATIC_ASSERT((internal::all_indices_known_statically<ReductionIndices>()() == false), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<ReductionIndices>()() == false), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::all_indices_known_statically<ReductionIndices>() == false), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<ReductionIndices>() == false), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
#endif
|
||||
|
||||
typedef IndexList<type2index<0>, type2index<1>, type2index<2>, type2index<3>> ReductionList;
|
||||
ReductionList reduction_list;
|
||||
EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>()(0, 0) == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>()(1, 1) == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>()(2, 2) == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>()(3, 3) == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>(0, 0) == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>(1, 1) == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>(2, 2) == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>(3, 3) == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
#if 0
|
||||
EIGEN_STATIC_ASSERT((internal::all_indices_known_statically<ReductionList>()() == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<ReductionList>()() == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::all_indices_known_statically<ReductionList>() == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<ReductionList>() == true), YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
#endif
|
||||
|
||||
Tensor<float, 0> result1 = tensor.sum(reduction_axis);
|
||||
|
Loading…
x
Reference in New Issue
Block a user