File indexing completed on 2025-01-18 09:56:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef EIGEN_ALLANDANY_H
0011 #define EIGEN_ALLANDANY_H
0012
0013 namespace Eigen {
0014
0015 namespace internal {
0016
0017 template<typename Derived, int UnrollCount, int Rows>
0018 struct all_unroller
0019 {
0020 enum {
0021 col = (UnrollCount-1) / Rows,
0022 row = (UnrollCount-1) % Rows
0023 };
0024
0025 EIGEN_DEVICE_FUNC static inline bool run(const Derived &mat)
0026 {
0027 return all_unroller<Derived, UnrollCount-1, Rows>::run(mat) && mat.coeff(row, col);
0028 }
0029 };
0030
0031 template<typename Derived, int Rows>
0032 struct all_unroller<Derived, 0, Rows>
0033 {
0034 EIGEN_DEVICE_FUNC static inline bool run(const Derived &) { return true; }
0035 };
0036
0037 template<typename Derived, int Rows>
0038 struct all_unroller<Derived, Dynamic, Rows>
0039 {
0040 EIGEN_DEVICE_FUNC static inline bool run(const Derived &) { return false; }
0041 };
0042
0043 template<typename Derived, int UnrollCount, int Rows>
0044 struct any_unroller
0045 {
0046 enum {
0047 col = (UnrollCount-1) / Rows,
0048 row = (UnrollCount-1) % Rows
0049 };
0050
0051 EIGEN_DEVICE_FUNC static inline bool run(const Derived &mat)
0052 {
0053 return any_unroller<Derived, UnrollCount-1, Rows>::run(mat) || mat.coeff(row, col);
0054 }
0055 };
0056
0057 template<typename Derived, int Rows>
0058 struct any_unroller<Derived, 0, Rows>
0059 {
0060 EIGEN_DEVICE_FUNC static inline bool run(const Derived & ) { return false; }
0061 };
0062
0063 template<typename Derived, int Rows>
0064 struct any_unroller<Derived, Dynamic, Rows>
0065 {
0066 EIGEN_DEVICE_FUNC static inline bool run(const Derived &) { return false; }
0067 };
0068
0069 }
0070
0071
0072
0073
0074
0075
0076
0077
0078 template<typename Derived>
0079 EIGEN_DEVICE_FUNC inline bool DenseBase<Derived>::all() const
0080 {
0081 typedef internal::evaluator<Derived> Evaluator;
0082 enum {
0083 unroll = SizeAtCompileTime != Dynamic
0084 && SizeAtCompileTime * (int(Evaluator::CoeffReadCost) + int(NumTraits<Scalar>::AddCost)) <= EIGEN_UNROLLING_LIMIT
0085 };
0086 Evaluator evaluator(derived());
0087 if(unroll)
0088 return internal::all_unroller<Evaluator, unroll ? int(SizeAtCompileTime) : Dynamic, internal::traits<Derived>::RowsAtCompileTime>::run(evaluator);
0089 else
0090 {
0091 for(Index j = 0; j < cols(); ++j)
0092 for(Index i = 0; i < rows(); ++i)
0093 if (!evaluator.coeff(i, j)) return false;
0094 return true;
0095 }
0096 }
0097
0098
0099
0100
0101
0102 template<typename Derived>
0103 EIGEN_DEVICE_FUNC inline bool DenseBase<Derived>::any() const
0104 {
0105 typedef internal::evaluator<Derived> Evaluator;
0106 enum {
0107 unroll = SizeAtCompileTime != Dynamic
0108 && SizeAtCompileTime * (int(Evaluator::CoeffReadCost) + int(NumTraits<Scalar>::AddCost)) <= EIGEN_UNROLLING_LIMIT
0109 };
0110 Evaluator evaluator(derived());
0111 if(unroll)
0112 return internal::any_unroller<Evaluator, unroll ? int(SizeAtCompileTime) : Dynamic, internal::traits<Derived>::RowsAtCompileTime>::run(evaluator);
0113 else
0114 {
0115 for(Index j = 0; j < cols(); ++j)
0116 for(Index i = 0; i < rows(); ++i)
0117 if (evaluator.coeff(i, j)) return true;
0118 return false;
0119 }
0120 }
0121
0122
0123
0124
0125
0126 template<typename Derived>
0127 EIGEN_DEVICE_FUNC inline Eigen::Index DenseBase<Derived>::count() const
0128 {
0129 return derived().template cast<bool>().template cast<Index>().sum();
0130 }
0131
0132
0133
0134
0135
0136 template<typename Derived>
0137 inline bool DenseBase<Derived>::hasNaN() const
0138 {
0139 #if EIGEN_COMP_MSVC || (defined __FAST_MATH__)
0140 return derived().array().isNaN().any();
0141 #else
0142 return !((derived().array()==derived().array()).all());
0143 #endif
0144 }
0145
0146
0147
0148
0149
0150 template<typename Derived>
0151 inline bool DenseBase<Derived>::allFinite() const
0152 {
0153 #if EIGEN_COMP_MSVC || (defined __FAST_MATH__)
0154 return derived().array().isFinite().all();
0155 #else
0156 return !((derived()-derived()).hasNaN());
0157 #endif
0158 }
0159
0160 }
0161
0162 #endif