10 #ifndef EIGEN_REAL_QZ_H
11 #define EIGEN_REAL_QZ_H
60 template <
typename MatrixType_>
216 template <
typename MatrixType>
218 const Index dim = m_S.cols();
223 m_T.template triangularView<StrictlyLower>().setZero();
226 m_S.applyOnTheLeft(m_Q.adjoint());
228 if (m_computeQZ) m_Z = MatrixType::Identity(dim, dim);
230 for (
Index j = 0;
j <= dim - 3;
j++) {
231 for (
Index i = dim - 1;
i >=
j + 2;
i--) {
235 G.makeGivens(m_S.coeff(
i - 1,
j), m_S.coeff(
i,
j), &m_S.coeffRef(
i - 1,
j));
237 m_S.rightCols(dim -
j - 1).applyOnTheLeft(
i - 1,
i,
G.adjoint());
238 m_T.rightCols(dim -
i + 1).applyOnTheLeft(
i - 1,
i,
G.adjoint());
240 if (m_computeQZ) m_Q.applyOnTheRight(
i - 1,
i,
G);
244 G.makeGivens(m_T.coeff(
i,
i), m_T.coeff(
i,
i - 1), &m_T.coeffRef(
i,
i));
245 m_T.coeffRef(
i,
i - 1) =
Scalar(0.0);
246 m_S.applyOnTheRight(
i,
i - 1,
G);
247 m_T.topRows(
i).applyOnTheRight(
i,
i - 1,
G);
249 if (m_computeQZ) m_Z.applyOnTheLeft(
i,
i - 1,
G.adjoint());
256 template <
typename MatrixType>
262 m_normOfS += m_S.col(
j).segment(0, (
std::min)(
size,
j + 2)).cwiseAbs().sum();
263 m_normOfT += m_T.row(
j).segment(
j,
size -
j).cwiseAbs().sum();
268 template <
typename MatrixType>
282 template <
typename MatrixType>
294 template <
typename MatrixType>
298 const Index dim = m_S.cols();
300 Index j = findSmallDiagEntry(
i,
i + 1);
303 Matrix2s STi = m_T.template block<2, 2>(
i,
i).template triangularView<Upper>().template solve<OnTheRight>(
304 m_S.template block<2, 2>(
i,
i));
306 Scalar q =
p *
p + STi(1, 0) * STi(0, 1);
314 G.makeGivens(
p + z, STi(1, 0));
316 G.makeGivens(
p - z, STi(1, 0));
317 m_S.rightCols(dim -
i).applyOnTheLeft(
i,
i + 1,
G.adjoint());
318 m_T.rightCols(dim -
i).applyOnTheLeft(
i,
i + 1,
G.adjoint());
320 if (m_computeQZ) m_Q.applyOnTheRight(
i,
i + 1,
G);
322 G.makeGivens(m_T.coeff(
i + 1,
i + 1), m_T.coeff(
i + 1,
i));
323 m_S.topRows(
i + 2).applyOnTheRight(
i + 1,
i,
G);
324 m_T.topRows(
i + 2).applyOnTheRight(
i + 1,
i,
G);
326 if (m_computeQZ) m_Z.applyOnTheLeft(
i + 1,
i,
G.adjoint());
328 m_S.coeffRef(
i + 1,
i) =
Scalar(0.0);
329 m_T.coeffRef(
i + 1,
i) =
Scalar(0.0);
332 pushDownZero(
j,
i,
i + 1);
337 template <
typename MatrixType>
340 const Index dim = m_S.cols();
341 for (
Index zz = z; zz < l; zz++) {
343 Index firstColS = zz >
f ? (zz - 1) : zz;
344 G.makeGivens(m_T.coeff(zz, zz + 1), m_T.coeff(zz + 1, zz + 1));
345 m_S.rightCols(dim - firstColS).applyOnTheLeft(zz, zz + 1,
G.adjoint());
346 m_T.rightCols(dim - zz).applyOnTheLeft(zz, zz + 1,
G.adjoint());
347 m_T.coeffRef(zz + 1, zz + 1) =
Scalar(0.0);
349 if (m_computeQZ) m_Q.applyOnTheRight(zz, zz + 1,
G);
352 G.makeGivens(m_S.coeff(zz + 1, zz), m_S.coeff(zz + 1, zz - 1));
353 m_S.topRows(zz + 2).applyOnTheRight(zz, zz - 1,
G);
354 m_T.topRows(zz + 1).applyOnTheRight(zz, zz - 1,
G);
355 m_S.coeffRef(zz + 1, zz - 1) =
Scalar(0.0);
357 if (m_computeQZ) m_Z.applyOnTheLeft(zz, zz - 1,
G.adjoint());
361 G.makeGivens(m_S.coeff(l, l), m_S.coeff(l, l - 1));
362 m_S.applyOnTheRight(l, l - 1,
G);
363 m_T.applyOnTheRight(l, l - 1,
G);
364 m_S.coeffRef(l, l - 1) =
Scalar(0.0);
366 if (m_computeQZ) m_Z.applyOnTheLeft(l, l - 1,
G.adjoint());
370 template <
typename MatrixType>
373 const Index dim = m_S.cols();
379 const Scalar a11 = m_S.coeff(
f + 0,
f + 0), a12 = m_S.coeff(
f + 0,
f + 1), a21 = m_S.coeff(
f + 1,
f + 0),
380 a22 = m_S.coeff(
f + 1,
f + 1), a32 = m_S.coeff(
f + 2,
f + 1), b12 = m_T.coeff(
f + 0,
f + 1),
381 b11i =
Scalar(1.0) / m_T.coeff(
f + 0,
f + 0), b22i =
Scalar(1.0) / m_T.coeff(
f + 1,
f + 1),
382 a87 = m_S.coeff(l - 1, l - 2), a98 = m_S.coeff(l - 0, l - 1),
383 b77i =
Scalar(1.0) / m_T.coeff(l - 2, l - 2), b88i =
Scalar(1.0) / m_T.coeff(l - 1, l - 1);
385 x = ll + a11 * a11 * b11i * b11i - lpl * a11 * b11i + a12 * a21 * b11i * b22i -
386 a11 * a21 * b12 * b11i * b11i * b22i;
387 y = a11 * a21 * b11i * b11i - lpl * a21 * b11i + a21 * a22 * b11i * b22i - a21 * a21 * b12 * b11i * b11i * b22i;
388 z = a21 * a32 * b11i * b22i;
389 }
else if (iter == 16) {
391 x = m_S.coeff(
f,
f) / m_T.coeff(
f,
f) - m_S.coeff(l, l) / m_T.coeff(l, l) +
392 m_S.coeff(l, l - 1) * m_T.coeff(l - 1, l) / (m_T.coeff(l - 1, l - 1) * m_T.coeff(l, l));
393 y = m_S.coeff(
f + 1,
f) / m_T.coeff(
f,
f);
395 }
else if (iter > 23 && !(iter % 8)) {
397 x = internal::random<Scalar>(-1.0, 1.0);
398 y = internal::random<Scalar>(-1.0, 1.0);
399 z = internal::random<Scalar>(-1.0, 1.0);
407 const Scalar a11 = m_S.coeff(
f,
f), a12 = m_S.coeff(
f,
f + 1), a21 = m_S.coeff(
f + 1,
f),
408 a22 = m_S.coeff(
f + 1,
f + 1), a32 = m_S.coeff(
f + 2,
f + 1),
410 a88 = m_S.coeff(l - 1, l - 1), a89 = m_S.coeff(l - 1, l), a98 = m_S.coeff(l, l - 1),
411 a99 = m_S.coeff(l, l),
413 b11 = m_T.coeff(
f,
f), b12 = m_T.coeff(
f,
f + 1), b22 = m_T.coeff(
f + 1,
f + 1),
415 b88 = m_T.coeff(l - 1, l - 1), b89 = m_T.coeff(l - 1, l), b99 = m_T.coeff(l, l);
417 x = ((a88 / b88 - a11 / b11) * (a99 / b99 - a11 / b11) - (a89 / b99) * (a98 / b88) +
418 (a98 / b88) * (b89 / b99) * (a11 / b11)) *
420 a12 / b22 - (a11 / b11) * (b12 / b22);
421 y = (a22 / b22 - a11 / b11) - (a21 / b11) * (b12 / b22) - (a88 / b88 - a11 / b11) - (a99 / b99 - a11 / b11) +
422 (a98 / b88) * (b89 / b99);
436 hr.makeHouseholderInPlace(tau,
beta);
437 essential2 = hr.template bottomRows<2>();
439 m_S.template middleRows<3>(
k).rightCols(dim - fc).applyHouseholderOnTheLeft(essential2, tau, m_workspace.
data());
440 m_T.template middleRows<3>(
k).rightCols(dim - fc).applyHouseholderOnTheLeft(essential2, tau, m_workspace.
data());
441 if (m_computeQZ) m_Q.template middleCols<3>(
k).applyHouseholderOnTheRight(essential2, tau, m_workspace.
data());
442 if (
k >
f) m_S.coeffRef(
k + 2,
k - 1) = m_S.coeffRef(
k + 1,
k - 1) =
Scalar(0.0);
445 hr << m_T.
coeff(
k + 2,
k + 2), m_T.coeff(
k + 2,
k), m_T.coeff(
k + 2,
k + 1);
446 hr.makeHouseholderInPlace(tau,
beta);
447 essential2 = hr.template bottomRows<2>();
452 tmp = m_S.template middleCols<2>(
k).topRows(lr) * essential2;
453 tmp += m_S.col(
k + 2).head(lr);
454 m_S.col(
k + 2).head(lr) -= tau *
tmp;
455 m_S.template middleCols<2>(
k).topRows(lr) -= (tau *
tmp) * essential2.adjoint();
457 tmp = m_T.template middleCols<2>(
k).topRows(lr) * essential2;
458 tmp += m_T.col(
k + 2).head(lr);
459 m_T.col(
k + 2).head(lr) -= tau *
tmp;
460 m_T.template middleCols<2>(
k).topRows(lr) -= (tau *
tmp) * essential2.adjoint();
465 tmp = essential2.adjoint() * (m_Z.template middleRows<2>(
k));
466 tmp += m_Z.row(
k + 2);
467 m_Z.row(
k + 2) -= tau *
tmp;
468 m_Z.template middleRows<2>(
k) -= essential2 * (tau *
tmp);
473 G.makeGivens(m_T.coeff(
k + 1,
k + 1), m_T.coeff(
k + 1,
k));
474 m_S.applyOnTheRight(
k + 1,
k,
G);
475 m_T.applyOnTheRight(
k + 1,
k,
G);
477 if (m_computeQZ) m_Z.applyOnTheLeft(
k + 1,
k,
G.adjoint());
478 m_T.coeffRef(
k + 1,
k) =
Scalar(0.0);
481 x = m_S.coeff(
k + 1,
k);
482 y = m_S.coeff(
k + 2,
k);
483 if (
k < l - 2) z = m_S.coeff(
k + 3,
k);
488 m_S.applyOnTheLeft(l - 1, l,
G.adjoint());
489 m_T.applyOnTheLeft(l - 1, l,
G.adjoint());
490 if (m_computeQZ) m_Q.applyOnTheRight(l - 1, l,
G);
491 m_S.coeffRef(l, l - 2) =
Scalar(0.0);
494 G.makeGivens(m_T.coeff(l, l), m_T.coeff(l, l - 1));
495 m_S.applyOnTheRight(l, l - 1,
G);
496 m_T.applyOnTheRight(l, l - 1,
G);
497 if (m_computeQZ) m_Z.applyOnTheLeft(l, l - 1,
G.adjoint());
498 m_T.coeffRef(l, l - 1) =
Scalar(0.0);
501 template <
typename MatrixType>
503 const Index dim = A_in.cols();
505 eigen_assert(A_in.rows() == dim && A_in.cols() == dim && B_in.rows() == dim && B_in.cols() == dim &&
506 "Need square matrices of the same dimension");
508 m_isInitialized =
true;
509 m_computeQZ = computeQZ;
512 m_workspace.resize(dim * 2);
516 hessenbergTriangular();
520 Index l = dim - 1,
f, local_iter = 0;
522 while (l > 0 && local_iter < m_maxIters) {
523 f = findSmallSubdiagEntry(l);
525 if (
f > 0) m_S.coeffRef(
f,
f - 1) =
Scalar(0.0);
530 }
else if (
f == l - 1)
538 Index z = findSmallDiagEntry(
f, l);
541 pushDownZero(z,
f, l);
546 step(
f, l, local_iter);
560 for (
Index i = 0;
i < dim - 1; ++
i) {
566 m_S.applyOnTheLeft(
i,
i + 1, j_left);
567 m_S.applyOnTheRight(
i,
i + 1, j_right);
568 m_T.applyOnTheLeft(
i,
i + 1, j_left);
569 m_T.applyOnTheRight(
i,
i + 1, j_right);
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
int i
Definition: BiCGSTAB_step_by_step.cpp:9
JacobiRotation< float > G
Definition: Jacobi_makeGivens.cpp:2
#define eigen_assert(x)
Definition: Macros.h:910
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition: PartialRedux_count.cpp:3
float * p
Definition: Tutorial_Map_using.cpp:9
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
boost::multiprecision::number< boost::multiprecision::cpp_dec_float< 100 >, boost::multiprecision::et_on > Real
Definition: boostmultiprec.cpp:77
HouseholderSequenceType householderQ() const
Definition: HouseholderQR.h:160
const MatrixType & matrixQR() const
Definition: HouseholderQR.h:168
Rotation given by a cosine-sine pair.
Definition: Jacobi.h:38
EIGEN_DEVICE_FUNC JacobiRotation transpose() const
Definition: Jacobi.h:61
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
Definition: PlainObjectBase.h:217
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const Scalar & coeff(Index rowId, Index colId) const
Definition: PlainObjectBase.h:198
constexpr EIGEN_DEVICE_FUNC const Scalar * data() const
Definition: PlainObjectBase.h:273
Performs a real QZ decomposition of a pair of square matrices.
Definition: RealQZ.h:61
Matrix< Scalar, 2, 1 > Vector2s
Definition: RealQZ.h:201
Matrix< Scalar, Dynamic, 1 > m_workspace
Definition: RealQZ.h:192
@ ColsAtCompileTime
Definition: RealQZ.h:66
@ Options
Definition: RealQZ.h:67
@ MaxRowsAtCompileTime
Definition: RealQZ.h:68
@ RowsAtCompileTime
Definition: RealQZ.h:65
@ MaxColsAtCompileTime
Definition: RealQZ.h:69
void computeNorms()
Definition: RealQZ.h:257
RealQZ & compute(const MatrixType &A, const MatrixType &B, bool computeQZ=true)
Computes QZ decomposition of given matrix.
Definition: RealQZ.h:502
Index iterations() const
Returns number of performed QR-like iterations.
Definition: RealQZ.h:177
Index m_global_iter
Definition: RealQZ.h:198
Matrix< Scalar, 2, 2 > Matrix2s
Definition: RealQZ.h:202
MatrixType_ MatrixType
Definition: RealQZ.h:63
Index findSmallSubdiagEntry(Index iu)
Definition: RealQZ.h:269
const MatrixType & matrixQ() const
Returns matrix Q in the QZ decomposition.
Definition: RealQZ.h:123
MatrixType m_Q
Definition: RealQZ.h:191
bool m_computeQZ
Definition: RealQZ.h:196
RealQZ & setMaxIterations(Index maxIters)
Definition: RealQZ.h:185
RealQZ(const MatrixType &A, const MatrixType &B, bool computeQZ=true)
Constructor; computes real QZ decomposition of given matrices.
Definition: RealQZ.h:107
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: RealQZ.h:170
void splitOffTwoRows(Index i)
Definition: RealQZ.h:295
Scalar m_normOfS
Definition: RealQZ.h:197
const MatrixType & matrixZ() const
Returns matrix Z in the QZ decomposition.
Definition: RealQZ.h:133
const MatrixType & matrixT() const
Returns matrix S in the QZ decomposition.
Definition: RealQZ.h:152
MatrixType::Scalar Scalar
Definition: RealQZ.h:71
void step(Index f, Index l, Index iter)
Definition: RealQZ.h:371
Matrix< Scalar, ColsAtCompileTime, 1, Options &~RowMajor, MaxColsAtCompileTime, 1 > ColumnVectorType
Definition: RealQZ.h:76
RealQZ(Index size=RowsAtCompileTime==Dynamic ? 1 :RowsAtCompileTime)
Default constructor.
Definition: RealQZ.h:89
void hessenbergTriangular()
Definition: RealQZ.h:217
MatrixType m_S
Definition: RealQZ.h:191
Matrix< ComplexScalar, ColsAtCompileTime, 1, Options &~RowMajor, MaxColsAtCompileTime, 1 > EigenvalueType
Definition: RealQZ.h:75
const MatrixType & matrixS() const
Returns matrix S in the QZ decomposition.
Definition: RealQZ.h:143
JacobiRotation< Scalar > JRs
Definition: RealQZ.h:203
Eigen::Index Index
Definition: RealQZ.h:73
Matrix< Scalar, 3, 1 > Vector3s
Definition: RealQZ.h:200
ComputationInfo m_info
Definition: RealQZ.h:193
std::complex< typename NumTraits< Scalar >::Real > ComplexScalar
Definition: RealQZ.h:72
MatrixType m_Z
Definition: RealQZ.h:191
MatrixType m_T
Definition: RealQZ.h:191
bool m_isInitialized
Definition: RealQZ.h:195
Index m_maxIters
Definition: RealQZ.h:194
Index findSmallDiagEntry(Index f, Index l)
Definition: RealQZ.h:283
void pushDownZero(Index z, Index f, Index l)
Definition: RealQZ.h:338
Scalar m_normOfT
Definition: RealQZ.h:197
Definition: matrices.h:74
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
Definition: cxx11_tensor_map.cpp:237
#define min(a, b)
Definition: datatypes.h:22
#define max(a, b)
Definition: datatypes.h:23
EIGEN_DONT_INLINE void compute(Solver &solver, const MatrixType &A)
Definition: dense_solvers.cpp:23
ComputationInfo
Definition: Constants.h:438
@ Success
Definition: Constants.h:440
@ NoConvergence
Definition: Constants.h:444
Scalar * y
Definition: level1_cplx_impl.h:128
RealScalar s
Definition: level1_cplx_impl.h:130
Scalar beta
Definition: level2_cplx_impl.h:36
char char char int int * k
Definition: level2_impl.h:374
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365
void real_2x2_jacobi_svd(const MatrixType &matrix, Index p, Index q, JacobiRotation< RealScalar > *j_left, JacobiRotation< RealScalar > *j_right)
Definition: RealSvd2x2.h:22
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool is_exactly_zero(const X &x)
Definition: Meta.h:592
EIGEN_DEVICE_FUNC const Scalar & q
Definition: SpecialFunctionsImpl.h:2019
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
const int Dynamic
Definition: Constants.h:25
list x
Definition: plotDoE.py:28
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217
Definition: ForwardDeclarations.h:21
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2