Eigen::internal::companion< Scalar_, Deg_ > Class Template Reference

#include <Companion.h>

Public Types

enum  { Deg = Deg_ , Deg_1 = decrement_if_fixed_size<Deg>::ret }
 
typedef Scalar_ Scalar
 
typedef NumTraits< Scalar >::Real RealScalar
 
typedef Matrix< Scalar, Deg, 1 > RightColumn
 
typedef Matrix< Scalar, Deg_1, 1 > BottomLeftDiagonal
 
typedef Matrix< Scalar, Deg, DegDenseCompanionMatrixType
 
typedef Matrix< Scalar, Deg_, Deg_1LeftBlock
 
typedef Matrix< Scalar, Deg_1, Deg_1BottomLeftBlock
 
typedef Matrix< Scalar, 1, Deg_1LeftBlockFirstRow
 
typedef DenseIndex Index
 

Public Member Functions

EIGEN_STRONG_INLINE const Scalar_ operator() (Index row, Index col) const
 
template<typename VectorType >
void setPolynomial (const VectorType &poly)
 
template<typename VectorType >
 companion (const VectorType &poly)
 
DenseCompanionMatrixType denseMatrix () const
 
void balance ()
 

Protected Member Functions

bool balanced (RealScalar colNorm, RealScalar rowNorm, bool &isBalanced, RealScalar &colB, RealScalar &rowB)
 
bool balancedR (RealScalar colNorm, RealScalar rowNorm, bool &isBalanced, RealScalar &colB, RealScalar &rowB)
 

Protected Attributes

RightColumn m_monic
 
BottomLeftDiagonal m_bl_diag
 

Member Typedef Documentation

◆ BottomLeftBlock

template<typename Scalar_ , int Deg_>
typedef Matrix<Scalar, Deg_1, Deg_1> Eigen::internal::companion< Scalar_, Deg_ >::BottomLeftBlock

◆ BottomLeftDiagonal

template<typename Scalar_ , int Deg_>
typedef Matrix<Scalar, Deg_1, 1> Eigen::internal::companion< Scalar_, Deg_ >::BottomLeftDiagonal

◆ DenseCompanionMatrixType

template<typename Scalar_ , int Deg_>
typedef Matrix<Scalar, Deg, Deg> Eigen::internal::companion< Scalar_, Deg_ >::DenseCompanionMatrixType

◆ Index

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

◆ LeftBlock

template<typename Scalar_ , int Deg_>
typedef Matrix<Scalar, Deg_, Deg_1> Eigen::internal::companion< Scalar_, Deg_ >::LeftBlock

◆ LeftBlockFirstRow

template<typename Scalar_ , int Deg_>
typedef Matrix<Scalar, 1, Deg_1> Eigen::internal::companion< Scalar_, Deg_ >::LeftBlockFirstRow

◆ RealScalar

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

◆ RightColumn

template<typename Scalar_ , int Deg_>
typedef Matrix<Scalar, Deg, 1> Eigen::internal::companion< Scalar_, Deg_ >::RightColumn

◆ Scalar

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

Member Enumeration Documentation

◆ anonymous enum

template<typename Scalar_ , int Deg_>
anonymous enum
Enumerator
Deg 
Deg_1 
@ Deg_1
Definition: Companion.h:38
@ Deg
Definition: Companion.h:38
@ ret
Definition: Companion.h:28

Constructor & Destructor Documentation

◆ companion()

template<typename Scalar_ , int Deg_>
template<typename VectorType >
Eigen::internal::companion< Scalar_, Deg_ >::companion ( const VectorType poly)
inline
75  {
76  setPolynomial(poly);
77  }
void setPolynomial(const VectorType &poly)
Definition: Companion.h:68

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

Member Function Documentation

◆ balance()

template<typename Scalar_ , int Deg_>
void Eigen::internal::companion< Scalar_, Deg_ >::balance

Balancing algorithm from B. N. PARLETT and C. REINSCH (1969) "Balancing a matrix for calculation of eigenvalues and eigenvectors" adapted to the case of companion matrices. A matrix with non zero row and non zero column is balanced for a certain norm if the i-th row and the i-th column have same norm for all i.

