aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/BooleanRedux.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2014-02-18 14:26:25 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2014-02-18 14:26:25 +0100
commit99e27916cfd1381aab50850611905335c288ee40 (patch)
tree1e08f4978cf03d35b80832b31db37783d32fd6b2 /Eigen/src/Core/BooleanRedux.h
parent06545058bbdeec4713b9b31c5018335660796076 (diff)
Fix all()/any() for evaluators
Diffstat (limited to 'Eigen/src/Core/BooleanRedux.h')
-rw-r--r--Eigen/src/Core/BooleanRedux.h46
1 files changed, 45 insertions, 1 deletions
diff --git a/Eigen/src/Core/BooleanRedux.h b/Eigen/src/Core/BooleanRedux.h
index be9f48a8c..f0b68f470 100644
--- a/Eigen/src/Core/BooleanRedux.h
+++ b/Eigen/src/Core/BooleanRedux.h
@@ -17,10 +17,18 @@ namespace internal {
template<typename Derived, int UnrollCount>
struct all_unroller
{
+#ifdef EIGEN_TEST_EVALUATORS
+ typedef typename Derived::ExpressionTraits Traits;
+ enum {
+ col = (UnrollCount-1) / Traits::RowsAtCompileTime,
+ row = (UnrollCount-1) % Traits::RowsAtCompileTime
+ };
+#else
enum {
col = (UnrollCount-1) / Derived::RowsAtCompileTime,
row = (UnrollCount-1) % Derived::RowsAtCompileTime
};
+#endif
static inline bool run(const Derived &mat)
{
@@ -43,11 +51,19 @@ struct all_unroller<Derived, Dynamic>
template<typename Derived, int UnrollCount>
struct any_unroller
{
+#ifdef EIGEN_TEST_EVALUATORS
+ typedef typename Derived::ExpressionTraits Traits;
+ enum {
+ col = (UnrollCount-1) / Traits::RowsAtCompileTime,
+ row = (UnrollCount-1) % Traits::RowsAtCompileTime
+ };
+#else
enum {
col = (UnrollCount-1) / Derived::RowsAtCompileTime,
row = (UnrollCount-1) % Derived::RowsAtCompileTime
};
-
+#endif
+
static inline bool run(const Derived &mat)
{
return any_unroller<Derived, UnrollCount-1>::run(mat) || mat.coeff(row, col);
@@ -84,6 +100,19 @@ inline bool DenseBase<Derived>::all() const
&& NumTraits<Scalar>::AddCost != Dynamic
&& SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT
};
+#ifdef EIGEN_TEST_EVALUATORS
+ typedef typename internal::evaluator<Derived>::type Evaluator;
+ Evaluator evaluator(derived());
+ if(unroll)
+ return internal::all_unroller<Evaluator, unroll ? int(SizeAtCompileTime) : Dynamic>::run(evaluator);
+ else
+ {
+ for(Index j = 0; j < cols(); ++j)
+ for(Index i = 0; i < rows(); ++i)
+ if (!evaluator.coeff(i, j)) return false;
+ return true;
+ }
+#else
if(unroll)
return internal::all_unroller<Derived, unroll ? int(SizeAtCompileTime) : Dynamic>::run(derived());
else
@@ -93,6 +122,7 @@ inline bool DenseBase<Derived>::all() const
if (!coeff(i, j)) return false;
return true;
}
+#endif
}
/** \returns true if at least one coefficient is true
@@ -108,6 +138,19 @@ inline bool DenseBase<Derived>::any() const
&& NumTraits<Scalar>::AddCost != Dynamic
&& SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT
};
+#ifdef EIGEN_TEST_EVALUATORS
+ typedef typename internal::evaluator<Derived>::type Evaluator;
+ Evaluator evaluator(derived());
+ if(unroll)
+ return internal::any_unroller<Evaluator, unroll ? int(SizeAtCompileTime) : Dynamic>::run(evaluator);
+ else
+ {
+ for(Index j = 0; j < cols(); ++j)
+ for(Index i = 0; i < rows(); ++i)
+ if (evaluator.coeff(i, j)) return true;
+ return false;
+ }
+#else
if(unroll)
return internal::any_unroller<Derived, unroll ? int(SizeAtCompileTime) : Dynamic>::run(derived());
else
@@ -117,6 +160,7 @@ inline bool DenseBase<Derived>::any() const
if (coeff(i, j)) return true;
return false;
}
+#endif
}
/** \returns the number of coefficients which evaluate to true