BooleanRedux.h
Go to the documentation of this file.
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 
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 
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 
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 
00136 template<typename Derived>
00137 inline bool DenseBase<Derived>::hasNaN() const
00138 {
00139   return !((derived().array()==derived().array()).all());
00140 }
00141 
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


turtlebot_exploration_3d
Author(s): Bona , Shawn
autogenerated on Thu Jun 6 2019 20:57:48