Go to the documentation of this file.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
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 }
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