Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
BooleanRedux.h
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> 00005 // 00006 // This Source Code Form is subject to the terms of the Mozilla 00007 // Public License v. 2.0. If a copy of the MPL was not distributed 00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 00009 00010 #ifndef EIGEN_ALLANDANY_H 00011 #define EIGEN_ALLANDANY_H 00012 00013 namespace Eigen { 00014 00015 namespace internal { 00016 00017 template<typename Derived, int UnrollCount> 00018 struct all_unroller 00019 { 00020 enum { 00021 col = (UnrollCount-1) / Derived::RowsAtCompileTime, 00022 row = (UnrollCount-1) % Derived::RowsAtCompileTime 00023 }; 00024 00025 static inline bool run(const Derived &mat) 00026 { 00027 return all_unroller<Derived, UnrollCount-1>::run(mat) && mat.coeff(row, col); 00028 } 00029 }; 00030 00031 template<typename Derived> 00032 struct all_unroller<Derived, 0> 00033 { 00034 static inline bool run(const Derived &/*mat*/) { return true; } 00035 }; 00036 00037 template<typename Derived> 00038 struct all_unroller<Derived, Dynamic> 00039 { 00040 static inline bool run(const Derived &) { return false; } 00041 }; 00042 00043 template<typename Derived, int UnrollCount> 00044 struct any_unroller 00045 { 00046 enum { 00047 col = (UnrollCount-1) / Derived::RowsAtCompileTime, 00048 row = (UnrollCount-1) % Derived::RowsAtCompileTime 00049 }; 00050 00051 static inline bool run(const Derived &mat) 00052 { 00053 return any_unroller<Derived, UnrollCount-1>::run(mat) || mat.coeff(row, col); 00054 } 00055 }; 00056 00057 template<typename Derived> 00058 struct any_unroller<Derived, 0> 00059 { 00060 static inline bool run(const Derived & /*mat*/) { return false; } 00061 }; 00062 00063 template<typename Derived> 00064 struct any_unroller<Derived, Dynamic> 00065 { 00066 static inline bool run(const Derived &) { return false; } 00067 }; 00068 00069 } // end namespace internal 00070 00071 /** \returns true if all coefficients are true 00072 * 00073 * Example: \include MatrixBase_all.cpp 00074 * Output: \verbinclude MatrixBase_all.out 00075 * 00076 * \sa any(), Cwise::operator<() 00077 */ 00078 template<typename Derived> 00079 inline bool DenseBase<Derived>::all() const 00080 { 00081 enum { 00082 unroll = SizeAtCompileTime != Dynamic 00083 && CoeffReadCost != Dynamic 00084 && NumTraits<Scalar>::AddCost != Dynamic 00085 && SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT 00086 }; 00087 if(unroll) 00088 return internal::all_unroller<Derived, unroll ? int(SizeAtCompileTime) : Dynamic>::run(derived()); 00089 else 00090 { 00091 for(Index j = 0; j < cols(); ++j) 00092 for(Index i = 0; i < rows(); ++i) 00093 if (!coeff(i, j)) return false; 00094 return true; 00095 } 00096 } 00097 00098 /** \returns true if at least one coefficient is true 00099 * 00100 * \sa all() 00101 */ 00102 template<typename Derived> 00103 inline bool DenseBase<Derived>::any() const 00104 { 00105 enum { 00106 unroll = SizeAtCompileTime != Dynamic 00107 && CoeffReadCost != Dynamic 00108 && NumTraits<Scalar>::AddCost != Dynamic 00109 && SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT 00110 }; 00111 if(unroll) 00112 return internal::any_unroller<Derived, unroll ? int(SizeAtCompileTime) : Dynamic>::run(derived()); 00113 else 00114 { 00115 for(Index j = 0; j < cols(); ++j) 00116 for(Index i = 0; i < rows(); ++i) 00117 if (coeff(i, j)) return true; 00118 return false; 00119 } 00120 } 00121 00122 /** \returns the number of coefficients which evaluate to true 00123 * 00124 * \sa all(), any() 00125 */ 00126 template<typename Derived> 00127 inline typename DenseBase<Derived>::Index DenseBase<Derived>::count() const 00128 { 00129 return derived().template cast<bool>().template cast<Index>().sum(); 00130 } 00131 00132 /** \returns true is \c *this contains at least one Not A Number (NaN). 00133 * 00134 * \sa allFinite() 00135 */ 00136 template<typename Derived> 00137 inline bool DenseBase<Derived>::hasNaN() const 00138 { 00139 return !((derived().array()==derived().array()).all()); 00140 } 00141 00142 /** \returns true if \c *this contains only finite numbers, i.e., no NaN and no +/-INF values. 00143 * 00144 * \sa hasNaN() 00145 */ 00146 template<typename Derived> 00147 inline bool DenseBase<Derived>::allFinite() const 00148 { 00149 return !((derived()-derived()).hasNaN()); 00150 } 00151 00152 } // end namespace Eigen 00153 00154 #endif // EIGEN_ALLANDANY_H
Generated on Thu Nov 17 2022 22:01:27 by
1.7.2