LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
dlaqr4.f
Go to the documentation of this file.
1*> \brief \b DLAQR4 computes the eigenvalues of a Hessenberg matrix, and optionally the matrices from the Schur decomposition.
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download DLAQR4 + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlaqr4.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlaqr4.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlaqr4.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE DLAQR4( WANTT, WANTZ, N, ILO, IHI, H, LDH, WR, WI,
20* ILOZ, IHIZ, Z, LDZ, WORK, LWORK, INFO )
21*
22* .. Scalar Arguments ..
23* INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, LWORK, N
24* LOGICAL WANTT, WANTZ
25* ..
26* .. Array Arguments ..
27* DOUBLE PRECISION H( LDH, * ), WI( * ), WORK( * ), WR( * ),
28* $ Z( LDZ, * )
29* ..
30*
31*
32*> \par Purpose:
33* =============
34*>
35*> \verbatim
36*>
37*> DLAQR4 implements one level of recursion for DLAQR0.
38*> It is a complete implementation of the small bulge multi-shift
39*> QR algorithm. It may be called by DLAQR0 and, for large enough
40*> deflation window size, it may be called by DLAQR3. This
41*> subroutine is identical to DLAQR0 except that it calls DLAQR2
42*> instead of DLAQR3.
43*>
44*> DLAQR4 computes the eigenvalues of a Hessenberg matrix H
45*> and, optionally, the matrices T and Z from the Schur decomposition
46*> H = Z T Z**T, where T is an upper quasi-triangular matrix (the
47*> Schur form), and Z is the orthogonal matrix of Schur vectors.
48*>
49*> Optionally Z may be postmultiplied into an input orthogonal
50*> matrix Q so that this routine can give the Schur factorization
51*> of a matrix A which has been reduced to the Hessenberg form H
52*> by the orthogonal matrix Q: A = Q*H*Q**T = (QZ)*T*(QZ)**T.
53*> \endverbatim
54*
55* Arguments:
56* ==========
57*
58*> \param[in] WANTT
59*> \verbatim
60*> WANTT is LOGICAL
61*> = .TRUE. : the full Schur form T is required;
62*> = .FALSE.: only eigenvalues are required.
63*> \endverbatim
64*>
65*> \param[in] WANTZ
66*> \verbatim
67*> WANTZ is LOGICAL
68*> = .TRUE. : the matrix of Schur vectors Z is required;
69*> = .FALSE.: Schur vectors are not required.
70*> \endverbatim
71*>
72*> \param[in] N
73*> \verbatim
74*> N is INTEGER
75*> The order of the matrix H. N >= 0.
76*> \endverbatim
77*>
78*> \param[in] ILO
79*> \verbatim
80*> ILO is INTEGER
81*> \endverbatim
82*>
83*> \param[in] IHI
84*> \verbatim
85*> IHI is INTEGER
86*> It is assumed that H is already upper triangular in rows
87*> and columns 1:ILO-1 and IHI+1:N and, if ILO > 1,
88*> H(ILO,ILO-1) is zero. ILO and IHI are normally set by a
89*> previous call to DGEBAL, and then passed to DGEHRD when the
90*> matrix output by DGEBAL is reduced to Hessenberg form.
91*> Otherwise, ILO and IHI should be set to 1 and N,
92*> respectively. If N > 0, then 1 <= ILO <= IHI <= N.
93*> If N = 0, then ILO = 1 and IHI = 0.
94*> \endverbatim
95*>
96*> \param[in,out] H
97*> \verbatim
98*> H is DOUBLE PRECISION array, dimension (LDH,N)
99*> On entry, the upper Hessenberg matrix H.
100*> On exit, if INFO = 0 and WANTT is .TRUE., then H contains
101*> the upper quasi-triangular matrix T from the Schur
102*> decomposition (the Schur form); 2-by-2 diagonal blocks
103*> (corresponding to complex conjugate pairs of eigenvalues)
104*> are returned in standard form, with H(i,i) = H(i+1,i+1)
105*> and H(i+1,i)*H(i,i+1) < 0. If INFO = 0 and WANTT is
106*> .FALSE., then the contents of H are unspecified on exit.
107*> (The output value of H when INFO > 0 is given under the
108*> description of INFO below.)
109*>
110*> This subroutine may explicitly set H(i,j) = 0 for i > j and
111*> j = 1, 2, ... ILO-1 or j = IHI+1, IHI+2, ... N.
112*> \endverbatim
113*>
114*> \param[in] LDH
115*> \verbatim
116*> LDH is INTEGER
117*> The leading dimension of the array H. LDH >= max(1,N).
118*> \endverbatim
119*>
120*> \param[out] WR
121*> \verbatim
122*> WR is DOUBLE PRECISION array, dimension (IHI)
123*> \endverbatim
124*>
125*> \param[out] WI
126*> \verbatim
127*> WI is DOUBLE PRECISION array, dimension (IHI)
128*> The real and imaginary parts, respectively, of the computed
129*> eigenvalues of H(ILO:IHI,ILO:IHI) are stored in WR(ILO:IHI)
130*> and WI(ILO:IHI). If two eigenvalues are computed as a
131*> complex conjugate pair, they are stored in consecutive
132*> elements of WR and WI, say the i-th and (i+1)th, with
133*> WI(i) > 0 and WI(i+1) < 0. If WANTT is .TRUE., then
134*> the eigenvalues are stored in the same order as on the
135*> diagonal of the Schur form returned in H, with
136*> WR(i) = H(i,i) and, if H(i:i+1,i:i+1) is a 2-by-2 diagonal
137*> block, WI(i) = sqrt(-H(i+1,i)*H(i,i+1)) and
138*> WI(i+1) = -WI(i).
139*> \endverbatim
140*>
141*> \param[in] ILOZ
142*> \verbatim
143*> ILOZ is INTEGER
144*> \endverbatim
145*>
146*> \param[in] IHIZ
147*> \verbatim
148*> IHIZ is INTEGER
149*> Specify the rows of Z to which transformations must be
150*> applied if WANTZ is .TRUE..
151*> 1 <= ILOZ <= ILO; IHI <= IHIZ <= N.
152*> \endverbatim
153*>
154*> \param[in,out] Z
155*> \verbatim
156*> Z is DOUBLE PRECISION array, dimension (LDZ,IHI)
157*> If WANTZ is .FALSE., then Z is not referenced.
158*> If WANTZ is .TRUE., then Z(ILO:IHI,ILOZ:IHIZ) is
159*> replaced by Z(ILO:IHI,ILOZ:IHIZ)*U where U is the
160*> orthogonal Schur factor of H(ILO:IHI,ILO:IHI).
161*> (The output value of Z when INFO > 0 is given under
162*> the description of INFO below.)
163*> \endverbatim
164*>
165*> \param[in] LDZ
166*> \verbatim
167*> LDZ is INTEGER
168*> The leading dimension of the array Z. if WANTZ is .TRUE.
169*> then LDZ >= MAX(1,IHIZ). Otherwise, LDZ >= 1.
170*> \endverbatim
171*>
172*> \param[out] WORK
173*> \verbatim
174*> WORK is DOUBLE PRECISION array, dimension LWORK
175*> On exit, if LWORK = -1, WORK(1) returns an estimate of
176*> the optimal value for LWORK.
177*> \endverbatim
178*>
179*> \param[in] LWORK
180*> \verbatim
181*> LWORK is INTEGER
182*> The dimension of the array WORK. LWORK >= max(1,N)
183*> is sufficient, but LWORK typically as large as 6*N may
184*> be required for optimal performance. A workspace query
185*> to determine the optimal workspace size is recommended.
186*>
187*> If LWORK = -1, then DLAQR4 does a workspace query.
188*> In this case, DLAQR4 checks the input parameters and
189*> estimates the optimal workspace size for the given
190*> values of N, ILO and IHI. The estimate is returned
191*> in WORK(1). No error message related to LWORK is
192*> issued by XERBLA. Neither H nor Z are accessed.
193*> \endverbatim
194*>
195*> \param[out] INFO
196*> \verbatim
197*> INFO is INTEGER
198*> = 0: successful exit
199*> > 0: if INFO = i, DLAQR4 failed to compute all of
200*> the eigenvalues. Elements 1:ilo-1 and i+1:n of WR
201*> and WI contain those eigenvalues which have been
202*> successfully computed. (Failures are rare.)
203*>
204*> If INFO > 0 and WANT is .FALSE., then on exit,
205*> the remaining unconverged eigenvalues are the eigen-
206*> values of the upper Hessenberg matrix rows and
207*> columns ILO through INFO of the final, output
208*> value of H.
209*>
210*> If INFO > 0 and WANTT is .TRUE., then on exit
211*>
212*> (*) (initial value of H)*U = U*(final value of H)
213*>
214*> where U is a orthogonal matrix. The final
215*> value of H is upper Hessenberg and triangular in
216*> rows and columns INFO+1 through IHI.
217*>
218*> If INFO > 0 and WANTZ is .TRUE., then on exit
219*>
220*> (final value of Z(ILO:IHI,ILOZ:IHIZ)
221*> = (initial value of Z(ILO:IHI,ILOZ:IHIZ)*U
222*>
223*> where U is the orthogonal matrix in (*) (regard-
224*> less of the value of WANTT.)
225*>
226*> If INFO > 0 and WANTZ is .FALSE., then Z is not
227*> accessed.
228*> \endverbatim
229*
230* Authors:
231* ========
232*
233*> \author Univ. of Tennessee
234*> \author Univ. of California Berkeley
235*> \author Univ. of Colorado Denver
236*> \author NAG Ltd.
237*
238*> \ingroup laqr4
239*
240*> \par Contributors:
241* ==================
242*>
243*> Karen Braman and Ralph Byers, Department of Mathematics,
244*> University of Kansas, USA
245*
246*> \par References:
247* ================
248*>
249*> K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
250*> Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
251*> Performance, SIAM Journal of Matrix Analysis, volume 23, pages
252*> 929--947, 2002.
253*> \n
254*> K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
255*> Algorithm Part II: Aggressive Early Deflation, SIAM Journal
256*> of Matrix Analysis, volume 23, pages 948--973, 2002.
257*>
258* =====================================================================
259 SUBROUTINE dlaqr4( WANTT, WANTZ, N, ILO, IHI, H, LDH, WR, WI,
260 $ ILOZ, IHIZ, Z, LDZ, WORK, LWORK, INFO )
261*
262* -- LAPACK auxiliary routine --
263* -- LAPACK is a software package provided by Univ. of Tennessee, --
264* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
265*
266* .. Scalar Arguments ..
267 INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, LWORK, N
268 LOGICAL WANTT, WANTZ
269* ..
270* .. Array Arguments ..
271 DOUBLE PRECISION H( LDH, * ), WI( * ), WORK( * ), WR( * ),
272 $ z( ldz, * )
273* ..
274*
275* ================================================================
276* .. Parameters ..
277*
278* ==== Matrices of order NTINY or smaller must be processed by
279* . DLAHQR because of insufficient subdiagonal scratch space.
280* . (This is a hard limit.) ====
281 INTEGER NTINY
282 parameter( ntiny = 15 )
283*
284* ==== Exceptional deflation windows: try to cure rare
285* . slow convergence by varying the size of the
286* . deflation window after KEXNW iterations. ====
287 INTEGER KEXNW
288 parameter( kexnw = 5 )
289*
290* ==== Exceptional shifts: try to cure rare slow convergence
291* . with ad-hoc exceptional shifts every KEXSH iterations.
292* . ====
293 INTEGER KEXSH
294 parameter( kexsh = 6 )
295*
296* ==== The constants WILK1 and WILK2 are used to form the
297* . exceptional shifts. ====
298 DOUBLE PRECISION WILK1, WILK2
299 parameter( wilk1 = 0.75d0, wilk2 = -0.4375d0 )
300 DOUBLE PRECISION ZERO, ONE
301 parameter( zero = 0.0d0, one = 1.0d0 )
302* ..
303* .. Local Scalars ..
304 DOUBLE PRECISION AA, BB, CC, CS, DD, SN, SS, SWAP
305 INTEGER I, INF, IT, ITMAX, K, KACC22, KBOT, KDU, KS,
306 $ kt, ktop, ku, kv, kwh, kwtop, kwv, ld, ls,
307 $ lwkopt, ndec, ndfl, nh, nho, nibble, nmin, ns,
308 $ nsmax, nsr, nve, nw, nwmax, nwr, nwupbd
309 LOGICAL SORTED
310 CHARACTER JBCMPZ*2
311* ..
312* .. External Functions ..
313 INTEGER ILAENV
314 EXTERNAL ilaenv
315* ..
316* .. Local Arrays ..
317 DOUBLE PRECISION ZDUM( 1, 1 )
318* ..
319* .. External Subroutines ..
320 EXTERNAL dlacpy, dlahqr, dlanv2, dlaqr2,
321 $ dlaqr5
322* ..
323* .. Intrinsic Functions ..
324 INTRINSIC abs, dble, int, max, min, mod
325* ..
326* .. Executable Statements ..
327 info = 0
328*
329* ==== Quick return for N = 0: nothing to do. ====
330*
331 IF( n.EQ.0 ) THEN
332 work( 1 ) = one
333 RETURN
334 END IF
335*
336 IF( n.LE.ntiny ) THEN
337*
338* ==== Tiny matrices must use DLAHQR. ====
339*
340 lwkopt = 1
341 IF( lwork.NE.-1 )
342 $ CALL dlahqr( wantt, wantz, n, ilo, ihi, h, ldh, wr, wi,
343 $ iloz, ihiz, z, ldz, info )
344 ELSE
345*
346* ==== Use small bulge multi-shift QR with aggressive early
347* . deflation on larger-than-tiny matrices. ====
348*
349* ==== Hope for the best. ====
350*
351 info = 0
352*
353* ==== Set up job flags for ILAENV. ====
354*
355 IF( wantt ) THEN
356 jbcmpz( 1: 1 ) = 'S'
357 ELSE
358 jbcmpz( 1: 1 ) = 'E'
359 END IF
360 IF( wantz ) THEN
361 jbcmpz( 2: 2 ) = 'V'
362 ELSE
363 jbcmpz( 2: 2 ) = 'N'
364 END IF
365*
366* ==== NWR = recommended deflation window size. At this
367* . point, N .GT. NTINY = 15, so there is enough
368* . subdiagonal workspace for NWR.GE.2 as required.
369* . (In fact, there is enough subdiagonal space for
370* . NWR.GE.4.) ====
371*
372 nwr = ilaenv( 13, 'DLAQR4', jbcmpz, n, ilo, ihi, lwork )
373 nwr = max( 2, nwr )
374 nwr = min( ihi-ilo+1, ( n-1 ) / 3, nwr )
375*
376* ==== NSR = recommended number of simultaneous shifts.
377* . At this point N .GT. NTINY = 15, so there is at
378* . enough subdiagonal workspace for NSR to be even
379* . and greater than or equal to two as required. ====
380*
381 nsr = ilaenv( 15, 'DLAQR4', jbcmpz, n, ilo, ihi, lwork )
382 nsr = min( nsr, ( n-3 ) / 6, ihi-ilo )
383 nsr = max( 2, nsr-mod( nsr, 2 ) )
384*
385* ==== Estimate optimal workspace ====
386*
387* ==== Workspace query call to DLAQR2 ====
388*
389 CALL dlaqr2( wantt, wantz, n, ilo, ihi, nwr+1, h, ldh, iloz,
390 $ ihiz, z, ldz, ls, ld, wr, wi, h, ldh, n, h, ldh,
391 $ n, h, ldh, work, -1 )
392*
393* ==== Optimal workspace = MAX(DLAQR5, DLAQR2) ====
394*
395 lwkopt = max( 3*nsr / 2, int( work( 1 ) ) )
396*
397* ==== Quick return in case of workspace query. ====
398*
399 IF( lwork.EQ.-1 ) THEN
400 work( 1 ) = dble( lwkopt )
401 RETURN
402 END IF
403*
404* ==== DLAHQR/DLAQR0 crossover point ====
405*
406 nmin = ilaenv( 12, 'DLAQR4', jbcmpz, n, ilo, ihi, lwork )
407 nmin = max( ntiny, nmin )
408*
409* ==== Nibble crossover point ====
410*
411 nibble = ilaenv( 14, 'DLAQR4', jbcmpz, n, ilo, ihi, lwork )
412 nibble = max( 0, nibble )
413*
414* ==== Accumulate reflections during ttswp? Use block
415* . 2-by-2 structure during matrix-matrix multiply? ====
416*
417 kacc22 = ilaenv( 16, 'DLAQR4', jbcmpz, n, ilo, ihi, lwork )
418 kacc22 = max( 0, kacc22 )
419 kacc22 = min( 2, kacc22 )
420*
421* ==== NWMAX = the largest possible deflation window for
422* . which there is sufficient workspace. ====
423*
424 nwmax = min( ( n-1 ) / 3, lwork / 2 )
425 nw = nwmax
426*
427* ==== NSMAX = the Largest number of simultaneous shifts
428* . for which there is sufficient workspace. ====
429*
430 nsmax = min( ( n-3 ) / 6, 2*lwork / 3 )
431 nsmax = nsmax - mod( nsmax, 2 )
432*
433* ==== NDFL: an iteration count restarted at deflation. ====
434*
435 ndfl = 1
436*
437* ==== ITMAX = iteration limit ====
438*
439 itmax = max( 30, 2*kexsh )*max( 10, ( ihi-ilo+1 ) )
440*
441* ==== Last row and column in the active block ====
442*
443 kbot = ihi
444*
445* ==== Main Loop ====
446*
447 DO 80 it = 1, itmax
448*
449* ==== Done when KBOT falls below ILO ====
450*
451 IF( kbot.LT.ilo )
452 $ GO TO 90
453*
454* ==== Locate active block ====
455*
456 DO 10 k = kbot, ilo + 1, -1
457 IF( h( k, k-1 ).EQ.zero )
458 $ GO TO 20
459 10 CONTINUE
460 k = ilo
461 20 CONTINUE
462 ktop = k
463*
464* ==== Select deflation window size:
465* . Typical Case:
466* . If possible and advisable, nibble the entire
467* . active block. If not, use size MIN(NWR,NWMAX)
468* . or MIN(NWR+1,NWMAX) depending upon which has
469* . the smaller corresponding subdiagonal entry
470* . (a heuristic).
471* .
472* . Exceptional Case:
473* . If there have been no deflations in KEXNW or
474* . more iterations, then vary the deflation window
475* . size. At first, because, larger windows are,
476* . in general, more powerful than smaller ones,
477* . rapidly increase the window to the maximum possible.
478* . Then, gradually reduce the window size. ====
479*
480 nh = kbot - ktop + 1
481 nwupbd = min( nh, nwmax )
482 IF( ndfl.LT.kexnw ) THEN
483 nw = min( nwupbd, nwr )
484 ELSE
485 nw = min( nwupbd, 2*nw )
486 END IF
487 IF( nw.LT.nwmax ) THEN
488 IF( nw.GE.nh-1 ) THEN
489 nw = nh
490 ELSE
491 kwtop = kbot - nw + 1
492 IF( abs( h( kwtop, kwtop-1 ) ).GT.
493 $ abs( h( kwtop-1, kwtop-2 ) ) )nw = nw + 1
494 END IF
495 END IF
496 IF( ndfl.LT.kexnw ) THEN
497 ndec = -1
498 ELSE IF( ndec.GE.0 .OR. nw.GE.nwupbd ) THEN
499 ndec = ndec + 1
500 IF( nw-ndec.LT.2 )
501 $ ndec = 0
502 nw = nw - ndec
503 END IF
504*
505* ==== Aggressive early deflation:
506* . split workspace under the subdiagonal into
507* . - an nw-by-nw work array V in the lower
508* . left-hand-corner,
509* . - an NW-by-at-least-NW-but-more-is-better
510* . (NW-by-NHO) horizontal work array along
511* . the bottom edge,
512* . - an at-least-NW-but-more-is-better (NHV-by-NW)
513* . vertical work array along the left-hand-edge.
514* . ====
515*
516 kv = n - nw + 1
517 kt = nw + 1
518 nho = ( n-nw-1 ) - kt + 1
519 kwv = nw + 2
520 nve = ( n-nw ) - kwv + 1
521*
522* ==== Aggressive early deflation ====
523*
524 CALL dlaqr2( wantt, wantz, n, ktop, kbot, nw, h, ldh,
525 $ iloz,
526 $ ihiz, z, ldz, ls, ld, wr, wi, h( kv, 1 ), ldh,
527 $ nho, h( kv, kt ), ldh, nve, h( kwv, 1 ), ldh,
528 $ work, lwork )
529*
530* ==== Adjust KBOT accounting for new deflations. ====
531*
532 kbot = kbot - ld
533*
534* ==== KS points to the shifts. ====
535*
536 ks = kbot - ls + 1
537*
538* ==== Skip an expensive QR sweep if there is a (partly
539* . heuristic) reason to expect that many eigenvalues
540* . will deflate without it. Here, the QR sweep is
541* . skipped if many eigenvalues have just been deflated
542* . or if the remaining active block is small.
543*
544 IF( ( ld.EQ.0 ) .OR. ( ( 100*ld.LE.nw*nibble ) .AND. ( kbot-
545 $ ktop+1.GT.min( nmin, nwmax ) ) ) ) THEN
546*
547* ==== NS = nominal number of simultaneous shifts.
548* . This may be lowered (slightly) if DLAQR2
549* . did not provide that many shifts. ====
550*
551 ns = min( nsmax, nsr, max( 2, kbot-ktop ) )
552 ns = ns - mod( ns, 2 )
553*
554* ==== If there have been no deflations
555* . in a multiple of KEXSH iterations,
556* . then try exceptional shifts.
557* . Otherwise use shifts provided by
558* . DLAQR2 above or from the eigenvalues
559* . of a trailing principal submatrix. ====
560*
561 IF( mod( ndfl, kexsh ).EQ.0 ) THEN
562 ks = kbot - ns + 1
563 DO 30 i = kbot, max( ks+1, ktop+2 ), -2
564 ss = abs( h( i, i-1 ) ) + abs( h( i-1, i-2 ) )
565 aa = wilk1*ss + h( i, i )
566 bb = ss
567 cc = wilk2*ss
568 dd = aa
569 CALL dlanv2( aa, bb, cc, dd, wr( i-1 ),
570 $ wi( i-1 ),
571 $ wr( i ), wi( i ), cs, sn )
572 30 CONTINUE
573 IF( ks.EQ.ktop ) THEN
574 wr( ks+1 ) = h( ks+1, ks+1 )
575 wi( ks+1 ) = zero
576 wr( ks ) = wr( ks+1 )
577 wi( ks ) = wi( ks+1 )
578 END IF
579 ELSE
580*
581* ==== Got NS/2 or fewer shifts? Use DLAHQR
582* . on a trailing principal submatrix to
583* . get more. (Since NS.LE.NSMAX.LE.(N-3)/6,
584* . there is enough space below the subdiagonal
585* . to fit an NS-by-NS scratch array.) ====
586*
587 IF( kbot-ks+1.LE.ns / 2 ) THEN
588 ks = kbot - ns + 1
589 kt = n - ns + 1
590 CALL dlacpy( 'A', ns, ns, h( ks, ks ), ldh,
591 $ h( kt, 1 ), ldh )
592 CALL dlahqr( .false., .false., ns, 1, ns,
593 $ h( kt, 1 ), ldh, wr( ks ), wi( ks ),
594 $ 1, 1, zdum, 1, inf )
595 ks = ks + inf
596*
597* ==== In case of a rare QR failure use
598* . eigenvalues of the trailing 2-by-2
599* . principal submatrix. ====
600*
601 IF( ks.GE.kbot ) THEN
602 aa = h( kbot-1, kbot-1 )
603 cc = h( kbot, kbot-1 )
604 bb = h( kbot-1, kbot )
605 dd = h( kbot, kbot )
606 CALL dlanv2( aa, bb, cc, dd, wr( kbot-1 ),
607 $ wi( kbot-1 ), wr( kbot ),
608 $ wi( kbot ), cs, sn )
609 ks = kbot - 1
610 END IF
611 END IF
612*
613 IF( kbot-ks+1.GT.ns ) THEN
614*
615* ==== Sort the shifts (Helps a little)
616* . Bubble sort keeps complex conjugate
617* . pairs together. ====
618*
619 sorted = .false.
620 DO 50 k = kbot, ks + 1, -1
621 IF( sorted )
622 $ GO TO 60
623 sorted = .true.
624 DO 40 i = ks, k - 1
625 IF( abs( wr( i ) )+abs( wi( i ) ).LT.
626 $ abs( wr( i+1 ) )+abs( wi( i+1 ) ) ) THEN
627 sorted = .false.
628*
629 swap = wr( i )
630 wr( i ) = wr( i+1 )
631 wr( i+1 ) = swap
632*
633 swap = wi( i )
634 wi( i ) = wi( i+1 )
635 wi( i+1 ) = swap
636 END IF
637 40 CONTINUE
638 50 CONTINUE
639 60 CONTINUE
640 END IF
641*
642* ==== Shuffle shifts into pairs of real shifts
643* . and pairs of complex conjugate shifts
644* . assuming complex conjugate shifts are
645* . already adjacent to one another. (Yes,
646* . they are.) ====
647*
648 DO 70 i = kbot, ks + 2, -2
649 IF( wi( i ).NE.-wi( i-1 ) ) THEN
650*
651 swap = wr( i )
652 wr( i ) = wr( i-1 )
653 wr( i-1 ) = wr( i-2 )
654 wr( i-2 ) = swap
655*
656 swap = wi( i )
657 wi( i ) = wi( i-1 )
658 wi( i-1 ) = wi( i-2 )
659 wi( i-2 ) = swap
660 END IF
661 70 CONTINUE
662 END IF
663*
664* ==== If there are only two shifts and both are
665* . real, then use only one. ====
666*
667 IF( kbot-ks+1.EQ.2 ) THEN
668 IF( wi( kbot ).EQ.zero ) THEN
669 IF( abs( wr( kbot )-h( kbot, kbot ) ).LT.
670 $ abs( wr( kbot-1 )-h( kbot, kbot ) ) ) THEN
671 wr( kbot-1 ) = wr( kbot )
672 ELSE
673 wr( kbot ) = wr( kbot-1 )
674 END IF
675 END IF
676 END IF
677*
678* ==== Use up to NS of the the smallest magnitude
679* . shifts. If there aren't NS shifts available,
680* . then use them all, possibly dropping one to
681* . make the number of shifts even. ====
682*
683 ns = min( ns, kbot-ks+1 )
684 ns = ns - mod( ns, 2 )
685 ks = kbot - ns + 1
686*
687* ==== Small-bulge multi-shift QR sweep:
688* . split workspace under the subdiagonal into
689* . - a KDU-by-KDU work array U in the lower
690* . left-hand-corner,
691* . - a KDU-by-at-least-KDU-but-more-is-better
692* . (KDU-by-NHo) horizontal work array WH along
693* . the bottom edge,
694* . - and an at-least-KDU-but-more-is-better-by-KDU
695* . (NVE-by-KDU) vertical work WV arrow along
696* . the left-hand-edge. ====
697*
698 kdu = 2*ns
699 ku = n - kdu + 1
700 kwh = kdu + 1
701 nho = ( n-kdu+1-4 ) - ( kdu+1 ) + 1
702 kwv = kdu + 4
703 nve = n - kdu - kwv + 1
704*
705* ==== Small-bulge multi-shift QR sweep ====
706*
707 CALL dlaqr5( wantt, wantz, kacc22, n, ktop, kbot, ns,
708 $ wr( ks ), wi( ks ), h, ldh, iloz, ihiz, z,
709 $ ldz, work, 3, h( ku, 1 ), ldh, nve,
710 $ h( kwv, 1 ), ldh, nho, h( ku, kwh ), ldh )
711 END IF
712*
713* ==== Note progress (or the lack of it). ====
714*
715 IF( ld.GT.0 ) THEN
716 ndfl = 1
717 ELSE
718 ndfl = ndfl + 1
719 END IF
720*
721* ==== End of main loop ====
722 80 CONTINUE
723*
724* ==== Iteration limit exceeded. Set INFO to show where
725* . the problem occurred and exit. ====
726*
727 info = kbot
728 90 CONTINUE
729 END IF
730*
731* ==== Return the optimal value of LWORK. ====
732*
733 work( 1 ) = dble( lwkopt )
734*
735* ==== End of DLAQR4 ====
736*
737 END
subroutine dlacpy(uplo, m, n, a, lda, b, ldb)
DLACPY copies all or part of one two-dimensional array to another.
Definition dlacpy.f:101
subroutine dlahqr(wantt, wantz, n, ilo, ihi, h, ldh, wr, wi, iloz, ihiz, z, ldz, info)
DLAHQR computes the eigenvalues and Schur factorization of an upper Hessenberg matrix,...
Definition dlahqr.f:205
subroutine dlanv2(a, b, c, d, rt1r, rt1i, rt2r, rt2i, cs, sn)
DLANV2 computes the Schur factorization of a real 2-by-2 nonsymmetric matrix in standard form.
Definition dlanv2.f:125
subroutine dlaqr2(wantt, wantz, n, ktop, kbot, nw, h, ldh, iloz, ihiz, z, ldz, ns, nd, sr, si, v, ldv, nh, t, ldt, nv, wv, ldwv, work, lwork)
DLAQR2 performs the orthogonal similarity transformation of a Hessenberg matrix to detect and deflate...
Definition dlaqr2.f:277
subroutine dlaqr4(wantt, wantz, n, ilo, ihi, h, ldh, wr, wi, iloz, ihiz, z, ldz, work, lwork, info)
DLAQR4 computes the eigenvalues of a Hessenberg matrix, and optionally the matrices from the Schur de...
Definition dlaqr4.f:261
subroutine dlaqr5(wantt, wantz, kacc22, n, ktop, kbot, nshfts, sr, si, h, ldh, iloz, ihiz, z, ldz, v, ldv, u, ldu, nv, wv, ldwv, nh, wh, ldwh)
DLAQR5 performs a single small-bulge multi-shift QR sweep.
Definition dlaqr5.f:263