Fuzzy.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) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
00005 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00006 //
00007 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 #ifndef EIGEN_FUZZY_H
00027 #define EIGEN_FUZZY_H
00028 
00029 namespace internal
00030 {
00031 
00032 template<typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
00033 struct isApprox_selector
00034 {
00035   static bool run(const Derived& x, const OtherDerived& y, typename Derived::RealScalar prec)
00036   {
00037     using std::min;
00038     const typename internal::nested<Derived,2>::type nested(x);
00039     const typename internal::nested<OtherDerived,2>::type otherNested(y);
00040     return (nested - otherNested).cwiseAbs2().sum() <= prec * prec * min(nested.cwiseAbs2().sum(), otherNested.cwiseAbs2().sum());
00041   }
00042 };
00043 
00044 template<typename Derived, typename OtherDerived>
00045 struct isApprox_selector<Derived, OtherDerived, true>
00046 {
00047   static bool run(const Derived& x, const OtherDerived& y, typename Derived::RealScalar)
00048   {
00049     return x.matrix() == y.matrix();
00050   }
00051 };
00052 
00053 template<typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
00054 struct isMuchSmallerThan_object_selector
00055 {
00056   static bool run(const Derived& x, const OtherDerived& y, typename Derived::RealScalar prec)
00057   {
00058     return x.cwiseAbs2().sum() <= abs2(prec) * y.cwiseAbs2().sum();
00059   }
00060 };
00061 
00062 template<typename Derived, typename OtherDerived>
00063 struct isMuchSmallerThan_object_selector<Derived, OtherDerived, true>
00064 {
00065   static bool run(const Derived& x, const OtherDerived&, typename Derived::RealScalar)
00066   {
00067     return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix();
00068   }
00069 };
00070 
00071 template<typename Derived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
00072 struct isMuchSmallerThan_scalar_selector
00073 {
00074   static bool run(const Derived& x, const typename Derived::RealScalar& y, typename Derived::RealScalar prec)
00075   {
00076     return x.cwiseAbs2().sum() <= abs2(prec * y);
00077   }
00078 };
00079 
00080 template<typename Derived>
00081 struct isMuchSmallerThan_scalar_selector<Derived, true>
00082 {
00083   static bool run(const Derived& x, const typename Derived::RealScalar&, typename Derived::RealScalar)
00084   {
00085     return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix();
00086   }
00087 };
00088 
00089 } // end namespace internal
00090 
00091 
00109 template<typename Derived>
00110 template<typename OtherDerived>
00111 bool DenseBase<Derived>::isApprox(
00112   const DenseBase<OtherDerived>& other,
00113   RealScalar prec
00114 ) const
00115 {
00116   return internal::isApprox_selector<Derived, OtherDerived>::run(derived(), other.derived(), prec);
00117 }
00118 
00132 template<typename Derived>
00133 bool DenseBase<Derived>::isMuchSmallerThan(
00134   const typename NumTraits<Scalar>::Real& other,
00135   RealScalar prec
00136 ) const
00137 {
00138   return internal::isMuchSmallerThan_scalar_selector<Derived>::run(derived(), other, prec);
00139 }
00140 
00151 template<typename Derived>
00152 template<typename OtherDerived>
00153 bool DenseBase<Derived>::isMuchSmallerThan(
00154   const DenseBase<OtherDerived>& other,
00155   RealScalar prec
00156 ) const
00157 {
00158   return internal::isMuchSmallerThan_object_selector<Derived, OtherDerived>::run(derived(), other.derived(), prec);
00159 }
00160 
00161 #endif // EIGEN_FUZZY_H


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:13