Mercurial > octave
comparison libcruft/lapack/claqr0.f @ 7789:82be108cc558
First attempt at single precision tyeps
* * *
corrections to qrupdate single precision routines
* * *
prefer demotion to single over promotion to double
* * *
Add single precision support to log2 function
* * *
Trivial PROJECT file update
* * *
Cache optimized hermitian/transpose methods
* * *
Add tests for tranpose/hermitian and ChangeLog entry for new transpose code
author | David Bateman <dbateman@free.fr> |
---|---|
date | Sun, 27 Apr 2008 22:34:17 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7788:45f5faba05a2 | 7789:82be108cc558 |
---|---|
1 SUBROUTINE CLAQR0( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ, | |
2 $ IHIZ, Z, LDZ, WORK, LWORK, INFO ) | |
3 * | |
4 * -- LAPACK auxiliary routine (version 3.1) -- | |
5 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. | |
6 * November 2006 | |
7 * | |
8 * .. Scalar Arguments .. | |
9 INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, LWORK, N | |
10 LOGICAL WANTT, WANTZ | |
11 * .. | |
12 * .. Array Arguments .. | |
13 COMPLEX H( LDH, * ), W( * ), WORK( * ), Z( LDZ, * ) | |
14 * .. | |
15 * | |
16 * Purpose | |
17 * ======= | |
18 * | |
19 * CLAQR0 computes the eigenvalues of a Hessenberg matrix H | |
20 * and, optionally, the matrices T and Z from the Schur decomposition | |
21 * H = Z T Z**H, where T is an upper triangular matrix (the | |
22 * Schur form), and Z is the unitary matrix of Schur vectors. | |
23 * | |
24 * Optionally Z may be postmultiplied into an input unitary | |
25 * matrix Q so that this routine can give the Schur factorization | |
26 * of a matrix A which has been reduced to the Hessenberg form H | |
27 * by the unitary matrix Q: A = Q*H*Q**H = (QZ)*H*(QZ)**H. | |
28 * | |
29 * Arguments | |
30 * ========= | |
31 * | |
32 * WANTT (input) LOGICAL | |
33 * = .TRUE. : the full Schur form T is required; | |
34 * = .FALSE.: only eigenvalues are required. | |
35 * | |
36 * WANTZ (input) LOGICAL | |
37 * = .TRUE. : the matrix of Schur vectors Z is required; | |
38 * = .FALSE.: Schur vectors are not required. | |
39 * | |
40 * N (input) INTEGER | |
41 * The order of the matrix H. N .GE. 0. | |
42 * | |
43 * ILO (input) INTEGER | |
44 * IHI (input) INTEGER | |
45 * It is assumed that H is already upper triangular in rows | |
46 * and columns 1:ILO-1 and IHI+1:N and, if ILO.GT.1, | |
47 * H(ILO,ILO-1) is zero. ILO and IHI are normally set by a | |
48 * previous call to CGEBAL, and then passed to CGEHRD when the | |
49 * matrix output by CGEBAL is reduced to Hessenberg form. | |
50 * Otherwise, ILO and IHI should be set to 1 and N, | |
51 * respectively. If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N. | |
52 * If N = 0, then ILO = 1 and IHI = 0. | |
53 * | |
54 * H (input/output) COMPLEX array, dimension (LDH,N) | |
55 * On entry, the upper Hessenberg matrix H. | |
56 * On exit, if INFO = 0 and WANTT is .TRUE., then H | |
57 * contains the upper triangular matrix T from the Schur | |
58 * decomposition (the Schur form). If INFO = 0 and WANT is | |
59 * .FALSE., then the contents of H are unspecified on exit. | |
60 * (The output value of H when INFO.GT.0 is given under the | |
61 * description of INFO below.) | |
62 * | |
63 * This subroutine may explicitly set H(i,j) = 0 for i.GT.j and | |
64 * j = 1, 2, ... ILO-1 or j = IHI+1, IHI+2, ... N. | |
65 * | |
66 * LDH (input) INTEGER | |
67 * The leading dimension of the array H. LDH .GE. max(1,N). | |
68 * | |
69 * W (output) COMPLEX array, dimension (N) | |
70 * The computed eigenvalues of H(ILO:IHI,ILO:IHI) are stored | |
71 * in W(ILO:IHI). If WANTT is .TRUE., then the eigenvalues are | |
72 * stored in the same order as on the diagonal of the Schur | |
73 * form returned in H, with W(i) = H(i,i). | |
74 * | |
75 * Z (input/output) COMPLEX array, dimension (LDZ,IHI) | |
76 * If WANTZ is .FALSE., then Z is not referenced. | |
77 * If WANTZ is .TRUE., then Z(ILO:IHI,ILOZ:IHIZ) is | |
78 * replaced by Z(ILO:IHI,ILOZ:IHIZ)*U where U is the | |
79 * orthogonal Schur factor of H(ILO:IHI,ILO:IHI). | |
80 * (The output value of Z when INFO.GT.0 is given under | |
81 * the description of INFO below.) | |
82 * | |
83 * LDZ (input) INTEGER | |
84 * The leading dimension of the array Z. if WANTZ is .TRUE. | |
85 * then LDZ.GE.MAX(1,IHIZ). Otherwize, LDZ.GE.1. | |
86 * | |
87 * WORK (workspace/output) COMPLEX array, dimension LWORK | |
88 * On exit, if LWORK = -1, WORK(1) returns an estimate of | |
89 * the optimal value for LWORK. | |
90 * | |
91 * LWORK (input) INTEGER | |
92 * The dimension of the array WORK. LWORK .GE. max(1,N) | |
93 * is sufficient, but LWORK typically as large as 6*N may | |
94 * be required for optimal performance. A workspace query | |
95 * to determine the optimal workspace size is recommended. | |
96 * | |
97 * If LWORK = -1, then CLAQR0 does a workspace query. | |
98 * In this case, CLAQR0 checks the input parameters and | |
99 * estimates the optimal workspace size for the given | |
100 * values of N, ILO and IHI. The estimate is returned | |
101 * in WORK(1). No error message related to LWORK is | |
102 * issued by XERBLA. Neither H nor Z are accessed. | |
103 * | |
104 * | |
105 * INFO (output) INTEGER | |
106 * = 0: successful exit | |
107 * .GT. 0: if INFO = i, CLAQR0 failed to compute all of | |
108 * the eigenvalues. Elements 1:ilo-1 and i+1:n of WR | |
109 * and WI contain those eigenvalues which have been | |
110 * successfully computed. (Failures are rare.) | |
111 * | |
112 * If INFO .GT. 0 and WANT is .FALSE., then on exit, | |
113 * the remaining unconverged eigenvalues are the eigen- | |
114 * values of the upper Hessenberg matrix rows and | |
115 * columns ILO through INFO of the final, output | |
116 * value of H. | |
117 * | |
118 * If INFO .GT. 0 and WANTT is .TRUE., then on exit | |
119 * | |
120 * (*) (initial value of H)*U = U*(final value of H) | |
121 * | |
122 * where U is a unitary matrix. The final | |
123 * value of H is upper Hessenberg and triangular in | |
124 * rows and columns INFO+1 through IHI. | |
125 * | |
126 * If INFO .GT. 0 and WANTZ is .TRUE., then on exit | |
127 * | |
128 * (final value of Z(ILO:IHI,ILOZ:IHIZ) | |
129 * = (initial value of Z(ILO:IHI,ILOZ:IHIZ)*U | |
130 * | |
131 * where U is the unitary matrix in (*) (regard- | |
132 * less of the value of WANTT.) | |
133 * | |
134 * If INFO .GT. 0 and WANTZ is .FALSE., then Z is not | |
135 * accessed. | |
136 * | |
137 * ================================================================ | |
138 * Based on contributions by | |
139 * Karen Braman and Ralph Byers, Department of Mathematics, | |
140 * University of Kansas, USA | |
141 * | |
142 * ================================================================ | |
143 * References: | |
144 * K. Braman, R. Byers and R. Mathias, The Multi-Shift QR | |
145 * Algorithm Part I: Maintaining Well Focused Shifts, and Level 3 | |
146 * Performance, SIAM Journal of Matrix Analysis, volume 23, pages | |
147 * 929--947, 2002. | |
148 * | |
149 * K. Braman, R. Byers and R. Mathias, The Multi-Shift QR | |
150 * Algorithm Part II: Aggressive Early Deflation, SIAM Journal | |
151 * of Matrix Analysis, volume 23, pages 948--973, 2002. | |
152 * | |
153 * ================================================================ | |
154 * .. Parameters .. | |
155 * | |
156 * ==== Matrices of order NTINY or smaller must be processed by | |
157 * . CLAHQR because of insufficient subdiagonal scratch space. | |
158 * . (This is a hard limit.) ==== | |
159 * | |
160 * ==== Exceptional deflation windows: try to cure rare | |
161 * . slow convergence by increasing the size of the | |
162 * . deflation window after KEXNW iterations. ===== | |
163 * | |
164 * ==== Exceptional shifts: try to cure rare slow convergence | |
165 * . with ad-hoc exceptional shifts every KEXSH iterations. | |
166 * . The constants WILK1 and WILK2 are used to form the | |
167 * . exceptional shifts. ==== | |
168 * | |
169 INTEGER NTINY | |
170 PARAMETER ( NTINY = 11 ) | |
171 INTEGER KEXNW, KEXSH | |
172 PARAMETER ( KEXNW = 5, KEXSH = 6 ) | |
173 REAL WILK1 | |
174 PARAMETER ( WILK1 = 0.75e0 ) | |
175 COMPLEX ZERO, ONE | |
176 PARAMETER ( ZERO = ( 0.0e0, 0.0e0 ), | |
177 $ ONE = ( 1.0e0, 0.0e0 ) ) | |
178 REAL TWO | |
179 PARAMETER ( TWO = 2.0e0 ) | |
180 * .. | |
181 * .. Local Scalars .. | |
182 COMPLEX AA, BB, CC, CDUM, DD, DET, RTDISC, SWAP, TR2 | |
183 REAL S | |
184 INTEGER I, INF, IT, ITMAX, K, KACC22, KBOT, KDU, KS, | |
185 $ KT, KTOP, KU, KV, KWH, KWTOP, KWV, LD, LS, | |
186 $ LWKOPT, NDFL, NH, NHO, NIBBLE, NMIN, NS, NSMAX, | |
187 $ NSR, NVE, NW, NWMAX, NWR | |
188 LOGICAL NWINC, SORTED | |
189 CHARACTER JBCMPZ*2 | |
190 * .. | |
191 * .. External Functions .. | |
192 INTEGER ILAENV | |
193 EXTERNAL ILAENV | |
194 * .. | |
195 * .. Local Arrays .. | |
196 COMPLEX ZDUM( 1, 1 ) | |
197 * .. | |
198 * .. External Subroutines .. | |
199 EXTERNAL CLACPY, CLAHQR, CLAQR3, CLAQR4, CLAQR5 | |
200 * .. | |
201 * .. Intrinsic Functions .. | |
202 INTRINSIC ABS, AIMAG, CMPLX, INT, MAX, MIN, MOD, REAL, | |
203 $ SQRT | |
204 * .. | |
205 * .. Statement Functions .. | |
206 REAL CABS1 | |
207 * .. | |
208 * .. Statement Function definitions .. | |
209 CABS1( CDUM ) = ABS( REAL( CDUM ) ) + ABS( AIMAG( CDUM ) ) | |
210 * .. | |
211 * .. Executable Statements .. | |
212 INFO = 0 | |
213 * | |
214 * ==== Quick return for N = 0: nothing to do. ==== | |
215 * | |
216 IF( N.EQ.0 ) THEN | |
217 WORK( 1 ) = ONE | |
218 RETURN | |
219 END IF | |
220 * | |
221 * ==== Set up job flags for ILAENV. ==== | |
222 * | |
223 IF( WANTT ) THEN | |
224 JBCMPZ( 1: 1 ) = 'S' | |
225 ELSE | |
226 JBCMPZ( 1: 1 ) = 'E' | |
227 END IF | |
228 IF( WANTZ ) THEN | |
229 JBCMPZ( 2: 2 ) = 'V' | |
230 ELSE | |
231 JBCMPZ( 2: 2 ) = 'N' | |
232 END IF | |
233 * | |
234 * ==== Tiny matrices must use CLAHQR. ==== | |
235 * | |
236 IF( N.LE.NTINY ) THEN | |
237 * | |
238 * ==== Estimate optimal workspace. ==== | |
239 * | |
240 LWKOPT = 1 | |
241 IF( LWORK.NE.-1 ) | |
242 $ CALL CLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ, | |
243 $ IHIZ, Z, LDZ, INFO ) | |
244 ELSE | |
245 * | |
246 * ==== Use small bulge multi-shift QR with aggressive early | |
247 * . deflation on larger-than-tiny matrices. ==== | |
248 * | |
249 * ==== Hope for the best. ==== | |
250 * | |
251 INFO = 0 | |
252 * | |
253 * ==== NWR = recommended deflation window size. At this | |
254 * . point, N .GT. NTINY = 11, so there is enough | |
255 * . subdiagonal workspace for NWR.GE.2 as required. | |
256 * . (In fact, there is enough subdiagonal space for | |
257 * . NWR.GE.3.) ==== | |
258 * | |
259 NWR = ILAENV( 13, 'CLAQR0', JBCMPZ, N, ILO, IHI, LWORK ) | |
260 NWR = MAX( 2, NWR ) | |
261 NWR = MIN( IHI-ILO+1, ( N-1 ) / 3, NWR ) | |
262 NW = NWR | |
263 * | |
264 * ==== NSR = recommended number of simultaneous shifts. | |
265 * . At this point N .GT. NTINY = 11, so there is at | |
266 * . enough subdiagonal workspace for NSR to be even | |
267 * . and greater than or equal to two as required. ==== | |
268 * | |
269 NSR = ILAENV( 15, 'CLAQR0', JBCMPZ, N, ILO, IHI, LWORK ) | |
270 NSR = MIN( NSR, ( N+6 ) / 9, IHI-ILO ) | |
271 NSR = MAX( 2, NSR-MOD( NSR, 2 ) ) | |
272 * | |
273 * ==== Estimate optimal workspace ==== | |
274 * | |
275 * ==== Workspace query call to CLAQR3 ==== | |
276 * | |
277 CALL CLAQR3( WANTT, WANTZ, N, ILO, IHI, NWR+1, H, LDH, ILOZ, | |
278 $ IHIZ, Z, LDZ, LS, LD, W, H, LDH, N, H, LDH, N, H, | |
279 $ LDH, WORK, -1 ) | |
280 * | |
281 * ==== Optimal workspace = MAX(CLAQR5, CLAQR3) ==== | |
282 * | |
283 LWKOPT = MAX( 3*NSR / 2, INT( WORK( 1 ) ) ) | |
284 * | |
285 * ==== Quick return in case of workspace query. ==== | |
286 * | |
287 IF( LWORK.EQ.-1 ) THEN | |
288 WORK( 1 ) = CMPLX( LWKOPT, 0 ) | |
289 RETURN | |
290 END IF | |
291 * | |
292 * ==== CLAHQR/CLAQR0 crossover point ==== | |
293 * | |
294 NMIN = ILAENV( 12, 'CLAQR0', JBCMPZ, N, ILO, IHI, LWORK ) | |
295 NMIN = MAX( NTINY, NMIN ) | |
296 * | |
297 * ==== Nibble crossover point ==== | |
298 * | |
299 NIBBLE = ILAENV( 14, 'CLAQR0', JBCMPZ, N, ILO, IHI, LWORK ) | |
300 NIBBLE = MAX( 0, NIBBLE ) | |
301 * | |
302 * ==== Accumulate reflections during ttswp? Use block | |
303 * . 2-by-2 structure during matrix-matrix multiply? ==== | |
304 * | |
305 KACC22 = ILAENV( 16, 'CLAQR0', JBCMPZ, N, ILO, IHI, LWORK ) | |
306 KACC22 = MAX( 0, KACC22 ) | |
307 KACC22 = MIN( 2, KACC22 ) | |
308 * | |
309 * ==== NWMAX = the largest possible deflation window for | |
310 * . which there is sufficient workspace. ==== | |
311 * | |
312 NWMAX = MIN( ( N-1 ) / 3, LWORK / 2 ) | |
313 * | |
314 * ==== NSMAX = the Largest number of simultaneous shifts | |
315 * . for which there is sufficient workspace. ==== | |
316 * | |
317 NSMAX = MIN( ( N+6 ) / 9, 2*LWORK / 3 ) | |
318 NSMAX = NSMAX - MOD( NSMAX, 2 ) | |
319 * | |
320 * ==== NDFL: an iteration count restarted at deflation. ==== | |
321 * | |
322 NDFL = 1 | |
323 * | |
324 * ==== ITMAX = iteration limit ==== | |
325 * | |
326 ITMAX = MAX( 30, 2*KEXSH )*MAX( 10, ( IHI-ILO+1 ) ) | |
327 * | |
328 * ==== Last row and column in the active block ==== | |
329 * | |
330 KBOT = IHI | |
331 * | |
332 * ==== Main Loop ==== | |
333 * | |
334 DO 70 IT = 1, ITMAX | |
335 * | |
336 * ==== Done when KBOT falls below ILO ==== | |
337 * | |
338 IF( KBOT.LT.ILO ) | |
339 $ GO TO 80 | |
340 * | |
341 * ==== Locate active block ==== | |
342 * | |
343 DO 10 K = KBOT, ILO + 1, -1 | |
344 IF( H( K, K-1 ).EQ.ZERO ) | |
345 $ GO TO 20 | |
346 10 CONTINUE | |
347 K = ILO | |
348 20 CONTINUE | |
349 KTOP = K | |
350 * | |
351 * ==== Select deflation window size ==== | |
352 * | |
353 NH = KBOT - KTOP + 1 | |
354 IF( NDFL.LT.KEXNW .OR. NH.LT.NW ) THEN | |
355 * | |
356 * ==== Typical deflation window. If possible and | |
357 * . advisable, nibble the entire active block. | |
358 * . If not, use size NWR or NWR+1 depending upon | |
359 * . which has the smaller corresponding subdiagonal | |
360 * . entry (a heuristic). ==== | |
361 * | |
362 NWINC = .TRUE. | |
363 IF( NH.LE.MIN( NMIN, NWMAX ) ) THEN | |
364 NW = NH | |
365 ELSE | |
366 NW = MIN( NWR, NH, NWMAX ) | |
367 IF( NW.LT.NWMAX ) THEN | |
368 IF( NW.GE.NH-1 ) THEN | |
369 NW = NH | |
370 ELSE | |
371 KWTOP = KBOT - NW + 1 | |
372 IF( CABS1( H( KWTOP, KWTOP-1 ) ).GT. | |
373 $ CABS1( H( KWTOP-1, KWTOP-2 ) ) )NW = NW + 1 | |
374 END IF | |
375 END IF | |
376 END IF | |
377 ELSE | |
378 * | |
379 * ==== Exceptional deflation window. If there have | |
380 * . been no deflations in KEXNW or more iterations, | |
381 * . then vary the deflation window size. At first, | |
382 * . because, larger windows are, in general, more | |
383 * . powerful than smaller ones, rapidly increase the | |
384 * . window up to the maximum reasonable and possible. | |
385 * . Then maybe try a slightly smaller window. ==== | |
386 * | |
387 IF( NWINC .AND. NW.LT.MIN( NWMAX, NH ) ) THEN | |
388 NW = MIN( NWMAX, NH, 2*NW ) | |
389 ELSE | |
390 NWINC = .FALSE. | |
391 IF( NW.EQ.NH .AND. NH.GT.2 ) | |
392 $ NW = NH - 1 | |
393 END IF | |
394 END IF | |
395 * | |
396 * ==== Aggressive early deflation: | |
397 * . split workspace under the subdiagonal into | |
398 * . - an nw-by-nw work array V in the lower | |
399 * . left-hand-corner, | |
400 * . - an NW-by-at-least-NW-but-more-is-better | |
401 * . (NW-by-NHO) horizontal work array along | |
402 * . the bottom edge, | |
403 * . - an at-least-NW-but-more-is-better (NHV-by-NW) | |
404 * . vertical work array along the left-hand-edge. | |
405 * . ==== | |
406 * | |
407 KV = N - NW + 1 | |
408 KT = NW + 1 | |
409 NHO = ( N-NW-1 ) - KT + 1 | |
410 KWV = NW + 2 | |
411 NVE = ( N-NW ) - KWV + 1 | |
412 * | |
413 * ==== Aggressive early deflation ==== | |
414 * | |
415 CALL CLAQR3( WANTT, WANTZ, N, KTOP, KBOT, NW, H, LDH, ILOZ, | |
416 $ IHIZ, Z, LDZ, LS, LD, W, H( KV, 1 ), LDH, NHO, | |
417 $ H( KV, KT ), LDH, NVE, H( KWV, 1 ), LDH, WORK, | |
418 $ LWORK ) | |
419 * | |
420 * ==== Adjust KBOT accounting for new deflations. ==== | |
421 * | |
422 KBOT = KBOT - LD | |
423 * | |
424 * ==== KS points to the shifts. ==== | |
425 * | |
426 KS = KBOT - LS + 1 | |
427 * | |
428 * ==== Skip an expensive QR sweep if there is a (partly | |
429 * . heuristic) reason to expect that many eigenvalues | |
430 * . will deflate without it. Here, the QR sweep is | |
431 * . skipped if many eigenvalues have just been deflated | |
432 * . or if the remaining active block is small. | |
433 * | |
434 IF( ( LD.EQ.0 ) .OR. ( ( 100*LD.LE.NW*NIBBLE ) .AND. ( KBOT- | |
435 $ KTOP+1.GT.MIN( NMIN, NWMAX ) ) ) ) THEN | |
436 * | |
437 * ==== NS = nominal number of simultaneous shifts. | |
438 * . This may be lowered (slightly) if CLAQR3 | |
439 * . did not provide that many shifts. ==== | |
440 * | |
441 NS = MIN( NSMAX, NSR, MAX( 2, KBOT-KTOP ) ) | |
442 NS = NS - MOD( NS, 2 ) | |
443 * | |
444 * ==== If there have been no deflations | |
445 * . in a multiple of KEXSH iterations, | |
446 * . then try exceptional shifts. | |
447 * . Otherwise use shifts provided by | |
448 * . CLAQR3 above or from the eigenvalues | |
449 * . of a trailing principal submatrix. ==== | |
450 * | |
451 IF( MOD( NDFL, KEXSH ).EQ.0 ) THEN | |
452 KS = KBOT - NS + 1 | |
453 DO 30 I = KBOT, KS + 1, -2 | |
454 W( I ) = H( I, I ) + WILK1*CABS1( H( I, I-1 ) ) | |
455 W( I-1 ) = W( I ) | |
456 30 CONTINUE | |
457 ELSE | |
458 * | |
459 * ==== Got NS/2 or fewer shifts? Use CLAQR4 or | |
460 * . CLAHQR on a trailing principal submatrix to | |
461 * . get more. (Since NS.LE.NSMAX.LE.(N+6)/9, | |
462 * . there is enough space below the subdiagonal | |
463 * . to fit an NS-by-NS scratch array.) ==== | |
464 * | |
465 IF( KBOT-KS+1.LE.NS / 2 ) THEN | |
466 KS = KBOT - NS + 1 | |
467 KT = N - NS + 1 | |
468 CALL CLACPY( 'A', NS, NS, H( KS, KS ), LDH, | |
469 $ H( KT, 1 ), LDH ) | |
470 IF( NS.GT.NMIN ) THEN | |
471 CALL CLAQR4( .false., .false., NS, 1, NS, | |
472 $ H( KT, 1 ), LDH, W( KS ), 1, 1, | |
473 $ ZDUM, 1, WORK, LWORK, INF ) | |
474 ELSE | |
475 CALL CLAHQR( .false., .false., NS, 1, NS, | |
476 $ H( KT, 1 ), LDH, W( KS ), 1, 1, | |
477 $ ZDUM, 1, INF ) | |
478 END IF | |
479 KS = KS + INF | |
480 * | |
481 * ==== In case of a rare QR failure use | |
482 * . eigenvalues of the trailing 2-by-2 | |
483 * . principal submatrix. Scale to avoid | |
484 * . overflows, underflows and subnormals. | |
485 * . (The scale factor S can not be zero, | |
486 * . because H(KBOT,KBOT-1) is nonzero.) ==== | |
487 * | |
488 IF( KS.GE.KBOT ) THEN | |
489 S = CABS1( H( KBOT-1, KBOT-1 ) ) + | |
490 $ CABS1( H( KBOT, KBOT-1 ) ) + | |
491 $ CABS1( H( KBOT-1, KBOT ) ) + | |
492 $ CABS1( H( KBOT, KBOT ) ) | |
493 AA = H( KBOT-1, KBOT-1 ) / S | |
494 CC = H( KBOT, KBOT-1 ) / S | |
495 BB = H( KBOT-1, KBOT ) / S | |
496 DD = H( KBOT, KBOT ) / S | |
497 TR2 = ( AA+DD ) / TWO | |
498 DET = ( AA-TR2 )*( DD-TR2 ) - BB*CC | |
499 RTDISC = SQRT( -DET ) | |
500 W( KBOT-1 ) = ( TR2+RTDISC )*S | |
501 W( KBOT ) = ( TR2-RTDISC )*S | |
502 * | |
503 KS = KBOT - 1 | |
504 END IF | |
505 END IF | |
506 * | |
507 IF( KBOT-KS+1.GT.NS ) THEN | |
508 * | |
509 * ==== Sort the shifts (Helps a little) ==== | |
510 * | |
511 SORTED = .false. | |
512 DO 50 K = KBOT, KS + 1, -1 | |
513 IF( SORTED ) | |
514 $ GO TO 60 | |
515 SORTED = .true. | |
516 DO 40 I = KS, K - 1 | |
517 IF( CABS1( W( I ) ).LT.CABS1( W( I+1 ) ) ) | |
518 $ THEN | |
519 SORTED = .false. | |
520 SWAP = W( I ) | |
521 W( I ) = W( I+1 ) | |
522 W( I+1 ) = SWAP | |
523 END IF | |
524 40 CONTINUE | |
525 50 CONTINUE | |
526 60 CONTINUE | |
527 END IF | |
528 END IF | |
529 * | |
530 * ==== If there are only two shifts, then use | |
531 * . only one. ==== | |
532 * | |
533 IF( KBOT-KS+1.EQ.2 ) THEN | |
534 IF( CABS1( W( KBOT )-H( KBOT, KBOT ) ).LT. | |
535 $ CABS1( W( KBOT-1 )-H( KBOT, KBOT ) ) ) THEN | |
536 W( KBOT-1 ) = W( KBOT ) | |
537 ELSE | |
538 W( KBOT ) = W( KBOT-1 ) | |
539 END IF | |
540 END IF | |
541 * | |
542 * ==== Use up to NS of the the smallest magnatiude | |
543 * . shifts. If there aren't NS shifts available, | |
544 * . then use them all, possibly dropping one to | |
545 * . make the number of shifts even. ==== | |
546 * | |
547 NS = MIN( NS, KBOT-KS+1 ) | |
548 NS = NS - MOD( NS, 2 ) | |
549 KS = KBOT - NS + 1 | |
550 * | |
551 * ==== Small-bulge multi-shift QR sweep: | |
552 * . split workspace under the subdiagonal into | |
553 * . - a KDU-by-KDU work array U in the lower | |
554 * . left-hand-corner, | |
555 * . - a KDU-by-at-least-KDU-but-more-is-better | |
556 * . (KDU-by-NHo) horizontal work array WH along | |
557 * . the bottom edge, | |
558 * . - and an at-least-KDU-but-more-is-better-by-KDU | |
559 * . (NVE-by-KDU) vertical work WV arrow along | |
560 * . the left-hand-edge. ==== | |
561 * | |
562 KDU = 3*NS - 3 | |
563 KU = N - KDU + 1 | |
564 KWH = KDU + 1 | |
565 NHO = ( N-KDU+1-4 ) - ( KDU+1 ) + 1 | |
566 KWV = KDU + 4 | |
567 NVE = N - KDU - KWV + 1 | |
568 * | |
569 * ==== Small-bulge multi-shift QR sweep ==== | |
570 * | |
571 CALL CLAQR5( WANTT, WANTZ, KACC22, N, KTOP, KBOT, NS, | |
572 $ W( KS ), H, LDH, ILOZ, IHIZ, Z, LDZ, WORK, | |
573 $ 3, H( KU, 1 ), LDH, NVE, H( KWV, 1 ), LDH, | |
574 $ NHO, H( KU, KWH ), LDH ) | |
575 END IF | |
576 * | |
577 * ==== Note progress (or the lack of it). ==== | |
578 * | |
579 IF( LD.GT.0 ) THEN | |
580 NDFL = 1 | |
581 ELSE | |
582 NDFL = NDFL + 1 | |
583 END IF | |
584 * | |
585 * ==== End of main loop ==== | |
586 70 CONTINUE | |
587 * | |
588 * ==== Iteration limit exceeded. Set INFO to show where | |
589 * . the problem occurred and exit. ==== | |
590 * | |
591 INFO = KBOT | |
592 80 CONTINUE | |
593 END IF | |
594 * | |
595 * ==== Return the optimal value of LWORK. ==== | |
596 * | |
597 WORK( 1 ) = CMPLX( LWKOPT, 0 ) | |
598 * | |
599 * ==== End of CLAQR0 ==== | |
600 * | |
601 END |