mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 03:39:01 +08:00
Fix all()/any() for evaluators
This commit is contained in:
parent
06545058bb
commit
99e27916cf
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user