diff --git a/Eigen/src/Core/BooleanRedux.h b/Eigen/src/Core/BooleanRedux.h index 78939a6e8..8e1d9059f 100644 --- a/Eigen/src/Core/BooleanRedux.h +++ b/Eigen/src/Core/BooleanRedux.h @@ -12,58 +12,60 @@ #include "./InternalHeaderCheck.h" -namespace Eigen { +namespace Eigen { namespace internal { -template +template struct all_unroller { enum { - col = (UnrollCount-1) / Rows, - row = (UnrollCount-1) % Rows + IsRowMajor = (Derived::Flags & RowMajor), + i = (UnrollCount-1) / InnerSize, + j = (UnrollCount-1) % InnerSize }; EIGEN_DEVICE_FUNC static inline bool run(const Derived &mat) { - return all_unroller::run(mat) && mat.coeff(row, col); + return all_unroller::run(mat) && mat.coeff(IsRowMajor ? i : j, IsRowMajor ? j : i); } }; -template -struct all_unroller +template +struct all_unroller { EIGEN_DEVICE_FUNC static inline bool run(const Derived &/*mat*/) { return true; } }; -template -struct all_unroller +template +struct all_unroller { EIGEN_DEVICE_FUNC static inline bool run(const Derived &) { return false; } }; -template +template struct any_unroller { enum { - col = (UnrollCount-1) / Rows, - row = (UnrollCount-1) % Rows + IsRowMajor = (Derived::Flags & RowMajor), + i = (UnrollCount-1) / InnerSize, + j = (UnrollCount-1) % InnerSize }; - + EIGEN_DEVICE_FUNC static inline bool run(const Derived &mat) { - return any_unroller::run(mat) || mat.coeff(row, col); + return any_unroller::run(mat) || mat.coeff(IsRowMajor ? i : j, IsRowMajor ? j : i); } }; -template -struct any_unroller +template +struct any_unroller { EIGEN_DEVICE_FUNC static inline bool run(const Derived & /*mat*/) { return false; } }; -template -struct any_unroller +template +struct any_unroller { EIGEN_DEVICE_FUNC static inline bool run(const Derived &) { return false; } }; @@ -83,16 +85,18 @@ EIGEN_DEVICE_FUNC inline bool DenseBase::all() const typedef internal::evaluator Evaluator; enum { unroll = SizeAtCompileTime != Dynamic - && SizeAtCompileTime * (int(Evaluator::CoeffReadCost) + int(NumTraits::AddCost)) <= EIGEN_UNROLLING_LIMIT + && SizeAtCompileTime * (int(Evaluator::CoeffReadCost) + int(NumTraits::AddCost)) <= EIGEN_UNROLLING_LIMIT, + IsRowMajor = (internal::traits::Flags & RowMajor), + InnerSizeAtCompileTime = IsRowMajor ? internal::traits::ColsAtCompileTime : internal::traits::RowsAtCompileTime }; Evaluator evaluator(derived()); if(unroll) - return internal::all_unroller::RowsAtCompileTime>::run(evaluator); + return internal::all_unroller::run(evaluator); else { - for(Index j = 0; j < cols(); ++j) - for(Index i = 0; i < rows(); ++i) - if (!evaluator.coeff(i, j)) return false; + for(Index i = 0; i < derived().outerSize(); ++i) + for(Index j = 0; j < derived().innerSize(); ++j) + if (!evaluator.coeff(IsRowMajor ? i : j, IsRowMajor ? j : i)) return false; return true; } } @@ -107,16 +111,18 @@ EIGEN_DEVICE_FUNC inline bool DenseBase::any() const typedef internal::evaluator Evaluator; enum { unroll = SizeAtCompileTime != Dynamic - && SizeAtCompileTime * (int(Evaluator::CoeffReadCost) + int(NumTraits::AddCost)) <= EIGEN_UNROLLING_LIMIT + && SizeAtCompileTime * (int(Evaluator::CoeffReadCost) + int(NumTraits::AddCost)) <= EIGEN_UNROLLING_LIMIT, + IsRowMajor = (internal::traits::Flags & RowMajor), + InnerSizeAtCompileTime = IsRowMajor ? internal::traits::ColsAtCompileTime : internal::traits::RowsAtCompileTime }; Evaluator evaluator(derived()); if(unroll) - return internal::any_unroller::RowsAtCompileTime>::run(evaluator); + return internal::any_unroller::run(evaluator); else { - for(Index j = 0; j < cols(); ++j) - for(Index i = 0; i < rows(); ++i) - if (evaluator.coeff(i, j)) return true; + for(Index i = 0; i < derived().outerSize(); ++i) + for(Index j = 0; j < derived().innerSize(); ++j) + if (evaluator.coeff(IsRowMajor ? i : j, IsRowMajor ? j : i)) return true; return false; } } @@ -158,7 +164,7 @@ EIGEN_DEVICE_FUNC inline bool DenseBase::allFinite() const return !((derived()-derived()).hasNaN()); #endif } - + } // end namespace Eigen #endif // EIGEN_ALLANDANY_H