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 internal {
00029
00030 template<typename Derived, int UnrollCount>
00031 struct all_unroller
00032 {
00033 enum {
00034 col = (UnrollCount-1) / Derived::RowsAtCompileTime,
00035 row = (UnrollCount-1) % Derived::RowsAtCompileTime
00036 };
00037
00038 inline static bool run(const Derived &mat)
00039 {
00040 return all_unroller<Derived, UnrollCount-1>::run(mat) && mat.coeff(row, col);
00041 }
00042 };
00043
00044 template<typename Derived>
00045 struct all_unroller<Derived, 1>
00046 {
00047 inline static bool run(const Derived &mat) { return mat.coeff(0, 0); }
00048 };
00049
00050 template<typename Derived>
00051 struct all_unroller<Derived, Dynamic>
00052 {
00053 inline static bool run(const Derived &) { return false; }
00054 };
00055
00056 template<typename Derived, int UnrollCount>
00057 struct any_unroller
00058 {
00059 enum {
00060 col = (UnrollCount-1) / Derived::RowsAtCompileTime,
00061 row = (UnrollCount-1) % Derived::RowsAtCompileTime
00062 };
00063
00064 inline static bool run(const Derived &mat)
00065 {
00066 return any_unroller<Derived, UnrollCount-1>::run(mat) || mat.coeff(row, col);
00067 }
00068 };
00069
00070 template<typename Derived>
00071 struct any_unroller<Derived, 1>
00072 {
00073 inline static bool run(const Derived &mat) { return mat.coeff(0, 0); }
00074 };
00075
00076 template<typename Derived>
00077 struct any_unroller<Derived, Dynamic>
00078 {
00079 inline static bool run(const Derived &) { return false; }
00080 };
00081
00082 }
00083
00091 template<typename Derived>
00092 inline bool DenseBase<Derived>::all() const
00093 {
00094 enum {
00095 unroll = SizeAtCompileTime != Dynamic
00096 && CoeffReadCost != Dynamic
00097 && NumTraits<Scalar>::AddCost != Dynamic
00098 && SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT
00099 };
00100 if(unroll)
00101 return internal::all_unroller<Derived,
00102 unroll ? int(SizeAtCompileTime) : Dynamic
00103 >::run(derived());
00104 else
00105 {
00106 for(Index j = 0; j < cols(); ++j)
00107 for(Index i = 0; i < rows(); ++i)
00108 if (!coeff(i, j)) return false;
00109 return true;
00110 }
00111 }
00112
00117 template<typename Derived>
00118 inline bool DenseBase<Derived>::any() const
00119 {
00120 enum {
00121 unroll = SizeAtCompileTime != Dynamic
00122 && CoeffReadCost != Dynamic
00123 && NumTraits<Scalar>::AddCost != Dynamic
00124 && SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT
00125 };
00126 if(unroll)
00127 return internal::any_unroller<Derived,
00128 unroll ? int(SizeAtCompileTime) : Dynamic
00129 >::run(derived());
00130 else
00131 {
00132 for(Index j = 0; j < cols(); ++j)
00133 for(Index i = 0; i < rows(); ++i)
00134 if (coeff(i, j)) return true;
00135 return false;
00136 }
00137 }
00138
00143 template<typename Derived>
00144 inline typename DenseBase<Derived>::Index DenseBase<Derived>::count() const
00145 {
00146 return derived().template cast<bool>().template cast<Index>().sum();
00147 }
00148
00149 #endif // EIGEN_ALLANDANY_H