mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 19:59:05 +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>
|
template<typename Derived, int UnrollCount>
|
||||||
struct all_unroller
|
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 {
|
enum {
|
||||||
col = (UnrollCount-1) / Derived::RowsAtCompileTime,
|
col = (UnrollCount-1) / Derived::RowsAtCompileTime,
|
||||||
row = (UnrollCount-1) % Derived::RowsAtCompileTime
|
row = (UnrollCount-1) % Derived::RowsAtCompileTime
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
static inline bool run(const Derived &mat)
|
static inline bool run(const Derived &mat)
|
||||||
{
|
{
|
||||||
@ -43,10 +51,18 @@ struct all_unroller<Derived, Dynamic>
|
|||||||
template<typename Derived, int UnrollCount>
|
template<typename Derived, int UnrollCount>
|
||||||
struct any_unroller
|
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 {
|
enum {
|
||||||
col = (UnrollCount-1) / Derived::RowsAtCompileTime,
|
col = (UnrollCount-1) / Derived::RowsAtCompileTime,
|
||||||
row = (UnrollCount-1) % Derived::RowsAtCompileTime
|
row = (UnrollCount-1) % Derived::RowsAtCompileTime
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
static inline bool run(const Derived &mat)
|
static inline bool run(const Derived &mat)
|
||||||
{
|
{
|
||||||
@ -84,6 +100,19 @@ inline bool DenseBase<Derived>::all() const
|
|||||||
&& NumTraits<Scalar>::AddCost != Dynamic
|
&& NumTraits<Scalar>::AddCost != Dynamic
|
||||||
&& SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT
|
&& 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)
|
if(unroll)
|
||||||
return internal::all_unroller<Derived, unroll ? int(SizeAtCompileTime) : Dynamic>::run(derived());
|
return internal::all_unroller<Derived, unroll ? int(SizeAtCompileTime) : Dynamic>::run(derived());
|
||||||
else
|
else
|
||||||
@ -93,6 +122,7 @@ inline bool DenseBase<Derived>::all() const
|
|||||||
if (!coeff(i, j)) return false;
|
if (!coeff(i, j)) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \returns true if at least one coefficient is true
|
/** \returns true if at least one coefficient is true
|
||||||
@ -108,6 +138,19 @@ inline bool DenseBase<Derived>::any() const
|
|||||||
&& NumTraits<Scalar>::AddCost != Dynamic
|
&& NumTraits<Scalar>::AddCost != Dynamic
|
||||||
&& SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT
|
&& 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)
|
if(unroll)
|
||||||
return internal::any_unroller<Derived, unroll ? int(SizeAtCompileTime) : Dynamic>::run(derived());
|
return internal::any_unroller<Derived, unroll ? int(SizeAtCompileTime) : Dynamic>::run(derived());
|
||||||
else
|
else
|
||||||
@ -117,6 +160,7 @@ inline bool DenseBase<Derived>::any() const
|
|||||||
if (coeff(i, j)) return true;
|
if (coeff(i, j)) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \returns the number of coefficients which evaluate to true
|
/** \returns the number of coefficients which evaluate to true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user