Fuzzy.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
5 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
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 namespace Eigen {
15 
16 namespace internal
17 {
18 
19 template<typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
21 {
22  static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar& prec)
23  {
24  using std::min;
26  typename internal::nested<OtherDerived,2>::type otherNested(y);
27  return (nested - otherNested).cwiseAbs2().sum() <= prec * prec * (min)(nested.cwiseAbs2().sum(), otherNested.cwiseAbs2().sum());
28  }
29 };
30 
31 template<typename Derived, typename OtherDerived>
32 struct isApprox_selector<Derived, OtherDerived, true>
33 {
34  static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar&)
35  {
36  return x.matrix() == y.matrix();
37  }
38 };
39 
40 template<typename Derived, typename OtherDerived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
42 {
43  static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar& prec)
44  {
45  return x.cwiseAbs2().sum() <= numext::abs2(prec) * y.cwiseAbs2().sum();
46  }
47 };
48 
49 template<typename Derived, typename OtherDerived>
50 struct isMuchSmallerThan_object_selector<Derived, OtherDerived, true>
51 {
52  static bool run(const Derived& x, const OtherDerived&, const typename Derived::RealScalar&)
53  {
54  return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix();
55  }
56 };
57 
58 template<typename Derived, bool is_integer = NumTraits<typename Derived::Scalar>::IsInteger>
60 {
61  static bool run(const Derived& x, const typename Derived::RealScalar& y, const typename Derived::RealScalar& prec)
62  {
63  return x.cwiseAbs2().sum() <= numext::abs2(prec * y);
64  }
65 };
66 
67 template<typename Derived>
68 struct isMuchSmallerThan_scalar_selector<Derived, true>
69 {
70  static bool run(const Derived& x, const typename Derived::RealScalar&, const typename Derived::RealScalar&)
71  {
72  return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix();
73  }
74 };
75 
76 } // end namespace internal
77 
78 
96 template<typename Derived>
97 template<typename OtherDerived>
99  const DenseBase<OtherDerived>& other,
100  const RealScalar& prec
101 ) const
102 {
103  return internal::isApprox_selector<Derived, OtherDerived>::run(derived(), other.derived(), prec);
104 }
105 
119 template<typename Derived>
121  const typename NumTraits<Scalar>::Real& other,
122  const RealScalar& prec
123 ) const
124 {
125  return internal::isMuchSmallerThan_scalar_selector<Derived>::run(derived(), other, prec);
126 }
127 
138 template<typename Derived>
139 template<typename OtherDerived>
141  const DenseBase<OtherDerived>& other,
142  const RealScalar& prec
143 ) const
144 {
145  return internal::isMuchSmallerThan_object_selector<Derived, OtherDerived>::run(derived(), other.derived(), prec);
146 }
147 
148 } // end namespace Eigen
149 
150 #endif // EIGEN_FUZZY_H
static bool run(const Derived &x, const OtherDerived &y, const typename Derived::RealScalar &prec)
Definition: Fuzzy.h:22
bool isApprox(const DenseBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: Fuzzy.h:98
static bool run(const Derived &x, const typename Derived::RealScalar &y, const typename Derived::RealScalar &prec)
Definition: Fuzzy.h:61
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
static bool run(const Derived &x, const OtherDerived &, const typename Derived::RealScalar &)
Definition: Fuzzy.h:52
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
EIGEN_STRONG_INLINE const CwiseUnaryOp< internal::scalar_abs2_op< Scalar >, const Derived > abs2() const
NumTraits< Scalar >::Real RealScalar
Definition: DenseBase.h:65
static bool run(const Derived &x, const OtherDerived &y, const typename Derived::RealScalar &)
Definition: Fuzzy.h:34
bool isMuchSmallerThan(const RealScalar &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
static bool run(const Derived &x, const OtherDerived &y, const typename Derived::RealScalar &prec)
Definition: Fuzzy.h:43
static bool run(const Derived &x, const typename Derived::RealScalar &, const typename Derived::RealScalar &)
Definition: Fuzzy.h:70


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:37