193  {
194  using std::abs;
195  EIGEN_STATIC_ASSERT(Deg == Dynamic || 1 < Deg, YOU_MADE_A_PROGRAMMING_MISTAKE);
196  const Index deg = m_monic.size();
197  const Index deg_1 = deg - 1;
198 
199  bool hasConverged = false;
200  while (!hasConverged) {
201  hasConverged = true;
202  RealScalar colNorm, rowNorm;
203  RealScalar colB, rowB;
204 
205  // First row, first column excluding the diagonal
206  //==============================================
207  colNorm = abs(m_bl_diag[0]);
208  rowNorm = abs(m_monic[0]);
209 
210  // Compute balancing of the row and the column
211  if (!balanced(colNorm, rowNorm, hasConverged, colB, rowB)) {
212  m_bl_diag[0] *= colB;
213  m_monic[0] *= rowB;
214  }
215 
216  // Middle rows and columns excluding the diagonal
217  //==============================================
218  for (Index i = 1; i < deg_1; ++i) {
219  // column norm, excluding the diagonal
220  colNorm = abs(m_bl_diag[i]);
221 
222  // row norm, excluding the diagonal
223  rowNorm = abs(m_bl_diag[i - 1]) + abs(m_monic[i]);
224 
225  // Compute balancing of the row and the column
226  if (!balanced(colNorm, rowNorm, hasConverged, colB, rowB)) {
227  m_bl_diag[i] *= colB;
228  m_bl_diag[i - 1] *= rowB;
229  m_monic[i] *= rowB;
230  }
231  }
232 
233  // Last row, last column excluding the diagonal
234  //============================================
235  const Index ebl = m_bl_diag.size() - 1;
236  VectorBlock<RightColumn, Deg_1> headMonic(m_monic, 0, deg_1);
237  colNorm = headMonic.array().abs().sum();
238  rowNorm = abs(m_bl_diag[ebl]);
239 
240  // Compute balancing of the row and the column
241  if (!balanced(colNorm, rowNorm, hasConverged, colB, rowB)) {
242  headMonic *= colB;
243  m_bl_diag[ebl] *= rowB;
244  }
245  }
246 }
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_STATIC_ASSERT(X, MSG)
Definition: StaticAssert.h:26
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
DenseIndex Index
Definition: Companion.h:51
bool balanced(RealScalar colNorm, RealScalar rowNorm, bool &isBalanced, RealScalar &colB, RealScalar &rowB)
Definition: Companion.h:125
RightColumn m_monic
Definition: Companion.h:120
BottomLeftDiagonal m_bl_diag
Definition: Companion.h:121
const int Dynamic
Definition: Constants.h:25

References abs(), Eigen::Dynamic, EIGEN_STATIC_ASSERT, and i.

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

◆ balanced()

template<typename Scalar_ , int Deg_>
bool Eigen::internal::companion< Scalar_, Deg_ >::balanced ( RealScalar  colNorm,
RealScalar  rowNorm,
bool isBalanced,
RealScalar colB,
RealScalar rowB 
)
inlineprotected

Helper function for the balancing algorithm.

Returns
true if the row and the column, having colNorm and rowNorm as norms, are balanced, false otherwise. colB and rowB are respectively the multipliers for the column and the row in order to balance them.
126  {
127  if (RealScalar(0) == colNorm || RealScalar(0) == rowNorm || !(numext::isfinite)(colNorm) ||
128  !(numext::isfinite)(rowNorm)) {
129  return true;
130  } else {
131  // To find the balancing coefficients, if the radix is 2,
132  // one finds \f$ \sigma \f$ such that
133  // \f$ 2^{2\sigma-1} < rowNorm / colNorm \le 2^{2\sigma+1} \f$
134  // then the balancing coefficient for the row is \f$ 1/2^{\sigma} \f$
135  // and the balancing coefficient for the column is \f$ 2^{\sigma} \f$
136  const RealScalar radix = RealScalar(2);
137  const RealScalar radix2 = RealScalar(4);
138 
139  rowB = rowNorm / radix;
140  colB = RealScalar(1);
141  const RealScalar s = colNorm + rowNorm;
142 
143  // Find sigma s.t. rowNorm / 2 <= 2^(2*sigma) * colNorm
144  RealScalar scout = colNorm;
145  while (scout < rowB) {
146  colB *= radix;
147  scout *= radix2;
148  }
149 
150  // We now have an upper-bound for sigma, try to lower it.
151  // Find sigma s.t. 2^(2*sigma) * colNorm / 2 < rowNorm
152  scout = colNorm * (colB / radix) * colB; // Avoid overflow.
153  while (scout >= rowNorm) {
154  colB /= radix;
155  scout /= radix2;
156  }
157 
158  // This line is used to avoid insubstantial balancing.
159  if ((rowNorm + radix * scout) < RealScalar(0.95) * s * colB) {
160  isBalanced = false;
161  rowB = RealScalar(1) / colB;
162  return false;
163  } else {
164  return true;
165  }
166  }
167 }
NumTraits< Scalar >::Real RealScalar
Definition: Companion.h:41
RealScalar s
Definition: level1_cplx_impl.h:130
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool() isfinite(const Eigen::bfloat16 &h)
Definition: BFloat16.h:752

