diff options
author | Benoit Steiner <benoit.steiner.goog@gmail.com> | 2015-11-12 17:19:45 -0800 |
---|---|---|
committer | Benoit Steiner <benoit.steiner.goog@gmail.com> | 2015-11-12 17:19:45 -0800 |
commit | 8037826367a7becab046df2a8be08a28806a625f (patch) | |
tree | 3e14507a5114856077aee8a6c5e6d87eb94616d1 /unsupported/Eigen/CXX11/src/Tensor | |
parent | e9ecfad7967fd5285846647372897ecdc125f976 (diff) |
Simplified more of the IndexList code.
Diffstat (limited to 'unsupported/Eigen/CXX11/src/Tensor')
4 files changed, 119 insertions, 101 deletions
diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorBroadcasting.h b/unsupported/Eigen/CXX11/src/Tensor/TensorBroadcasting.h index c7af02b11..dc64959e1 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorBroadcasting.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorBroadcasting.h @@ -156,11 +156,11 @@ struct TensorEvaluator<const TensorBroadcastingOp<Broadcast, ArgType>, Device> Index inputIndex = 0; for (int i = NumDims - 1; i > 0; --i) { const Index idx = index / m_outputStrides[i]; - if (internal::index_statically_eq<Broadcast>()(i, 1)) { + if (internal::index_statically_eq<Broadcast>(i, 1)) { eigen_assert(idx < m_impl.dimensions()[i]); inputIndex += idx * m_inputStrides[i]; } else { - if (internal::index_statically_eq<InputDimensions>()(i, 1)) { + if (internal::index_statically_eq<InputDimensions>(i, 1)) { eigen_assert(idx % m_impl.dimensions()[i] == 0); } else { inputIndex += (idx % m_impl.dimensions()[i]) * m_inputStrides[i]; @@ -168,11 +168,11 @@ struct TensorEvaluator<const TensorBroadcastingOp<Broadcast, ArgType>, Device> } index -= idx * m_outputStrides[i]; } - if (internal::index_statically_eq<Broadcast>()(0, 1)) { + if (internal::index_statically_eq<Broadcast>(0, 1)) { eigen_assert(index < m_impl.dimensions()[0]); inputIndex += index; } else { - if (internal::index_statically_eq<InputDimensions>()(0, 1)) { + if (internal::index_statically_eq<InputDimensions>(0, 1)) { eigen_assert(index % m_impl.dimensions()[0] == 0); } else { inputIndex += (index % m_impl.dimensions()[0]); @@ -186,11 +186,11 @@ struct TensorEvaluator<const TensorBroadcastingOp<Broadcast, ArgType>, Device> Index inputIndex = 0; for (int i = 0; i < NumDims - 1; ++i) { const Index idx = index / m_outputStrides[i]; - if (internal::index_statically_eq<Broadcast>()(i, 1)) { + if (internal::index_statically_eq<Broadcast>(i, 1)) { eigen_assert(idx < m_impl.dimensions()[i]); inputIndex += idx * m_inputStrides[i]; } else { - if (internal::index_statically_eq<InputDimensions>()(i, 1)) { + if (internal::index_statically_eq<InputDimensions>(i, 1)) { eigen_assert(idx % m_impl.dimensions()[i] == 0); } else { inputIndex += (idx % m_impl.dimensions()[i]) * m_inputStrides[i]; @@ -198,11 +198,11 @@ struct TensorEvaluator<const TensorBroadcastingOp<Broadcast, ArgType>, Device> } index -= idx * m_outputStrides[i]; } - if (internal::index_statically_eq<Broadcast>()(NumDims-1, 1)) { + if (internal::index_statically_eq<Broadcast>(NumDims-1, 1)) { eigen_assert(index < m_impl.dimensions()[NumDims-1]); inputIndex += index; } else { - if (internal::index_statically_eq<InputDimensions>()(NumDims-1, 1)) { + if (internal::index_statically_eq<InputDimensions>(NumDims-1, 1)) { eigen_assert(index % m_impl.dimensions()[NumDims-1] == 0); } else { inputIndex += (index % m_impl.dimensions()[NumDims-1]); @@ -235,11 +235,11 @@ struct TensorEvaluator<const TensorBroadcastingOp<Broadcast, ArgType>, Device> Index inputIndex = 0; for (int i = NumDims - 1; i > 0; --i) { const Index idx = index / m_outputStrides[i]; - if (internal::index_statically_eq<Broadcast>()(i, 1)) { + if (internal::index_statically_eq<Broadcast>(i, 1)) { eigen_assert(idx < m_impl.dimensions()[i]); inputIndex += idx * m_inputStrides[i]; } else { - if (internal::index_statically_eq<InputDimensions>()(i, 1)) { + if (internal::index_statically_eq<InputDimensions>(i, 1)) { eigen_assert(idx % m_impl.dimensions()[i] == 0); } else { inputIndex += (idx % m_impl.dimensions()[i]) * m_inputStrides[i]; @@ -248,11 +248,11 @@ struct TensorEvaluator<const TensorBroadcastingOp<Broadcast, ArgType>, Device> index -= idx * m_outputStrides[i]; } Index innermostLoc; - if (internal::index_statically_eq<Broadcast>()(0, 1)) { + if (internal::index_statically_eq<Broadcast>(0, 1)) { eigen_assert(index < m_impl.dimensions()[0]); innermostLoc = index; } else { - if (internal::index_statically_eq<InputDimensions>()(0, 1)) { + if (internal::index_statically_eq<InputDimensions>(0, 1)) { eigen_assert(index % m_impl.dimensions()[0] == 0); innermostLoc = 0; } else { @@ -288,11 +288,11 @@ struct TensorEvaluator<const TensorBroadcastingOp<Broadcast, ArgType>, Device> Index inputIndex = 0; for (int i = 0; i < NumDims - 1; ++i) { const Index idx = index / m_outputStrides[i]; - if (internal::index_statically_eq<Broadcast>()(i, 1)) { + if (internal::index_statically_eq<Broadcast>(i, 1)) { eigen_assert(idx < m_impl.dimensions()[i]); inputIndex += idx * m_inputStrides[i]; } else { - if (internal::index_statically_eq<InputDimensions>()(i, 1)) { + if (internal::index_statically_eq<InputDimensions>(i, 1)) { eigen_assert(idx % m_impl.dimensions()[i] == 0); } else { inputIndex += (idx % m_impl.dimensions()[i]) * m_inputStrides[i]; @@ -301,11 +301,11 @@ struct TensorEvaluator<const TensorBroadcastingOp<Broadcast, ArgType>, Device> index -= idx * m_outputStrides[i]; } Index innermostLoc; - if (internal::index_statically_eq<Broadcast>()(NumDims-1, 1)) { + if (internal::index_statically_eq<Broadcast>(NumDims-1, 1)) { eigen_assert(index < m_impl.dimensions()[NumDims-1]); innermostLoc = index; } else { - if (internal::index_statically_eq<InputDimensions>()(NumDims-1, 1)) { + if (internal::index_statically_eq<InputDimensions>(NumDims-1, 1)) { eigen_assert(index % m_impl.dimensions()[NumDims-1] == 0); innermostLoc = 0; } else { diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorDimensionList.h b/unsupported/Eigen/CXX11/src/Tensor/TensorDimensionList.h index da7782188..206808245 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorDimensionList.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorDimensionList.h @@ -85,53 +85,53 @@ struct indices_statically_known_to_increase_impl<const DimensionList<Index, Rank }; template <typename Index, std::size_t Rank> -struct index_statically_eq<DimensionList<Index, Rank> > { - constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { +struct index_statically_eq_impl<DimensionList<Index, Rank> > { + static constexpr bool run(const DenseIndex i, const DenseIndex value) { return i == value; } }; template <typename Index, std::size_t Rank> -struct index_statically_eq<const DimensionList<Index, Rank> > { - constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { +struct index_statically_eq_impl<const DimensionList<Index, Rank> > { + static constexpr bool run(const DenseIndex i, const DenseIndex value) { return i == value; } }; template <typename Index, std::size_t Rank> -struct index_statically_ne<DimensionList<Index, Rank> > { - constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { +struct index_statically_ne_impl<DimensionList<Index, Rank> > { + static constexpr bool run(const DenseIndex i, const DenseIndex value) { return i != value; } }; template <typename Index, std::size_t Rank> -struct index_statically_ne<const DimensionList<Index, Rank> > { - constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { +struct index_statically_ne_impl<const DimensionList<Index, Rank> > { + static constexpr bool run(const DenseIndex i, const DenseIndex value) { return i != value; } }; template <typename Index, std::size_t Rank> -struct index_statically_gt<DimensionList<Index, Rank> > { - constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { +struct index_statically_gt_impl<DimensionList<Index, Rank> > { + static constexpr bool run(const DenseIndex i, const DenseIndex value) { return i > value; } }; template <typename Index, std::size_t Rank> -struct index_statically_gt<const DimensionList<Index, Rank> > { - constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { +struct index_statically_gt_impl<const DimensionList<Index, Rank> > { + static constexpr bool run(const DenseIndex i, const DenseIndex value) { return i > value; } }; template <typename Index, std::size_t Rank> -struct index_statically_lt<DimensionList<Index, Rank> > { - constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { +struct index_statically_lt_impl<DimensionList<Index, Rank> > { + static constexpr bool run(const DenseIndex i, const DenseIndex value) { return i < value; } }; template <typename Index, std::size_t Rank> -struct index_statically_lt<const DimensionList<Index, Rank> > { - constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { +struct index_statically_lt_impl<const DimensionList<Index, Rank> > { + static constexpr bool run(const DenseIndex i, const DenseIndex value) { return i < value; } }; @@ -177,53 +177,53 @@ struct indices_statically_known_to_increase_impl<const DimensionList<Index, Rank }; template <typename Index, std::size_t Rank> -struct index_statically_eq<DimensionList<Index, Rank> > { - EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex, const DenseIndex) const { +struct index_statically_eq_impl<DimensionList<Index, Rank> > { + static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(const DenseIndex, const DenseIndex) const { return false; } }; template <typename Index, std::size_t Rank> -struct index_statically_eq<const DimensionList<Index, Rank> > { - EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex, const DenseIndex) const { +struct index_statically_eq_impl<const DimensionList<Index, Rank> > { + static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(const DenseIndex, const DenseIndex) const { return false; } }; template <typename Index, std::size_t Rank> -struct index_statically_ne<DimensionList<Index, Rank> > { - EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex, const DenseIndex) const { +struct index_statically_ne_impl<DimensionList<Index, Rank> > { + static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run() (const DenseIndex, const DenseIndex) const { return false; } }; template <typename Index, std::size_t Rank> -struct index_statically_ne<const DimensionList<Index, Rank> > { - EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex, const DenseIndex) const { +struct index_statically_ne_impl<const DimensionList<Index, Rank> > { + static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(const DenseIndex, const DenseIndex) const { return false; } }; template <typename Index, std::size_t Rank> -struct index_statically_gt<DimensionList<Index, Rank> > { - EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex, const DenseIndex) const { +struct index_statically_gt_impl<DimensionList<Index, Rank> > { + static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run() (const DenseIndex, const DenseIndex) const { return false; } }; template <typename Index, std::size_t Rank> -struct index_statically_gt<const DimensionList<Index, Rank> > { - EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex, const DenseIndex) const { +struct index_statically_gt_impl<const DimensionList<Index, Rank> > { + static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(const DenseIndex, const DenseIndex) const { return false; } }; template <typename Index, std::size_t Rank> -struct index_statically_lt<DimensionList<Index, Rank> > { - EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex, const DenseIndex) const { +struct index_statically_lt_impl<DimensionList<Index, Rank> > { + static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run() (const DenseIndex, const DenseIndex) const { return false; } }; template <typename Index, std::size_t Rank> -struct index_statically_lt<const DimensionList<Index, Rank> > { - EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex, const DenseIndex) const { +struct index_statically_lt_impl<const DimensionList<Index, Rank> > { + static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool run(const DenseIndex, const DenseIndex) const { return false; } }; diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorIndexList.h b/unsupported/Eigen/CXX11/src/Tensor/TensorIndexList.h index 69d21d3c1..472fad0da 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorIndexList.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorIndexList.h @@ -363,98 +363,124 @@ static constexpr bool indices_statically_known_to_increase() { template <typename Tx> -struct index_statically_eq { - constexpr bool operator() (DenseIndex, DenseIndex) const { +struct index_statically_eq_impl { + static constexpr bool run(DenseIndex, DenseIndex) { return false; } }; template <typename FirstType, typename... OtherTypes> -struct index_statically_eq<IndexList<FirstType, OtherTypes...> > { - constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { +struct index_statically_eq_impl<IndexList<FirstType, OtherTypes...> > { + static constexpr bool run(const DenseIndex i, const DenseIndex value) { return IndexList<FirstType, OtherTypes...>().value_known_statically(i) & (IndexList<FirstType, OtherTypes...>().get(i) == value); } }; template <typename FirstType, typename... OtherTypes> -struct index_statically_eq<const IndexList<FirstType, OtherTypes...> > { - constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { +struct index_statically_eq_impl<const IndexList<FirstType, OtherTypes...> > { +static constexpr bool run(const DenseIndex i, const DenseIndex value) { return IndexList<FirstType, OtherTypes...>().value_known_statically(i) & (IndexList<FirstType, OtherTypes...>().get(i) == value); } }; template <typename T> -struct index_statically_ne { - constexpr bool operator() (DenseIndex, DenseIndex) const { - return false; +static constexpr bool index_statically_eq(DenseIndex i, DenseIndex value) { + return index_statically_eq_impl<T>::run(i, value); +} + + +template <typename T> +struct index_statically_ne_impl { + static constexpr bool run(DenseIndex, DenseIndex) { + return false; } }; template <typename FirstType, typename... OtherTypes> -struct index_statically_ne<IndexList<FirstType, OtherTypes...> > { - constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { +struct index_statically_ne_impl<IndexList<FirstType, OtherTypes...> > { + static constexpr bool run(const DenseIndex i, const DenseIndex value) { return IndexList<FirstType, OtherTypes...>().value_known_statically(i) & (IndexList<FirstType, OtherTypes...>().get(i) != value); } }; template <typename FirstType, typename... OtherTypes> -struct index_statically_ne<const IndexList<FirstType, OtherTypes...> > { - constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { +struct index_statically_ne_impl<const IndexList<FirstType, OtherTypes...> > { +static constexpr bool run(const DenseIndex i, const DenseIndex value) { return IndexList<FirstType, OtherTypes...>().value_known_statically(i) & (IndexList<FirstType, OtherTypes...>().get(i) != value); } }; +template <typename T> +static constexpr bool index_statically_ne(DenseIndex i, DenseIndex value) { + return index_statically_ne_impl<T>::run(i, value); +} + + template <typename T> -struct index_statically_gt { - constexpr bool operator() (DenseIndex, DenseIndex) const { - return false; +struct index_statically_gt_impl { + static constexpr bool run(DenseIndex, DenseIndex) { + return false; } }; template <typename FirstType, typename... OtherTypes> -struct index_statically_gt<IndexList<FirstType, OtherTypes...> > { - constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { +struct index_statically_gt_impl<IndexList<FirstType, OtherTypes...> > { + static constexpr bool run(const DenseIndex i, const DenseIndex value) { return IndexList<FirstType, OtherTypes...>().value_known_statically(i) & (IndexList<FirstType, OtherTypes...>().get(i) > value); } }; template <typename FirstType, typename... OtherTypes> -struct index_statically_gt<const IndexList<FirstType, OtherTypes...> > { - constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { +struct index_statically_gt_impl<const IndexList<FirstType, OtherTypes...> > { +static constexpr bool run(const DenseIndex i, const DenseIndex value) { return IndexList<FirstType, OtherTypes...>().value_known_statically(i) & (IndexList<FirstType, OtherTypes...>().get(i) > value); } }; template <typename T> -struct index_statically_lt { - constexpr bool operator() (DenseIndex, DenseIndex) const { - return false; +static constexpr bool index_statically_gt(DenseIndex i, DenseIndex value) { + return index_statically_gt_impl<T>::run(i, value); +} + + + + +template <typename T> +struct index_statically_lt_impl { + static constexpr bool run(DenseIndex, DenseIndex) { + return false; } }; template <typename FirstType, typename... OtherTypes> -struct index_statically_lt<IndexList<FirstType, OtherTypes...> > { - constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { +struct index_statically_lt_impl<IndexList<FirstType, OtherTypes...> > { + static constexpr bool run(const DenseIndex i, const DenseIndex value) { return IndexList<FirstType, OtherTypes...>().value_known_statically(i) & (IndexList<FirstType, OtherTypes...>().get(i) < value); } }; template <typename FirstType, typename... OtherTypes> -struct index_statically_lt<const IndexList<FirstType, OtherTypes...> > { - constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { +struct index_statically_lt_impl<const IndexList<FirstType, OtherTypes...> > { +static constexpr bool run(const DenseIndex i, const DenseIndex value) { return IndexList<FirstType, OtherTypes...>().value_known_statically(i) & (IndexList<FirstType, OtherTypes...>().get(i) < value); } }; +template <typename T> +static constexpr bool index_statically_lt(DenseIndex i, DenseIndex value) { + return index_statically_lt_impl<T>::run(i, value); +} + + } // end namespace internal } // end namespace Eigen @@ -484,32 +510,24 @@ static EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC bool indices_statically_known_to_in } template <typename T> -struct index_statically_eq { - EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC bool operator() (DenseIndex, DenseIndex) const{ - return false; - } -}; +static EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC bool indices_statically_eq(DenseIndex, DenseIndex) { + return false; +} template <typename T> -struct index_statically_ne { - EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC bool operator() (DenseIndex, DenseIndex) const{ - return false; - } -}; +static EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC bool indices_statically_ne(DenseIndex, DenseIndex) { + return false; +} template <typename T> -struct index_statically_gt { - EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC bool operator() (DenseIndex, DenseIndex) const{ - return false; - } -}; +static EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC bool indices_statically_gt(DenseIndex, DenseIndex) { + return false; +} template <typename T> -struct index_statically_lt { - EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC bool operator() (DenseIndex, DenseIndex) const{ - return false; - } -}; +static EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC bool indices_statically_lt(DenseIndex, DenseIndex) { + return false; +} } // end namespace internal } // end namespace Eigen diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorReduction.h b/unsupported/Eigen/CXX11/src/Tensor/TensorReduction.h index 4d3e25d87..bd15295b8 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorReduction.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorReduction.h @@ -89,29 +89,29 @@ struct preserve_inner_most_dims { template <typename ReducedDims, int NumTensorDims> struct are_inner_most_dims<ReducedDims, NumTensorDims, ColMajor>{ static const bool tmp1 = indices_statically_known_to_increase<ReducedDims>(); - static const bool tmp2 = index_statically_eq<ReducedDims>()(0, 0); - static const bool tmp3 = index_statically_eq<ReducedDims>()(array_size<ReducedDims>::value-1, array_size<ReducedDims>::value-1); + static const bool tmp2 = index_statically_eq<ReducedDims>(0, 0); + static const bool tmp3 = index_statically_eq<ReducedDims>(array_size<ReducedDims>::value-1, array_size<ReducedDims>::value-1); static const bool value = tmp1 & tmp2 & tmp3; }; template <typename ReducedDims, int NumTensorDims> struct are_inner_most_dims<ReducedDims, NumTensorDims, RowMajor>{ static const bool tmp1 = indices_statically_known_to_increase<ReducedDims>(); - static const bool tmp2 = index_statically_eq<ReducedDims>()(0, NumTensorDims - array_size<ReducedDims>::value); - static const bool tmp3 = index_statically_eq<ReducedDims>()(array_size<ReducedDims>::value - 1, NumTensorDims - 1); + static const bool tmp2 = index_statically_eq<ReducedDims>(0, NumTensorDims - array_size<ReducedDims>::value); + static const bool tmp3 = index_statically_eq<ReducedDims>(array_size<ReducedDims>::value - 1, NumTensorDims - 1); static const bool value = tmp1 & tmp2 & tmp3; }; template <typename ReducedDims, int NumTensorDims> struct preserve_inner_most_dims<ReducedDims, NumTensorDims, ColMajor>{ static const bool tmp1 = indices_statically_known_to_increase<ReducedDims>(); - static const bool tmp2 = index_statically_gt<ReducedDims>()(0, 0); + static const bool tmp2 = index_statically_gt<ReducedDims>(0, 0); static const bool value = tmp1 & tmp2; }; template <typename ReducedDims, int NumTensorDims> struct preserve_inner_most_dims<ReducedDims, NumTensorDims, RowMajor>{ static const bool tmp1 = indices_statically_known_to_increase<ReducedDims>(); - static const bool tmp2 = index_statically_lt<ReducedDims>()(array_size<ReducedDims>::value - 1, NumTensorDims - 1); + static const bool tmp2 = index_statically_lt<ReducedDims>(array_size<ReducedDims>::value - 1, NumTensorDims - 1); static const bool value = tmp1 & tmp2; }; #endif |