34 template<typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
35 struct isApprox_selector
37 static bool run(
const Derived& x,
const OtherDerived&
y,
typename Derived::RealScalar prec)
40 typename internal::nested<Derived,2>::type nested(x);
41 typename internal::nested<OtherDerived,2>::type otherNested(y);
42 return (nested - otherNested).cwiseAbs2().sum() <= prec * prec * (min)(nested.cwiseAbs2().sum(), otherNested.cwiseAbs2().sum());
46 template<
typename Derived,
typename OtherDerived>
47 struct isApprox_selector<Derived, OtherDerived, true>
49 static bool run(
const Derived& x,
const OtherDerived& y,
typename Derived::RealScalar)
51 return x.matrix() == y.matrix();
55 template<typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
56 struct isMuchSmallerThan_object_selector
58 static bool run(
const Derived& x,
const OtherDerived& y,
typename Derived::RealScalar prec)
60 return x.cwiseAbs2().sum() <=
abs2(prec) * y.cwiseAbs2().sum();
64 template<
typename Derived,
typename OtherDerived>
65 struct isMuchSmallerThan_object_selector<Derived, OtherDerived, true>
67 static bool run(
const Derived& x,
const OtherDerived&,
typename Derived::RealScalar)
69 return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix();
73 template<typename Derived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
74 struct isMuchSmallerThan_scalar_selector
76 static bool run(
const Derived& x,
const typename Derived::RealScalar& y,
typename Derived::RealScalar prec)
78 return x.cwiseAbs2().sum() <=
abs2(prec * y);
82 template<
typename Derived>
83 struct isMuchSmallerThan_scalar_selector<Derived, true>
85 static bool run(
const Derived& x,
const typename Derived::RealScalar&,
typename Derived::RealScalar)
87 return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix();
111 template<
typename Derived>
112 template<
typename OtherDerived>
118 return internal::isApprox_selector<Derived, OtherDerived>::run(derived(), other.derived(), prec);
134 template<
typename Derived>
140 return internal::isMuchSmallerThan_scalar_selector<Derived>::run(derived(), other, prec);
153 template<
typename Derived>
154 template<
typename OtherDerived>
160 return internal::isMuchSmallerThan_object_selector<Derived, OtherDerived>::run(derived(), other.derived(), prec);
165 #endif // EIGEN_FUZZY_H