15 #include "./InternalHeaderCheck.h" 21 template <typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
22 struct isApprox_selector {
23 EIGEN_DEVICE_FUNC
static bool run(
const Derived& x,
const OtherDerived& y,
const typename Derived::RealScalar& prec) {
24 typename internal::nested_eval<Derived, 2>::type nested(x);
25 typename internal::nested_eval<OtherDerived, 2>::type otherNested(y);
26 return (nested.matrix() - otherNested.matrix()).cwiseAbs2().sum() <=
27 prec * prec * numext::mini(nested.cwiseAbs2().sum(), otherNested.cwiseAbs2().sum());
31 template <
typename Derived,
typename OtherDerived>
32 struct isApprox_selector<Derived, OtherDerived, true> {
33 EIGEN_DEVICE_FUNC
static bool run(
const Derived& x,
const OtherDerived& y,
const typename Derived::RealScalar&) {
34 return x.matrix() == y.matrix();
38 template <typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
39 struct isMuchSmallerThan_object_selector {
40 EIGEN_DEVICE_FUNC
static bool run(
const Derived& x,
const OtherDerived& y,
const typename Derived::RealScalar& prec) {
41 return x.cwiseAbs2().sum() <= numext::abs2(prec) * y.cwiseAbs2().sum();
45 template <
typename Derived,
typename OtherDerived>
46 struct isMuchSmallerThan_object_selector<Derived, OtherDerived, true> {
47 EIGEN_DEVICE_FUNC
static bool run(
const Derived& x,
const OtherDerived&,
const typename Derived::RealScalar&) {
48 return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix();
52 template <typename Derived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
53 struct isMuchSmallerThan_scalar_selector {
54 EIGEN_DEVICE_FUNC
static bool run(
const Derived& x,
const typename Derived::RealScalar& y,
55 const typename Derived::RealScalar& prec) {
56 return x.cwiseAbs2().sum() <= numext::abs2(prec * y);
60 template <
typename Derived>
61 struct isMuchSmallerThan_scalar_selector<Derived, true> {
62 EIGEN_DEVICE_FUNC
static bool run(
const Derived& x,
const typename Derived::RealScalar&,
63 const typename Derived::RealScalar&) {
64 return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix();
87 template <
typename Derived>
88 template <
typename OtherDerived>
90 const RealScalar& prec)
const {
91 return internal::isApprox_selector<Derived, OtherDerived>::run(derived(), other.
derived(), prec);
107 template <
typename Derived>
109 const RealScalar& prec)
const {
110 return internal::isMuchSmallerThan_scalar_selector<Derived>::run(derived(), other, prec);
123 template <
typename Derived>
124 template <
typename OtherDerived>
126 const RealScalar& prec)
const {
127 return internal::isMuchSmallerThan_object_selector<Derived, OtherDerived>::run(derived(), other.
derived(), prec);
132 #endif // EIGEN_FUZZY_H constexpr Derived & derived()
Definition: EigenBase.h:49
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:232
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:38
bool isApprox(const DenseBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: Fuzzy.h:89