<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
generalized_schur_move.hpp
Go to the documentation of this file.
1
5//
6// Copyright (c) 2021-2023, University of Colorado Denver. All rights reserved.
7//
8// This file is part of <T>LAPACK.
9// <T>LAPACK is free software: you can redistribute it and/or modify it under
10// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
11
12#ifndef TLAPACK_GENERALIZED_SCHUR_MOVE_HH
13#define TLAPACK_GENERALIZED_SCHUR_MOVE_HH
14
17
18namespace tlapack {
19
52template <TLAPACK_MATRIX matrix_t>
54 bool want_z,
55 matrix_t& A,
56 matrix_t& B,
57 matrix_t& Q,
58 matrix_t& Z,
61{
62 using idx_t = size_type<matrix_t>;
63 using T = type_t<matrix_t>;
64 using real_t = real_type<T>;
65
66 const idx_t n = ncols(A);
67 const real_t zero(0);
68
69 // Quick return
70 if (n == 0) return 0;
71
72 // Check if ifst points to the middle of a 2x2 block
73 if (is_real<T>)
74 if (ifst > 0)
75 if (A(ifst, ifst - 1) != zero) ifst = ifst - 1;
76
77 // Size of the current block, can be either 1, 2
78 idx_t nbf = 1;
79 if (is_real<T>)
80 if (ifst < n - 1)
81 if (A(ifst + 1, ifst) != zero) nbf = 2;
82
83 // Check if ilst points to the middle of a 2x2 block
84 if (is_real<T>)
85 if (ilst > 0)
86 if (A(ilst, ilst - 1) != zero) ilst = ilst - 1;
87
88 // Size of the final block, can be either 1, 2
89 idx_t nbl = 1;
90 if (is_real<T>)
91 if (ilst < n - 1)
92 if (A(ilst + 1, ilst) != zero) nbl = 2;
93
94 idx_t here = ifst;
95 if (ifst < ilst) {
96 if (nbf == 2 and nbl == 1) ilst = ilst - 1;
97 if (nbf == 1 and nbl == 2) ilst = ilst + 1;
98
99 while (here != ilst) {
100 // Size of the next eigenvalue block
101 idx_t nbnext = 1;
102 if (is_real<T>)
103 if (here + nbf + 1 < n)
104 if (A(here + nbf + 1, here + nbf) != zero) nbnext = 2;
105
107 nbf, nbnext);
108 if (ierr) {
109 // The swap failed, return with error
110 ilst = here;
111 return 1;
112 }
113 here = here + nbnext;
114 }
115 }
116 else {
117 while (here != ilst) {
118 // Size of the next eigenvalue block
119 idx_t nbnext = 1;
120 if (is_real<T>)
121 if (here > 1)
122 if (A(here - 1, here - 2) != zero) nbnext = 2;
123
125 here - nbnext, nbnext, nbf);
126 if (ierr) {
127 // The swap failed, return with error
128 ilst = here;
129 return 1;
130 }
131 here = here - nbnext;
132 }
133 }
134
135 return 0;
136}
137
138} // namespace tlapack
139
140#endif // TLAPACK_GENERALIZED_SCHUR_MOVE_HH
int generalized_schur_swap(bool want_q, bool want_z, matrix_t &A, matrix_t &B, matrix_t &Q, matrix_t &Z, const size_type< matrix_t > &j0, const size_type< matrix_t > &n1, const size_type< matrix_t > &n2)
schur_swap, swaps 2 eigenvalues of A.
Definition generalized_schur_swap.hpp:58
int generalized_schur_move(bool want_q, bool want_z, matrix_t &A, matrix_t &B, matrix_t &Q, matrix_t &Z, size_type< matrix_t > &ifst, size_type< matrix_t > &ilst)
generalized_schur_move reorders the generalized Schur factorization of a pencil ( S,...
Definition generalized_schur_move.hpp:53
typename traits::real_type_traits< Types..., int >::type real_type
The common real type of the list of types.
Definition scalar_type_traits.hpp:113