Eigen  5.0.1
 
Loading...
Searching...
No Matches
RealQZ.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2012 Alexey Korepanov <kaikaikai@yandex.ru>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9// SPDX-License-Identifier: MPL-2.0
10
11#ifndef EIGEN_REAL_QZ_H
12#define EIGEN_REAL_QZ_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18
60
61template <typename MatrixType_>
62class RealQZ {
63 public:
64 using MatrixType = MatrixType_;
65 enum {
66 RowsAtCompileTime = MatrixType::RowsAtCompileTime,
67 ColsAtCompileTime = MatrixType::ColsAtCompileTime,
68 Options = internal::plain_object_options<MatrixType>::value,
69 MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
70 MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
71 };
72 using Scalar = typename MatrixType::Scalar;
73 using ComplexScalar = internal::make_complex_t<Scalar>;
74 using Index = Eigen::Index;
75
78
83
95 explicit RealQZ(Index size = RowsAtCompileTime == Dynamic ? 1 : RowsAtCompileTime)
96 : m_S(size, size),
97 m_T(size, size),
98 m_Q(size, size),
99 m_Z(size, size),
100 m_workspace(size * 2),
101 m_hCoeffs(size),
102 m_maxIters(400),
103 m_isInitialized(false),
104 m_computeQZ(true) {}
105
114 template <typename InputTypeA, typename InputTypeB>
115 RealQZ(const EigenBase<InputTypeA>& A, const EigenBase<InputTypeB>& B, bool computeQZ = true)
116 : m_S(A.derived()),
117 m_T(B.derived()),
118 m_Q(A.rows(), A.cols()),
119 m_Z(A.rows(), A.cols()),
120 m_workspace(A.rows() * 2),
121 m_hCoeffs(A.rows()),
122 m_maxIters(400),
123 m_isInitialized(false),
124 m_computeQZ(true) {
125 computeInPlace(computeQZ);
126 }
127
138 template <typename InputTypeA, typename InputTypeB>
140 : m_S(A.derived()),
141 m_T(B.derived()),
142 m_Q(A.rows(), A.cols()),
143 m_Z(A.rows(), A.cols()),
144 m_workspace(A.rows() * 2),
145 m_hCoeffs(A.rows()),
146 m_maxIters(400),
147 m_isInitialized(false),
148 m_computeQZ(true) {
149 computeInPlace(computeQZ);
150 }
151
156 const PlainMatrixType& matrixQ() const {
157 eigen_assert(m_isInitialized && "RealQZ is not initialized.");
158 eigen_assert(m_computeQZ && "The matrices Q and Z have not been computed during the QZ decomposition.");
159 return m_Q;
160 }
161
166 const PlainMatrixType& matrixZ() const {
167 eigen_assert(m_isInitialized && "RealQZ is not initialized.");
168 eigen_assert(m_computeQZ && "The matrices Q and Z have not been computed during the QZ decomposition.");
169 return m_Z;
170 }
171
176 const MatrixType& matrixS() const {
177 eigen_assert(m_isInitialized && "RealQZ is not initialized.");
178 return m_S;
179 }
180
185 const MatrixType& matrixT() const {
186 eigen_assert(m_isInitialized && "RealQZ is not initialized.");
187 return m_T;
188 }
189
197 template <typename InputTypeA, typename InputTypeB>
198 RealQZ& compute(const EigenBase<InputTypeA>& A, const EigenBase<InputTypeB>& B, bool computeQZ = true);
199
205 eigen_assert(m_isInitialized && "RealQZ is not initialized.");
206 return m_info;
207 }
208
212 eigen_assert(m_isInitialized && "RealQZ is not initialized.");
213 return m_global_iter;
214 }
215
220 m_maxIters = maxIters;
221 return *this;
222 }
223
224 private:
225 MatrixType m_S, m_T;
226 PlainMatrixType m_Q, m_Z;
227 Matrix<Scalar, Dynamic, 1> m_workspace;
228 ColumnVectorType m_hCoeffs;
229 ComputationInfo m_info;
230 Index m_maxIters;
231 bool m_isInitialized;
232 bool m_computeQZ;
233 Scalar m_normOfT, m_normOfS;
234 Index m_global_iter;
235
236 using Vector3s = Matrix<Scalar, 3, 1>;
237 using Vector2s = Matrix<Scalar, 2, 1>;
238 using Matrix2s = Matrix<Scalar, 2, 2>;
239 using JRs = JacobiRotation<Scalar>;
240
241 RealQZ& computeInPlace(bool computeQZ);
242 void hessenbergTriangular();
243 void computeNorms();
244 Index findSmallSubdiagEntry(Index iu);
245 Index findSmallDiagEntry(Index f, Index l);
246 void splitOffTwoRows(Index i);
247 void pushDownZero(Index z, Index f, Index l);
248 void step(Index f, Index l, Index iter);
249
250}; // RealQZ
251
253template <typename MatrixType>
254void RealQZ<MatrixType>::hessenbergTriangular() {
255 const Index dim = m_S.cols();
256
257 // perform QR decomposition of T in place: T holds R above the Householder vectors Q is formed from
258 m_hCoeffs.resize(dim);
259 internal::householder_qr_inplace_blocked<MatrixType, ColumnVectorType>::run(m_T, m_hCoeffs, 48, m_workspace.data());
260 Map<ColumnVectorType> workspace(m_workspace.data(), dim);
261 householderSequence(m_T, m_hCoeffs.conjugate()).evalTo(m_Q, workspace);
262 m_T.template triangularView<StrictlyLower>().setZero();
263 // Z is unused until it is initialized below, so it can hold Q* S without aliasing S.
264 m_Z.noalias() = m_Q.adjoint() * m_S;
265 m_S.swap(m_Z);
266 // init Z as Identity
267 if (m_computeQZ) m_Z = PlainMatrixType::Identity(dim, dim);
268 // reduce S to upper Hessenberg with Givens rotations
269 for (Index j = 0; j <= dim - 3; j++) {
270 for (Index i = dim - 1; i >= j + 2; i--) {
271 JRs G;
272 // kill S(i,j)
273 if (!numext::is_exactly_zero(m_S.coeff(i, j))) {
274 G.makeGivens(m_S.coeff(i - 1, j), m_S.coeff(i, j), &m_S.coeffRef(i - 1, j));
275 m_S.coeffRef(i, j) = Scalar(0.0);
276 m_S.rightCols(dim - j - 1).applyOnTheLeft(i - 1, i, G.adjoint());
277 m_T.rightCols(dim - i + 1).applyOnTheLeft(i - 1, i, G.adjoint());
278 // update Q
279 if (m_computeQZ) m_Q.applyOnTheRight(i - 1, i, G);
280 }
281 // kill T(i,i-1)
282 if (!numext::is_exactly_zero(m_T.coeff(i, i - 1))) {
283 G.makeGivens(m_T.coeff(i, i), m_T.coeff(i, i - 1), &m_T.coeffRef(i, i));
284 m_T.coeffRef(i, i - 1) = Scalar(0.0);
285 m_S.applyOnTheRight(i, i - 1, G);
286 m_T.topRows(i).applyOnTheRight(i, i - 1, G);
287 // update Z
288 if (m_computeQZ) m_Z.applyOnTheLeft(i, i - 1, G.adjoint());
289 }
290 }
291 }
292}
293
295template <typename MatrixType>
296inline void RealQZ<MatrixType>::computeNorms() {
297 m_normOfS = internal::hessenberg_abs_sum<Upper>(m_S);
298 m_normOfT = internal::triangular_abs_sum<Upper>(m_T);
299}
300
302template <typename MatrixType>
303inline Index RealQZ<MatrixType>::findSmallSubdiagEntry(Index iu) {
304 using std::abs;
305 Index res = iu;
306 while (res > 0) {
307 Scalar s = abs(m_S.coeff(res - 1, res - 1)) + abs(m_S.coeff(res, res));
308 if (numext::is_exactly_zero(s)) s = m_normOfS;
309 if (abs(m_S.coeff(res, res - 1)) < NumTraits<Scalar>::epsilon() * s) break;
310 res--;
311 }
312 return res;
313}
314
316template <typename MatrixType>
317inline Index RealQZ<MatrixType>::findSmallDiagEntry(Index f, Index l) {
318 using std::abs;
319 Index res = l;
320 while (res >= f) {
321 if (abs(m_T.coeff(res, res)) <= NumTraits<Scalar>::epsilon() * m_normOfT) break;
322 res--;
323 }
324 return res;
325}
326
328template <typename MatrixType>
329inline void RealQZ<MatrixType>::splitOffTwoRows(Index i) {
330 using std::abs;
331 using std::sqrt;
332 const Index dim = m_S.cols();
333 if (numext::is_exactly_zero(abs(m_S.coeff(i + 1, i)))) return;
334 Index j = findSmallDiagEntry(i, i + 1);
335 if (j == i - 1) {
336 // block of (S T^{-1})
337 Matrix2s STi = m_T.template block<2, 2>(i, i).template triangularView<Upper>().template solve<OnTheRight>(
338 m_S.template block<2, 2>(i, i));
339 Scalar p = Scalar(0.5) * (STi(0, 0) - STi(1, 1));
340 Scalar q = p * p + STi(1, 0) * STi(0, 1);
341 if (q >= 0) {
342 Scalar z = sqrt(q);
343 // one QR-like iteration for ABi - lambda I
344 // is enough - when we know exact eigenvalue in advance,
345 // convergence is immediate
346 JRs G;
347 if (p >= 0)
348 G.makeGivens(p + z, STi(1, 0));
349 else
350 G.makeGivens(p - z, STi(1, 0));
351 m_S.rightCols(dim - i).applyOnTheLeft(i, i + 1, G.adjoint());
352 m_T.rightCols(dim - i).applyOnTheLeft(i, i + 1, G.adjoint());
353 // update Q
354 if (m_computeQZ) m_Q.applyOnTheRight(i, i + 1, G);
355
356 G.makeGivens(m_T.coeff(i + 1, i + 1), m_T.coeff(i + 1, i));
357 m_S.topRows(i + 2).applyOnTheRight(i + 1, i, G);
358 m_T.topRows(i + 2).applyOnTheRight(i + 1, i, G);
359 // update Z
360 if (m_computeQZ) m_Z.applyOnTheLeft(i + 1, i, G.adjoint());
361
362 m_S.coeffRef(i + 1, i) = Scalar(0.0);
363 m_T.coeffRef(i + 1, i) = Scalar(0.0);
364 }
365 } else {
366 pushDownZero(j, i, i + 1);
367 }
368}
369
371template <typename MatrixType>
372inline void RealQZ<MatrixType>::pushDownZero(Index z, Index f, Index l) {
373 JRs G;
374 const Index dim = m_S.cols();
375 for (Index zz = z; zz < l; zz++) {
376 // push 0 down
377 Index firstColS = zz > f ? (zz - 1) : zz;
378 G.makeGivens(m_T.coeff(zz, zz + 1), m_T.coeff(zz + 1, zz + 1));
379 m_S.rightCols(dim - firstColS).applyOnTheLeft(zz, zz + 1, G.adjoint());
380 m_T.rightCols(dim - zz).applyOnTheLeft(zz, zz + 1, G.adjoint());
381 m_T.coeffRef(zz + 1, zz + 1) = Scalar(0.0);
382 // update Q
383 if (m_computeQZ) m_Q.applyOnTheRight(zz, zz + 1, G);
384 // kill S(zz+1, zz-1)
385 if (zz > f) {
386 G.makeGivens(m_S.coeff(zz + 1, zz), m_S.coeff(zz + 1, zz - 1));
387 m_S.topRows(zz + 2).applyOnTheRight(zz, zz - 1, G);
388 m_T.topRows(zz + 1).applyOnTheRight(zz, zz - 1, G);
389 m_S.coeffRef(zz + 1, zz - 1) = Scalar(0.0);
390 // update Z
391 if (m_computeQZ) m_Z.applyOnTheLeft(zz, zz - 1, G.adjoint());
392 }
393 }
394 // finally kill S(l,l-1)
395 G.makeGivens(m_S.coeff(l, l), m_S.coeff(l, l - 1));
396 m_S.applyOnTheRight(l, l - 1, G);
397 m_T.applyOnTheRight(l, l - 1, G);
398 m_S.coeffRef(l, l - 1) = Scalar(0.0);
399 // update Z
400 if (m_computeQZ) m_Z.applyOnTheLeft(l, l - 1, G.adjoint());
401}
402
404template <typename MatrixType>
405inline void RealQZ<MatrixType>::step(Index f, Index l, Index iter) {
406 using std::abs;
407 const Index dim = m_S.cols();
408
409 // x, y, z
410 Scalar x, y, z;
411 if (iter == 10) {
412 // Wilkinson ad hoc shift
413 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),
414 a22 = m_S.coeff(f + 1, f + 1), a32 = m_S.coeff(f + 2, f + 1), b12 = m_T.coeff(f + 0, f + 1),
415 b11i = Scalar(1.0) / m_T.coeff(f + 0, f + 0), b22i = Scalar(1.0) / m_T.coeff(f + 1, f + 1),
416 a87 = m_S.coeff(l - 1, l - 2), a98 = m_S.coeff(l - 0, l - 1),
417 b77i = Scalar(1.0) / m_T.coeff(l - 2, l - 2), b88i = Scalar(1.0) / m_T.coeff(l - 1, l - 1);
418 Scalar ss = abs(a87 * b77i) + abs(a98 * b88i), lpl = Scalar(1.5) * ss, ll = ss * ss;
419 x = ll + a11 * a11 * b11i * b11i - lpl * a11 * b11i + a12 * a21 * b11i * b22i -
420 a11 * a21 * b12 * b11i * b11i * b22i;
421 y = a11 * a21 * b11i * b11i - lpl * a21 * b11i + a21 * a22 * b11i * b22i - a21 * a21 * b12 * b11i * b11i * b22i;
422 z = a21 * a32 * b11i * b22i;
423 } else if (iter == 16) {
424 // another exceptional shift
425 x = m_S.coeff(f, f) / m_T.coeff(f, f) - m_S.coeff(l, l) / m_T.coeff(l, l) +
426 m_S.coeff(l, l - 1) * m_T.coeff(l - 1, l) / (m_T.coeff(l - 1, l - 1) * m_T.coeff(l, l));
427 y = m_S.coeff(f + 1, f) / m_T.coeff(f, f);
428 z = 0;
429 } else if (iter > 23 && !(iter % 8)) {
430 // extremely exceptional shift
431 x = internal::random<Scalar>(-1.0, 1.0);
432 y = internal::random<Scalar>(-1.0, 1.0);
433 z = internal::random<Scalar>(-1.0, 1.0);
434 } else {
435 // Compute the shifts: (x,y,z,0...) = (AB^-1 - l1 I) (AB^-1 - l2 I) e1
436 // where l1 and l2 are the eigenvalues of the 2x2 matrix C = U V^-1 where
437 // U and V are 2x2 bottom right sub matrices of A and B. Thus:
438 // = AB^-1AB^-1 + l1 l2 I - (l1+l2)(AB^-1)
439 // = AB^-1AB^-1 + det(M) - tr(M)(AB^-1)
440 // Since we are only interested in having x, y, z with a correct ratio, we have:
441 const Scalar a11 = m_S.coeff(f, f), a12 = m_S.coeff(f, f + 1), a21 = m_S.coeff(f + 1, f),
442 a22 = m_S.coeff(f + 1, f + 1), a32 = m_S.coeff(f + 2, f + 1),
443
444 a88 = m_S.coeff(l - 1, l - 1), a89 = m_S.coeff(l - 1, l), a98 = m_S.coeff(l, l - 1),
445 a99 = m_S.coeff(l, l),
446
447 b11 = m_T.coeff(f, f), b12 = m_T.coeff(f, f + 1), b22 = m_T.coeff(f + 1, f + 1),
448
449 b88 = m_T.coeff(l - 1, l - 1), b89 = m_T.coeff(l - 1, l), b99 = m_T.coeff(l, l);
450
451 x = ((a88 / b88 - a11 / b11) * (a99 / b99 - a11 / b11) - (a89 / b99) * (a98 / b88) +
452 (a98 / b88) * (b89 / b99) * (a11 / b11)) *
453 (b11 / a21) +
454 a12 / b22 - (a11 / b11) * (b12 / b22);
455 y = (a22 / b22 - a11 / b11) - (a21 / b11) * (b12 / b22) - (a88 / b88 - a11 / b11) - (a99 / b99 - a11 / b11) +
456 (a98 / b88) * (b89 / b99);
457 z = a32 / b22;
458 }
459
460 JRs G;
461
462 for (Index k = f; k <= l - 2; k++) {
463 // variables for Householder reflections
464 Vector2s essential2;
465 Scalar tau, beta;
466
467 Vector3s hr(x, y, z);
468
469 // Q_k to annihilate S(k+1,k-1) and S(k+2,k-1)
470 hr.makeHouseholderInPlace(tau, beta);
471 essential2 = hr.template bottomRows<2>();
472 Index fc = (std::max)(k - 1, Index(0)); // first col to update
473 m_S.template middleRows<3>(k).rightCols(dim - fc).applyHouseholderOnTheLeft(essential2, tau, m_workspace.data());
474 m_T.template middleRows<3>(k).rightCols(dim - fc).applyHouseholderOnTheLeft(essential2, tau, m_workspace.data());
475 if (m_computeQZ) m_Q.template middleCols<3>(k).applyHouseholderOnTheRight(essential2, tau, m_workspace.data());
476 if (k > f) m_S.coeffRef(k + 2, k - 1) = m_S.coeffRef(k + 1, k - 1) = Scalar(0.0);
477
478 // Z_{k1} to annihilate T(k+2,k+1) and T(k+2,k)
479 hr << m_T.coeff(k + 2, k + 2), m_T.coeff(k + 2, k), m_T.coeff(k + 2, k + 1);
480 hr.makeHouseholderInPlace(tau, beta);
481 essential2 = hr.template bottomRows<2>();
482 {
483 Index lr = (std::min)(k + 4, dim); // last row to update
484 Map<Matrix<Scalar, Dynamic, 1> > tmp(m_workspace.data(), lr);
485 // S
486 tmp.noalias() = m_S.template middleCols<2>(k).topRows(lr) * essential2;
487 tmp += m_S.col(k + 2).head(lr);
488 m_S.col(k + 2).head(lr) -= tau * tmp;
489 m_S.template middleCols<2>(k).topRows(lr).noalias() -= (tau * tmp) * essential2.adjoint();
490 // T
491 tmp.noalias() = m_T.template middleCols<2>(k).topRows(lr) * essential2;
492 tmp += m_T.col(k + 2).head(lr);
493 m_T.col(k + 2).head(lr) -= tau * tmp;
494 m_T.template middleCols<2>(k).topRows(lr).noalias() -= (tau * tmp) * essential2.adjoint();
495 }
496 if (m_computeQZ) {
497 // Z
498 Map<Matrix<Scalar, 1, Dynamic> > tmp(m_workspace.data(), dim);
499 tmp.noalias() = essential2.adjoint() * (m_Z.template middleRows<2>(k));
500 tmp += m_Z.row(k + 2);
501 m_Z.row(k + 2) -= tau * tmp;
502 m_Z.template middleRows<2>(k).noalias() -= essential2 * (tau * tmp);
503 }
504 m_T.coeffRef(k + 2, k) = m_T.coeffRef(k + 2, k + 1) = Scalar(0.0);
505
506 // Z_{k2} to annihilate T(k+1,k)
507 G.makeGivens(m_T.coeff(k + 1, k + 1), m_T.coeff(k + 1, k));
508 m_S.applyOnTheRight(k + 1, k, G);
509 m_T.applyOnTheRight(k + 1, k, G);
510 // update Z
511 if (m_computeQZ) m_Z.applyOnTheLeft(k + 1, k, G.adjoint());
512 m_T.coeffRef(k + 1, k) = Scalar(0.0);
513
514 // update x,y,z
515 x = m_S.coeff(k + 1, k);
516 y = m_S.coeff(k + 2, k);
517 if (k < l - 2) z = m_S.coeff(k + 3, k);
518 } // loop over k
519
520 // Q_{n-1} to annihilate y = S(l,l-2)
521 G.makeGivens(x, y);
522 m_S.applyOnTheLeft(l - 1, l, G.adjoint());
523 m_T.applyOnTheLeft(l - 1, l, G.adjoint());
524 if (m_computeQZ) m_Q.applyOnTheRight(l - 1, l, G);
525 m_S.coeffRef(l, l - 2) = Scalar(0.0);
526
527 // Z_{n-1} to annihilate T(l,l-1)
528 G.makeGivens(m_T.coeff(l, l), m_T.coeff(l, l - 1));
529 m_S.applyOnTheRight(l, l - 1, G);
530 m_T.applyOnTheRight(l, l - 1, G);
531 if (m_computeQZ) m_Z.applyOnTheLeft(l, l - 1, G.adjoint());
532 m_T.coeffRef(l, l - 1) = Scalar(0.0);
533}
534
535template <typename MatrixType>
536template <typename InputTypeA, typename InputTypeB>
538 bool computeQZ) {
539 eigen_assert(A_in.rows() == A_in.cols() && B_in.rows() == A_in.cols() && B_in.cols() == A_in.cols() &&
540 "Need square matrices of the same dimension");
541 m_S = A_in.derived();
542 m_T = B_in.derived();
543 return computeInPlace(computeQZ);
544}
545
547template <typename MatrixType>
548RealQZ<MatrixType>& RealQZ<MatrixType>::computeInPlace(bool computeQZ) {
549 const Index dim = m_S.cols();
550
551 eigen_assert(m_S.rows() == dim && m_T.rows() == dim && m_T.cols() == dim &&
552 "Need square matrices of the same dimension");
553
554 m_isInitialized = true;
555 m_computeQZ = computeQZ;
556 m_workspace.resize(dim * 2);
557 m_global_iter = 0;
558
559 // entrance point: hessenberg triangular decomposition
560 hessenbergTriangular();
561 // compute L1 vector norms of T, S into m_normOfS, m_normOfT
562 computeNorms();
563
564 Index l = dim - 1, f, local_iter = 0;
565
566 while (l > 0 && local_iter < m_maxIters) {
567 f = findSmallSubdiagEntry(l);
568 // now rows and columns f..l (including) decouple from the rest of the problem
569 if (f > 0) m_S.coeffRef(f, f - 1) = Scalar(0.0);
570 if (f == l) // One root found
571 {
572 l--;
573 local_iter = 0;
574 } else if (f == l - 1) // Two roots found
575 {
576 splitOffTwoRows(f);
577 l -= 2;
578 local_iter = 0;
579 } else // No convergence yet
580 {
581 // if there's zero on diagonal of T, we can isolate an eigenvalue with Givens rotations
582 Index z = findSmallDiagEntry(f, l);
583 if (z >= f) {
584 // zero found
585 pushDownZero(z, f, l);
586 } else {
587 // We are sure now that S.block(f,f, l-f+1,l-f+1) is unreduced upper-Hessenberg
588 // and T.block(f,f, l-f+1,l-f+1) is invertible upper-triangular, which allows to
589 // apply a QR-like iteration to rows and columns f..l.
590 step(f, l, local_iter);
591 // count QR-like steps
592 m_global_iter++;
593 }
594 // count iterations toward m_maxIters
595 local_iter++;
596 }
597 }
598 // check if we converged before reaching iterations limit
599 m_info = (local_iter < m_maxIters) ? Success : NoConvergence;
600
601 // For each non triangular 2x2 diagonal block of S,
602 // reduce the respective 2x2 diagonal block of T to positive diagonal form using 2x2 SVD.
603 // This step is not mandatory for QZ, but it does help further extraction of eigenvalues/eigenvectors,
604 // and is in par with Lapack/Matlab QZ.
605 if (m_info == Success) {
606 for (Index i = 0; i < dim - 1; ++i) {
607 if (!numext::is_exactly_zero(m_S.coeff(i + 1, i))) {
608 JacobiRotation<Scalar> j_left, j_right;
609 internal::real_2x2_jacobi_svd(m_T, i, i + 1, &j_left, &j_right);
610
611 // Apply resulting Jacobi rotations
612 m_S.applyOnTheLeft(i, i + 1, j_left);
613 m_S.applyOnTheRight(i, i + 1, j_right);
614 m_T.applyOnTheLeft(i, i + 1, j_left);
615 m_T.applyOnTheRight(i, i + 1, j_right);
616 m_T(i + 1, i) = m_T(i, i + 1) = Scalar(0);
617
618 if (m_computeQZ) {
619 m_Q.applyOnTheRight(i, i + 1, j_left.transpose());
620 m_Z.applyOnTheLeft(i, i + 1, j_right.transpose());
621 }
622
623 i++;
624 }
625 }
626 }
627
628 // The QZ sweep restores T's triangularity only up to rounding, so its strictly lower triangle
629 // can retain entries of order eps*||T||. matrixT() is documented upper triangular; make it so,
630 // as the deflation above already does for the subdiagonal of S.
631 m_T.template triangularView<StrictlyLower>().setZero();
632
633 return *this;
634} // end compute
635
636} // end namespace Eigen
637
638#endif // EIGEN_REAL_QZ_H
Rotation given by a cosine-sine pair.
Definition Jacobi.h:39
A matrix or vector expression mapping an existing array of data.
Definition Map.h:97
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:188
Performs a real QZ decomposition of a pair of square matrices.
Definition RealQZ.h:62
RealQZ(EigenBase< InputTypeA > &A, EigenBase< InputTypeB > &B, bool computeQZ=true)
Constructor for inplace decomposition .
Definition RealQZ.h:139
const MatrixType & matrixT() const
Returns matrix S in the QZ decomposition.
Definition RealQZ.h:185
const MatrixType & matrixS() const
Returns matrix S in the QZ decomposition.
Definition RealQZ.h:176
Index iterations() const
Returns number of performed QR-like iterations.
Definition RealQZ.h:211
Eigen::Index Index
Definition RealQZ.h:74
const PlainMatrixType & matrixQ() const
Returns matrix Q in the QZ decomposition.
Definition RealQZ.h:156
ComputationInfo info() const
Reports whether previous computation was successful.
Definition RealQZ.h:204
Matrix< Scalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime > PlainMatrixType
Type of the matrices returned by matrixQ() and matrixZ(): a plain matrix with the shape and storage o...
Definition RealQZ.h:81
const PlainMatrixType & matrixZ() const
Returns matrix Z in the QZ decomposition.
Definition RealQZ.h:166
RealQZ & compute(const EigenBase< InputTypeA > &A, const EigenBase< InputTypeB > &B, bool computeQZ=true)
Computes QZ decomposition of given matrix.
RealQZ(Index size=RowsAtCompileTime==Dynamic ? 1 :RowsAtCompileTime)
Default constructor.
Definition RealQZ.h:95
RealQZ(const EigenBase< InputTypeA > &A, const EigenBase< InputTypeB > &B, bool computeQZ=true)
Constructor; computes real QZ decomposition of given matrices.
Definition RealQZ.h:115
RealQZ & setMaxIterations(Index maxIters)
Definition RealQZ.h:219
HouseholderSequence< VectorsType, CoeffsType > householderSequence(const VectorsType &v, const CoeffsType &h)
Convenience function for constructing a Householder sequence.
Definition HouseholderSequence.h:673
ComputationInfo
Definition Constants.h:455
@ Success
Definition Constants.h:457
@ NoConvergence
Definition Constants.h:461
Definition EigenBase.h:34