10 #ifndef EIGEN_COMPANION_H
11 #define EIGEN_COMPANION_H
23 #ifndef EIGEN_PARSED_BY_DOXYGEN
26 struct decrement_if_fixed_size
34 template<
typename Scalar_,
int Deg_ >
42 Deg_1=decrement_if_fixed_size<Deg>::ret
45 typedef Scalar_ Scalar;
47 typedef Matrix<Scalar, Deg, 1> RightColumn;
49 typedef Matrix<Scalar, Deg_1, 1> BottomLeftDiagonal;
51 typedef Matrix<Scalar, Deg, Deg> DenseCompanionMatrixType;
52 typedef Matrix< Scalar, Deg_, Deg_1 > LeftBlock;
53 typedef Matrix< Scalar, Deg_1, Deg_1 > BottomLeftBlock;
54 typedef Matrix< Scalar, 1, Deg_1 > LeftBlockFirstRow;
61 if( m_bl_diag.rows() > col )
63 if( 0 < row ){
return m_bl_diag[
col]; }
66 else{
return m_monic[
row]; }
70 template<
typename VectorType>
71 void setPolynomial(
const VectorType& poly )
73 const Index deg = poly.size()-1;
74 m_monic = -poly.head(deg)/poly[deg];
75 m_bl_diag.setOnes(deg-1);
78 template<
typename VectorType>
79 companion(
const VectorType& poly ){
80 setPolynomial( poly ); }
83 DenseCompanionMatrixType denseMatrix()
const
85 const Index deg = m_monic.size();
86 const Index deg_1 = deg-1;
87 DenseCompanionMatrixType companMat(deg,deg);
89 ( LeftBlock(deg,deg_1)
105 bool balanced( RealScalar colNorm, RealScalar rowNorm,
106 bool& isBalanced, RealScalar& colB, RealScalar& rowB );
114 bool balancedR( RealScalar colNorm, RealScalar rowNorm,
115 bool& isBalanced, RealScalar& colB, RealScalar& rowB );
130 BottomLeftDiagonal m_bl_diag;
135 template<
typename Scalar_,
int Deg_ >
137 bool companion<Scalar_,Deg_>::balanced( RealScalar colNorm, RealScalar rowNorm,
138 bool& isBalanced, RealScalar& colB, RealScalar& rowB )
140 if( RealScalar(0) == colNorm || RealScalar(0) == rowNorm
151 const RealScalar radix = RealScalar(2);
152 const RealScalar radix2 = RealScalar(4);
154 rowB = rowNorm / radix;
155 colB = RealScalar(1);
156 const RealScalar s = colNorm + rowNorm;
159 RealScalar scout = colNorm;
168 scout = colNorm * (colB / radix) * colB;
169 while (scout >= rowNorm)
176 if ((rowNorm + radix * scout) < RealScalar(0.95) * s * colB)
179 rowB = RealScalar(1) / colB;
189 template<
typename Scalar_,
int Deg_ >
191 bool companion<Scalar_,Deg_>::balancedR( RealScalar colNorm, RealScalar rowNorm,
192 bool& isBalanced, RealScalar& colB, RealScalar& rowB )
194 if( RealScalar(0) == colNorm || RealScalar(0) == rowNorm ){
return true; }
201 const RealScalar
q = colNorm/rowNorm;
204 rowB =
sqrt( colNorm/rowNorm );
205 colB = RealScalar(1)/rowB;
216 template<
typename Scalar_,
int Deg_ >
217 void companion<Scalar_,Deg_>::balance()
221 const Index deg = m_monic.size();
222 const Index deg_1 = deg-1;
224 bool hasConverged=
false;
225 while( !hasConverged )
228 RealScalar colNorm,rowNorm;
229 RealScalar colB,rowB;
233 colNorm =
abs(m_bl_diag[0]);
234 rowNorm =
abs(m_monic[0]);
237 if( !balanced( colNorm, rowNorm, hasConverged, colB, rowB ) )
239 m_bl_diag[0] *= colB;
248 colNorm =
abs(m_bl_diag[i]);
251 rowNorm =
abs(m_bl_diag[i-1]) +
abs(m_monic[i]);
254 if( !balanced( colNorm, rowNorm, hasConverged, colB, rowB ) )
256 m_bl_diag[
i] *= colB;
257 m_bl_diag[
i-1] *= rowB;
264 const Index ebl = m_bl_diag.size()-1;
265 VectorBlock<RightColumn,Deg_1> headMonic( m_monic, 0, deg_1 );
266 colNorm = headMonic.array().abs().sum();
267 rowNorm =
abs( m_bl_diag[ebl] );
270 if( !balanced( colNorm, rowNorm, hasConverged, colB, rowB ) )
273 m_bl_diag[ebl] *= rowB;
RowXpr row(Index i) const
ColXpr col(Index i) const
IndexedView_or_VectorBlock operator()(const Indices &indices)
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar, Size)
#define EIGEN_STATIC_ASSERT(X, MSG)
static const ConstantReturnType Zero()
static const IdentityReturnType Identity()
bool isApprox(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
EIGEN_ALWAYS_INLINE bool() isfinite(const Eigen::bfloat16 &h)
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)
adouble abs(const adouble &x)