* added cwise comparisons

* added "all" and "any" special redux operators
 * added support bool matrices
 * added support for cost model of STL functors via ei_functor_traits
  (By default ei_functor_traits query the functor member Cost)
This commit is contained in:
Gael Guennebaud
2008-04-03 18:13:27 +00:00
parent 249dc4f482
commit 048910caae
8 changed files with 282 additions and 11 deletions

View File

@@ -232,4 +232,102 @@ MatrixBase<Derived>::maxCoeff() const
return this->redux(Eigen::ei_scalar_max_op<Scalar>());
}
template<typename Derived, int UnrollCount>
struct ei_all_unroller
{
enum {
col = (UnrollCount-1) / Derived::RowsAtCompileTime,
row = (UnrollCount-1) % Derived::RowsAtCompileTime
};
static bool run(const Derived &mat)
{
return ei_all_unroller<Derived, UnrollCount-1>::run(mat) && mat.coeff(row, col);
}
};
template<typename Derived>
struct ei_all_unroller<Derived, 1>
{
static bool run(const Derived &mat) { return mat.coeff(0, 0); }
};
template<typename Derived>
struct ei_all_unroller<Derived, Dynamic>
{
static bool run(const Derived &) { return false; }
};
template<typename Derived, int UnrollCount>
struct ei_any_unroller
{
enum {
col = (UnrollCount-1) / Derived::RowsAtCompileTime,
row = (UnrollCount-1) % Derived::RowsAtCompileTime
};
static bool run(const Derived &mat)
{
return ei_any_unroller<Derived, UnrollCount-1>::run(mat) || mat.coeff(row, col);
}
};
template<typename Derived>
struct ei_any_unroller<Derived, 1>
{
static bool run(const Derived &mat) { return mat.coeff(0, 0); }
};
template<typename Derived>
struct ei_any_unroller<Derived, Dynamic>
{
static bool run(const Derived &) { return false; }
};
/** \returns true if all coefficients are true
*
* \sa MatrixBase::any()
*/
template<typename Derived>
bool MatrixBase<Derived>::all(void) const
{
if(EIGEN_UNROLLED_LOOPS
&& SizeAtCompileTime != Dynamic
&& SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT)
return ei_all_unroller<Derived,
(SizeAtCompileTime>0 && SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT) ?
SizeAtCompileTime : Dynamic>::run(derived());
else
{
for(int j = 0; j < cols(); j++)
for(int i = 0; i < rows(); i++)
if (!coeff(i, j)) return false;
return true;
}
}
/** \returns true if at least one coefficient is true
*
* \sa MatrixBase::any()
*/
template<typename Derived>
bool MatrixBase<Derived>::any(void) const
{
if(EIGEN_UNROLLED_LOOPS
&& SizeAtCompileTime != Dynamic
&& SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT)
return ei_any_unroller<Derived,
(SizeAtCompileTime>0 && SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT) ?
SizeAtCompileTime : Dynamic>::run(derived());
else
{
for(int j = 0; j < cols(); j++)
for(int i = 0; i < rows(); i++)
if (coeff(i, j)) return true;
return false;
}
}
#endif // EIGEN_REDUX_H