Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
Fuzzy.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2006-2008 Benoit Jacob <[email protected]>
5// Copyright (C) 2008 Gael Guennebaud <[email protected]>
6//
7// This Source Code Form is subject to the terms of the Mozilla
8// Public License v. 2.0. If a copy of the MPL was not distributed
9// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
11#ifndef EIGEN_FUZZY_H
12#define EIGEN_FUZZY_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18
19namespace internal {
20
21template <typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
22struct 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());
28 }
29};
30
31template <typename Derived, typename OtherDerived>
32struct 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();
35 }
36};
37
38template <typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
39struct 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();
42 }
43};
44
45template <typename Derived, typename OtherDerived>
46struct 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();
49 }
50};
51
52template <typename Derived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
53struct 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);
57 }
58};
59
60template <typename Derived>
61struct 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();
65 }
66};
67
68} // end namespace internal
69
87template <typename Derived>
88template <typename OtherDerived>
89EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isApprox(const DenseBase<OtherDerived>& other,
90 const RealScalar& prec) const {
91 return internal::isApprox_selector<Derived, OtherDerived>::run(derived(), other.derived(), prec);
92}
93
107template <typename Derived>
108EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isMuchSmallerThan(const typename NumTraits<Scalar>::Real& other,
109 const RealScalar& prec) const {
110 return internal::isMuchSmallerThan_scalar_selector<Derived>::run(derived(), other, prec);
111}
112
123template <typename Derived>
124template <typename OtherDerived>
126 const RealScalar& prec) const {
127 return internal::isMuchSmallerThan_object_selector<Derived, OtherDerived>::run(derived(), other.derived(), prec);
128}
129
130} // end namespace Eigen
131
132#endif // EIGEN_FUZZY_H
Base class for all dense matrices, vectors, and arrays.
Definition DenseBase.h:44
Derived & derived()
Definition EigenBase.h:49
Namespace containing all symbols from the Eigen library.
Definition Core:137