Eigen::PolynomialSolverBase< Scalar_, Deg_ > Class Template Reference

Defined to be inherited by polynomial solvers: it provides convenient methods such as. More...

#include <PolynomialSolver.h>

+ Inheritance diagram for Eigen::PolynomialSolverBase< Scalar_, Deg_ >:

Public Types

typedef Scalar_ Scalar
 
typedef NumTraits< Scalar >::Real RealScalar
 
typedef std::complex< RealScalarRootType
 
typedef Matrix< RootType, Deg_, 1 > RootsType
 
typedef DenseIndex Index
 

Public Member Functions

template<typename OtherPolynomial >
 PolynomialSolverBase (const OtherPolynomial &poly)
 
 PolynomialSolverBase ()
 
const RootsTyperoots () const
 
template<typename Stl_back_insertion_sequence >
void realRoots (Stl_back_insertion_sequence &bi_seq, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const
 
const RootTypegreatestRoot () const
 
const RootTypesmallestRoot () const
 
const RealScalarabsGreatestRealRoot (bool &hasArealRoot, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const
 
const RealScalarabsSmallestRealRoot (bool &hasArealRoot, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const
 
const RealScalargreatestRealRoot (bool &hasArealRoot, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const
 
const RealScalarsmallestRealRoot (bool &hasArealRoot, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const
 

Protected Member Functions

template<typename OtherPolynomial >
void setPolynomial (const OtherPolynomial &poly)
 
template<typename squaredNormBinaryPredicate >
const RootTypeselectComplexRoot_withRespectToNorm (squaredNormBinaryPredicate &pred) const
 
template<typename squaredRealPartBinaryPredicate >
const RealScalarselectRealRoot_withRespectToAbsRealPart (squaredRealPartBinaryPredicate &pred, bool &hasArealRoot, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const
 
template<typename RealPartBinaryPredicate >
const RealScalarselectRealRoot_withRespectToRealPart (RealPartBinaryPredicate &pred, bool &hasArealRoot, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const
 

Protected Attributes

RootsType m_roots
 

Detailed Description

template<typename Scalar_, int Deg_>
class Eigen::PolynomialSolverBase< Scalar_, Deg_ >

Defined to be inherited by polynomial solvers: it provides convenient methods such as.

  • real roots,
  • greatest, smallest complex roots,
  • real roots with greatest, smallest absolute real value,
  • greatest, smallest real roots.

It stores the set of roots as a vector of complexes.

Member Typedef Documentation

◆ Index

template<typename Scalar_ , int Deg_>
typedef DenseIndex Eigen::PolynomialSolverBase< Scalar_, Deg_ >::Index

◆ RealScalar

template<typename Scalar_ , int Deg_>
typedef NumTraits<Scalar>::Real Eigen::PolynomialSolverBase< Scalar_, Deg_ >::RealScalar

◆ RootsType

template<typename Scalar_ , int Deg_>
typedef Matrix<RootType, Deg_, 1> Eigen::PolynomialSolverBase< Scalar_, Deg_ >::RootsType

◆ RootType

template<typename Scalar_ , int Deg_>
typedef std::complex<RealScalar> Eigen::PolynomialSolverBase< Scalar_, Deg_ >::RootType

◆ Scalar

template<typename Scalar_ , int Deg_>
typedef Scalar_ Eigen::PolynomialSolverBase< Scalar_, Deg_ >::Scalar

Constructor & Destructor Documentation

◆ PolynomialSolverBase() [1/2]

template<typename Scalar_ , int Deg_>
template<typename OtherPolynomial >
Eigen::PolynomialSolverBase< Scalar_, Deg_ >::PolynomialSolverBase ( const OtherPolynomial &  poly)
inline
51  {
52  setPolynomial(poly());
53  }
void setPolynomial(const OtherPolynomial &poly)
Definition: PolynomialSolver.h:45

References Eigen::PolynomialSolverBase< Scalar_, Deg_ >::setPolynomial().

◆ PolynomialSolverBase() [2/2]

template<typename Scalar_ , int Deg_>
Eigen::PolynomialSolverBase< Scalar_, Deg_ >::PolynomialSolverBase ( )
inline
55 {}

Member Function Documentation

◆ absGreatestRealRoot()

template<typename Scalar_ , int Deg_>
const RealScalar& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::absGreatestRealRoot ( bool hasArealRoot,
const RealScalar absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() 
) const
inline
Returns
a real root with greatest absolute magnitude. A real root is defined as the real part of a complex root with absolute imaginary part smallest than absImaginaryThreshold. absImaginaryThreshold takes the dummy_precision associated with the Scalar_ template parameter of the PolynomialSolver class as the default value. If no real root is found the boolean hasArealRoot is set to false and the real part of the root with smallest absolute imaginary part is returned instead.
Parameters
[out]hasArealRoot: boolean true if a real root is found according to the absImaginaryThreshold criterion, false otherwise.
[in]absImaginaryThreshold: threshold on the absolute imaginary part to decide whether or not a root is real.
195  {
196  std::greater<RealScalar> greater;
197  return selectRealRoot_withRespectToAbsRealPart(greater, hasArealRoot, absImaginaryThreshold);
198  }
const RealScalar & selectRealRoot_withRespectToAbsRealPart(squaredRealPartBinaryPredicate &pred, bool &hasArealRoot, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const
Definition: PolynomialSolver.h:118

References Eigen::PolynomialSolverBase< Scalar_, Deg_ >::selectRealRoot_withRespectToAbsRealPart().

◆ absSmallestRealRoot()

template<typename Scalar_ , int Deg_>
const RealScalar& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::absSmallestRealRoot ( bool hasArealRoot,
const RealScalar absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() 
) const
inline
Returns
a real root with smallest absolute magnitude. A real root is defined as the real part of a complex root with absolute imaginary part smallest than absImaginaryThreshold. absImaginaryThreshold takes the dummy_precision associated with the Scalar_ template parameter of the PolynomialSolver class as the default value. If no real root is found the boolean hasArealRoot is set to false and the real part of the root with smallest absolute imaginary part is returned instead.
Parameters
[out]hasArealRoot: boolean true if a real root is found according to the absImaginaryThreshold criterion, false otherwise.
[in]absImaginaryThreshold: threshold on the absolute imaginary part to decide whether or not a root is real.
215  {
216  std::less<RealScalar> less;
217  return selectRealRoot_withRespectToAbsRealPart(less, hasArealRoot, absImaginaryThreshold);
218  }

References Eigen::PolynomialSolverBase< Scalar_, Deg_ >::selectRealRoot_withRespectToAbsRealPart().

◆ greatestRealRoot()

template<typename Scalar_ , int Deg_>
const RealScalar& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::greatestRealRoot ( bool hasArealRoot,
const RealScalar absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() 
) const
inline
Returns
the real root with greatest value. A real root is defined as the real part of a complex root with absolute imaginary part smallest than absImaginaryThreshold. absImaginaryThreshold takes the dummy_precision associated with the Scalar_ template parameter of the PolynomialSolver class as the default value. If no real root is found the boolean hasArealRoot is set to false and the real part of the root with smallest absolute imaginary part is returned instead.
Parameters
[out]hasArealRoot: boolean true if a real root is found according to the absImaginaryThreshold criterion, false otherwise.
[in]absImaginaryThreshold: threshold on the absolute imaginary part to decide whether or not a root is real.
235  {
236  std::greater<RealScalar> greater;
237  return selectRealRoot_withRespectToRealPart(greater, hasArealRoot, absImaginaryThreshold);
238  }
const RealScalar & selectRealRoot_withRespectToRealPart(RealPartBinaryPredicate &pred, bool &hasArealRoot, const RealScalar &absImaginaryThreshold=NumTraits< Scalar >::dummy_precision()) const
Definition: PolynomialSolver.h:149

References Eigen::PolynomialSolverBase< Scalar_, Deg_ >::selectRealRoot_withRespectToRealPart().

◆ greatestRoot()

template<typename Scalar_ , int Deg_>
const RootType& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::greatestRoot ( ) const
inline
Returns
the complex root with greatest norm.
103  {
104  std::greater<RealScalar> greater;
105  return selectComplexRoot_withRespectToNorm(greater);
106  }
const RootType & selectComplexRoot_withRespectToNorm(squaredNormBinaryPredicate &pred) const
Definition: PolynomialSolver.h:86

References Eigen::PolynomialSolverBase< Scalar_, Deg_ >::selectComplexRoot_withRespectToNorm().

◆ realRoots()

template<typename Scalar_ , int Deg_>
template<typename Stl_back_insertion_sequence >
void Eigen::PolynomialSolverBase< Scalar_, Deg_ >::realRoots ( Stl_back_insertion_sequence &  bi_seq,
const RealScalar absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() 
) const
inline

Clear and fills the back insertion sequence with the real roots of the polynomial i.e. the real part of the complex roots that have an imaginary part which absolute value is smaller than absImaginaryThreshold. absImaginaryThreshold takes the dummy_precision associated with the Scalar_ template parameter of the PolynomialSolver class as the default value.

Parameters
[out]bi_seq: the back insertion sequence (stl concept)
[in]absImaginaryThreshold: the maximum bound of the imaginary part of a complex number that is considered as real.
74  {
75  using std::abs;
76  bi_seq.clear();
77  for (Index i = 0; i < m_roots.size(); ++i) {
78  if (abs(m_roots[i].imag()) < absImaginaryThreshold) {
79  bi_seq.push_back(m_roots[i].real());
80  }
81  }
82  }
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
int i
Definition: BiCGSTAB_step_by_step.cpp:9
RootsType m_roots
Definition: PolynomialSolver.h:261
DenseIndex Index
Definition: PolynomialSolver.h:41
const AutoDiffScalar< DerType > & real(const AutoDiffScalar< DerType > &x)
Definition: AutoDiffScalar.h:486
DerType::Scalar imag(const AutoDiffScalar< DerType > &)
Definition: AutoDiffScalar.h:490

References abs(), i, Eigen::imag(), Eigen::PolynomialSolverBase< Scalar_, Deg_ >::m_roots, and Eigen::real().

Referenced by evalSolverSugarFunction(), and main().

◆ roots()

template<typename Scalar_ , int Deg_>
const RootsType& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::roots ( ) const
inline
Returns
the complex roots of the polynomial
59 { return m_roots; }

References Eigen::PolynomialSolverBase< Scalar_, Deg_ >::m_roots.

Referenced by main().

◆ selectComplexRoot_withRespectToNorm()

template<typename Scalar_ , int Deg_>
template<typename squaredNormBinaryPredicate >
const RootType& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::selectComplexRoot_withRespectToNorm ( squaredNormBinaryPredicate &  pred) const
inlineprotected
86  {
87  Index res = 0;
88  RealScalar norm2 = numext::abs2(m_roots[0]);
89  for (Index i = 1; i < m_roots.size(); ++i) {
90  const RealScalar currNorm2 = numext::abs2(m_roots[i]);
91  if (pred(currNorm2, norm2)) {
92  res = i;
93  norm2 = currNorm2;
94  }
95  }
96  return m_roots[res];
97  }
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition: PartialRedux_count.cpp:3
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
EIGEN_DEVICE_FUNC bool abs2(bool x)
Definition: MathFunctions.h:1102

References Eigen::numext::abs2(), i, Eigen::PolynomialSolverBase< Scalar_, Deg_ >::m_roots, and res.

Referenced by Eigen::PolynomialSolverBase< Scalar_, Deg_ >::greatestRoot(), and Eigen::PolynomialSolverBase< Scalar_, Deg_ >::smallestRoot().

◆ selectRealRoot_withRespectToAbsRealPart()

template<typename Scalar_ , int Deg_>
template<typename squaredRealPartBinaryPredicate >
const RealScalar& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::selectRealRoot_withRespectToAbsRealPart ( squaredRealPartBinaryPredicate &  pred,
bool hasArealRoot,
const RealScalar absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() 
) const
inlineprotected
120  {
121  using std::abs;
122  hasArealRoot = false;
123  Index res = 0;
124  RealScalar abs2(0);
125 
126  for (Index i = 0; i < m_roots.size(); ++i) {
127  if (abs(m_roots[i].imag()) <= absImaginaryThreshold) {
128  if (!hasArealRoot) {
129  hasArealRoot = true;
130  res = i;
131  abs2 = m_roots[i].real() * m_roots[i].real();
132  } else {
133  const RealScalar currAbs2 = m_roots[i].real() * m_roots[i].real();
134  if (pred(currAbs2, abs2)) {
135  abs2 = currAbs2;
136  res = i;
137  }
138  }
139  } else if (!hasArealRoot) {
140  if (abs(m_roots[i].imag()) < abs(m_roots[res].imag())) {
141  res = i;
142  }
143  }
144  }
145  return numext::real_ref(m_roots[res]);
146  }
EIGEN_DEVICE_FUNC internal::add_const_on_value_type_t< EIGEN_MATHFUNC_RETVAL(real_ref, Scalar)> real_ref(const Scalar &x)
Definition: MathFunctions.h:1051

References abs(), Eigen::numext::abs2(), i, Eigen::imag(), Eigen::PolynomialSolverBase< Scalar_, Deg_ >::m_roots, Eigen::numext::real_ref(), and res.

Referenced by Eigen::PolynomialSolverBase< Scalar_, Deg_ >::absGreatestRealRoot(), and Eigen::PolynomialSolverBase< Scalar_, Deg_ >::absSmallestRealRoot().

◆ selectRealRoot_withRespectToRealPart()

template<typename Scalar_ , int Deg_>
template<typename RealPartBinaryPredicate >
const RealScalar& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::selectRealRoot_withRespectToRealPart ( RealPartBinaryPredicate &  pred,
bool hasArealRoot,
const RealScalar absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() 
) const
inlineprotected
151  {
152  using std::abs;
153  hasArealRoot = false;
154  Index res = 0;
155  RealScalar val(0);
156 
157  for (Index i = 0; i < m_roots.size(); ++i) {
158  if (abs(m_roots[i].imag()) <= absImaginaryThreshold) {
159  if (!hasArealRoot) {
160  hasArealRoot = true;
161  res = i;
162  val = m_roots[i].real();
163  } else {
164  const RealScalar curr = m_roots[i].real();
165  if (pred(curr, val)) {
166  val = curr;
167  res = i;
168  }
169  }
170  } else {
171  if (abs(m_roots[i].imag()) < abs(m_roots[res].imag())) {
172  res = i;
173  }
174  }
175  }
176  return numext::real_ref(m_roots[res]);
177  }
val
Definition: calibrate.py:119

References abs(), i, Eigen::imag(), Eigen::PolynomialSolverBase< Scalar_, Deg_ >::m_roots, Eigen::numext::real_ref(), res, and calibrate::val.

Referenced by Eigen::PolynomialSolverBase< Scalar_, Deg_ >::greatestRealRoot(), and Eigen::PolynomialSolverBase< Scalar_, Deg_ >::smallestRealRoot().

◆ setPolynomial()

template<typename Scalar_ , int Deg_>
template<typename OtherPolynomial >
void Eigen::PolynomialSolverBase< Scalar_, Deg_ >::setPolynomial ( const OtherPolynomial &  poly)
inlineprotected
45  {
46  m_roots.resize(poly.size() - 1);
47  }
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Definition: PlainObjectBase.h:294

References Eigen::PolynomialSolverBase< Scalar_, Deg_ >::m_roots, and Eigen::PlainObjectBase< Derived >::resize().

Referenced by Eigen::PolynomialSolverBase< Scalar_, Deg_ >::PolynomialSolverBase().

◆ smallestRealRoot()

template<typename Scalar_ , int Deg_>
const RealScalar& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::smallestRealRoot ( bool hasArealRoot,
const RealScalar absImaginaryThreshold = NumTraits<Scalar>::dummy_precision() 
) const
inline
Returns
the real root with smallest value. A real root is defined as the real part of a complex root with absolute imaginary part smallest than absImaginaryThreshold. absImaginaryThreshold takes the dummy_precision associated with the Scalar_ template parameter of the PolynomialSolver class as the default value. If no real root is found the boolean hasArealRoot is set to false and the real part of the root with smallest absolute imaginary part is returned instead.
Parameters
[out]hasArealRoot: boolean true if a real root is found according to the absImaginaryThreshold criterion, false otherwise.
[in]absImaginaryThreshold: threshold on the absolute imaginary part to decide whether or not a root is real.
255  {
256  std::less<RealScalar> less;
257  return selectRealRoot_withRespectToRealPart(less, hasArealRoot, absImaginaryThreshold);
258  }

References Eigen::PolynomialSolverBase< Scalar_, Deg_ >::selectRealRoot_withRespectToRealPart().

◆ smallestRoot()

template<typename Scalar_ , int Deg_>
const RootType& Eigen::PolynomialSolverBase< Scalar_, Deg_ >::smallestRoot ( ) const
inline
Returns
the complex root with smallest norm.
111  {
112  std::less<RealScalar> less;
114  }

References Eigen::PolynomialSolverBase< Scalar_, Deg_ >::selectComplexRoot_withRespectToNorm().

Member Data Documentation

◆ m_roots


The documentation for this class was generated from the following file: