Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef EIGEN_ALLANDANY_H
00026 #define EIGEN_ALLANDANY_H
00027
00028 namespace Eigen {
00029
00030 namespace internal {
00031
00032 template<typename Derived, int UnrollCount>
00033 struct all_unroller
00034 {
00035 enum {
00036 col = (UnrollCount-1) / Derived::RowsAtCompileTime,
00037 row = (UnrollCount-1) % Derived::RowsAtCompileTime
00038 };
00039
00040 static inline bool run(const Derived &mat)
00041 {
00042 return all_unroller<Derived, UnrollCount-1>::run(mat) && mat.coeff(row, col);
00043 }
00044 };
00045
00046 template<typename Derived>
00047 struct all_unroller<Derived, 1>
00048 {
00049 static inline bool run(const Derived &mat) { return mat.coeff(0, 0); }
00050 };
00051
00052 template<typename Derived>
00053 struct all_unroller<Derived, Dynamic>
00054 {
00055 static inline bool run(const Derived &) { return false; }
00056 };
00057
00058 template<typename Derived, int UnrollCount>
00059 struct any_unroller
00060 {
00061 enum {
00062 col = (UnrollCount-1) / Derived::RowsAtCompileTime,
00063 row = (UnrollCount-1) % Derived::RowsAtCompileTime
00064 };
00065
00066 static inline bool run(const Derived &mat)
00067 {
00068 return any_unroller<Derived, UnrollCount-1>::run(mat) || mat.coeff(row, col);
00069 }
00070 };
00071
00072 template<typename Derived>
00073 struct any_unroller<Derived, 1>
00074 {
00075 static inline bool run(const Derived &mat) { return mat.coeff(0, 0); }
00076 };
00077
00078 template<typename Derived>
00079 struct any_unroller<Derived, Dynamic>
00080 {
00081 static inline bool run(const Derived &) { return false; }
00082 };
00083
00084 }
00085
00093 template<typename Derived>
00094 inline bool DenseBase<Derived>::all() const
00095 {
00096 enum {
00097 unroll = SizeAtCompileTime != Dynamic
00098 && CoeffReadCost != Dynamic
00099 && NumTraits<Scalar>::AddCost != Dynamic
00100 && SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT
00101 };
00102 if(unroll)
00103 return internal::all_unroller<Derived,
00104 unroll ? int(SizeAtCompileTime) : Dynamic
00105 >::run(derived());
00106 else
00107 {
00108 for(Index j = 0; j < cols(); ++j)
00109 for(Index i = 0; i < rows(); ++i)
00110 if (!coeff(i, j)) return false;
00111 return true;
00112 }
00113 }
00114
00119 template<typename Derived>
00120 inline bool DenseBase<Derived>::any() const
00121 {
00122 enum {
00123 unroll = SizeAtCompileTime != Dynamic
00124 && CoeffReadCost != Dynamic
00125 && NumTraits<Scalar>::AddCost != Dynamic
00126 && SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT
00127 };
00128 if(unroll)
00129 return internal::any_unroller<Derived,
00130 unroll ? int(SizeAtCompileTime) : Dynamic
00131 >::run(derived());
00132 else
00133 {
00134 for(Index j = 0; j < cols(); ++j)
00135 for(Index i = 0; i < rows(); ++i)
00136 if (coeff(i, j)) return true;
00137 return false;
00138 }
00139 }
00140
00145 template<typename Derived>
00146 inline typename DenseBase<Derived>::Index DenseBase<Derived>::count() const
00147 {
00148 return derived().template cast<bool>().template cast<Index>().sum();
00149 }
00150
00151 }
00152
00153 #endif // EIGEN_ALLANDANY_H