References Eigen::numext::isfinite(), and s.

◆ balancedR()

template<typename Scalar_ , int Deg_>
bool Eigen::internal::companion< Scalar_, Deg_ >::balancedR ( RealScalar  colNorm,
RealScalar  rowNorm,
bool isBalanced,
RealScalar colB,
RealScalar rowB 
)
inlineprotected

Helper function for the balancing algorithm.

Returns
true if the row and the column, having colNorm and rowNorm as norms, are balanced, false otherwise. colB and rowB are respectively the multipliers for the column and the row in order to balance them.

Set the norm of the column and the row to the geometric mean of the row and column norm

171  {
172  if (RealScalar(0) == colNorm || RealScalar(0) == rowNorm) {
173  return true;
174  } else {
179  const RealScalar q = colNorm / rowNorm;
180  if (!isApprox(q, Scalar_(1))) {
181  rowB = sqrt(colNorm / rowNorm);
182  colB = RealScalar(1) / rowB;
183 
184  isBalanced = false;
185  return false;
186  } else {
187  return true;
188  }
189  }
190 }
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
EIGEN_DEVICE_FUNC bool isApprox(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
Definition: MathFunctions.h:1923
EIGEN_DEVICE_FUNC const Scalar & q
Definition: SpecialFunctionsImpl.h:2019

References Eigen::internal::isApprox(), Eigen::numext::q, and sqrt().

◆ denseMatrix()

template<typename Scalar_ , int Deg_>
DenseCompanionMatrixType Eigen::internal::companion< Scalar_, Deg_ >::denseMatrix ( ) const
inline
80  {
81  const Index deg = m_monic.size();
82  const Index deg_1 = deg - 1;
83  DenseCompanionMatrixType companMat(deg, deg);
84  companMat << (LeftBlock(deg, deg_1) << LeftBlockFirstRow::Zero(1, deg_1),
85  BottomLeftBlock::Identity(deg - 1, deg - 1) * m_bl_diag.asDiagonal())
86  .finished(),
87  m_monic;
88  return companMat;
89  }
Matrix< Scalar, Deg_, Deg_1 > LeftBlock
Definition: Companion.h:47
Matrix< Scalar, Deg, Deg > DenseCompanionMatrixType
Definition: Companion.h:46
bool finished
Definition: MergeRestartFiles.py:79
double Zero
Definition: pseudosolid_node_update_elements.cc:35

References MergeRestartFiles::finished, Eigen::internal::companion< Scalar_, Deg_ >::m_bl_diag, Eigen::internal::companion< Scalar_, Deg_ >::m_monic, and oomph::PseudoSolidHelper::Zero.

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

◆ operator()()

template<typename Scalar_ , int Deg_>
EIGEN_STRONG_INLINE const Scalar_ Eigen::internal::companion< Scalar_, Deg_ >::operator() ( Index  row,
Index  col 
) const
inline
54  {
55  if (m_bl_diag.rows() > col) {
56  if (0 < row) {
57  return m_bl_diag[col];
58  } else {
59  return 0;
60  }
61  } else {
62  return m_monic[row];
63  }
64  }
m col(1)
m row(1)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:191

References col(), Eigen::internal::companion< Scalar_, Deg_ >::m_bl_diag, Eigen::internal::companion< Scalar_, Deg_ >::m_monic, row(), and Eigen::PlainObjectBase< Derived >::rows().

◆ setPolynomial()

template<typename Scalar_ , int Deg_>
template<typename VectorType >
void Eigen::internal::companion< Scalar_, Deg_ >::setPolynomial ( const VectorType poly)
inline
68  {
69  const Index deg = poly.size() - 1;
70  m_monic = -poly.head(deg) / poly[deg];
71  m_bl_diag.setOnes(deg - 1);
72  }
EIGEN_DEVICE_FUNC Derived & setOnes(Index size)
Definition: CwiseNullaryOp.h:708

References Eigen::internal::companion< Scalar_, Deg_ >::m_bl_diag, Eigen::internal::companion< Scalar_, Deg_ >::m_monic, and Eigen::PlainObjectBase< Derived >::setOnes().

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

Member Data Documentation

◆ m_bl_diag

◆ m_monic


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