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