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 const typename internal::nested<Derived,2>::type nested(x);
00038 const typename internal::nested<OtherDerived,2>::type otherNested(y);
00039 return (nested - otherNested).cwiseAbs2().sum() <= prec * prec * std::min(nested.cwiseAbs2().sum(), otherNested.cwiseAbs2().sum());
00040 }
00041 };
00042
00043 template<typename Derived, typename OtherDerived>
00044 struct isApprox_selector<Derived, OtherDerived, true>
00045 {
00046 static bool run(const Derived& x, const OtherDerived& y, typename Derived::RealScalar)
00047 {
00048 return x.matrix() == y.matrix();
00049 }
00050 };
00051
00052 template<typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
00053 struct isMuchSmallerThan_object_selector
00054 {
00055 static bool run(const Derived& x, const OtherDerived& y, typename Derived::RealScalar prec)
00056 {
00057 return x.cwiseAbs2().sum() <= abs2(prec) * y.cwiseAbs2().sum();
00058 }
00059 };
00060
00061 template<typename Derived, typename OtherDerived>
00062 struct isMuchSmallerThan_object_selector<Derived, OtherDerived, true>
00063 {
00064 static bool run(const Derived& x, const OtherDerived&, typename Derived::RealScalar)
00065 {
00066 return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix();
00067 }
00068 };
00069
00070 template<typename Derived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
00071 struct isMuchSmallerThan_scalar_selector
00072 {
00073 static bool run(const Derived& x, const typename Derived::RealScalar& y, typename Derived::RealScalar prec)
00074 {
00075 return x.cwiseAbs2().sum() <= abs2(prec * y);
00076 }
00077 };
00078
00079 template<typename Derived>
00080 struct isMuchSmallerThan_scalar_selector<Derived, true>
00081 {
00082 static bool run(const Derived& x, const typename Derived::RealScalar&, typename Derived::RealScalar)
00083 {
00084 return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix();
00085 }
00086 };
00087
00088 }
00089
00090
00108 template<typename Derived>
00109 template<typename OtherDerived>
00110 bool DenseBase<Derived>::isApprox(
00111 const DenseBase<OtherDerived>& other,
00112 RealScalar prec
00113 ) const
00114 {
00115 return internal::isApprox_selector<Derived, OtherDerived>::run(derived(), other.derived(), prec);
00116 }
00117
00131 template<typename Derived>
00132 bool DenseBase<Derived>::isMuchSmallerThan(
00133 const typename NumTraits<Scalar>::Real& other,
00134 RealScalar prec
00135 ) const
00136 {
00137 return internal::isMuchSmallerThan_scalar_selector<Derived>::run(derived(), other, prec);
00138 }
00139
00150 template<typename Derived>
00151 template<typename OtherDerived>
00152 bool DenseBase<Derived>::isMuchSmallerThan(
00153 const DenseBase<OtherDerived>& other,
00154 RealScalar prec
00155 ) const
00156 {
00157 return internal::isMuchSmallerThan_object_selector<Derived, OtherDerived>::run(derived(), other.derived(), prec);
00158 }
00159
00160 #endif // EIGEN_FUZZY_H