File indexing completed on 2025-01-18 09:56:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef EIGEN_FUZZY_H
0012 #define EIGEN_FUZZY_H
0013
0014 namespace Eigen {
0015
0016 namespace internal
0017 {
0018
0019 template<typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
0020 struct isApprox_selector
0021 {
0022 EIGEN_DEVICE_FUNC
0023 static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar& prec)
0024 {
0025 typename internal::nested_eval<Derived,2>::type nested(x);
0026 typename internal::nested_eval<OtherDerived,2>::type otherNested(y);
0027 return (nested - otherNested).cwiseAbs2().sum() <= prec * prec * numext::mini(nested.cwiseAbs2().sum(), otherNested.cwiseAbs2().sum());
0028 }
0029 };
0030
0031 template<typename Derived, typename OtherDerived>
0032 struct isApprox_selector<Derived, OtherDerived, true>
0033 {
0034 EIGEN_DEVICE_FUNC
0035 static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar&)
0036 {
0037 return x.matrix() == y.matrix();
0038 }
0039 };
0040
0041 template<typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
0042 struct isMuchSmallerThan_object_selector
0043 {
0044 EIGEN_DEVICE_FUNC
0045 static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar& prec)
0046 {
0047 return x.cwiseAbs2().sum() <= numext::abs2(prec) * y.cwiseAbs2().sum();
0048 }
0049 };
0050
0051 template<typename Derived, typename OtherDerived>
0052 struct isMuchSmallerThan_object_selector<Derived, OtherDerived, true>
0053 {
0054 EIGEN_DEVICE_FUNC
0055 static bool run(const Derived& x, const OtherDerived&, const typename Derived::RealScalar&)
0056 {
0057 return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix();
0058 }
0059 };
0060
0061 template<typename Derived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
0062 struct isMuchSmallerThan_scalar_selector
0063 {
0064 EIGEN_DEVICE_FUNC
0065 static bool run(const Derived& x, const typename Derived::RealScalar& y, const typename Derived::RealScalar& prec)
0066 {
0067 return x.cwiseAbs2().sum() <= numext::abs2(prec * y);
0068 }
0069 };
0070
0071 template<typename Derived>
0072 struct isMuchSmallerThan_scalar_selector<Derived, true>
0073 {
0074 EIGEN_DEVICE_FUNC
0075 static bool run(const Derived& x, const typename Derived::RealScalar&, const typename Derived::RealScalar&)
0076 {
0077 return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix();
0078 }
0079 };
0080
0081 }
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101 template<typename Derived>
0102 template<typename OtherDerived>
0103 EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isApprox(
0104 const DenseBase<OtherDerived>& other,
0105 const RealScalar& prec
0106 ) const
0107 {
0108 return internal::isApprox_selector<Derived, OtherDerived>::run(derived(), other.derived(), prec);
0109 }
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124 template<typename Derived>
0125 EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isMuchSmallerThan(
0126 const typename NumTraits<Scalar>::Real& other,
0127 const RealScalar& prec
0128 ) const
0129 {
0130 return internal::isMuchSmallerThan_scalar_selector<Derived>::run(derived(), other, prec);
0131 }
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143 template<typename Derived>
0144 template<typename OtherDerived>
0145 EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isMuchSmallerThan(
0146 const DenseBase<OtherDerived>& other,
0147 const RealScalar& prec
0148 ) const
0149 {
0150 return internal::isMuchSmallerThan_object_selector<Derived, OtherDerived>::run(derived(), other.derived(), prec);
0151 }
0152
0153 }
0154
0155 #endif