Debian Codegraph @

debian/external_deps/fetk/punc/src/arpack/dlaqrb.c

raw
1 /* ./src_f77/dlaqrb.f -- translated by f2c (version 20030320).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include <punc/vf2c.h>
7
8 /* Table of constant values */
9
10 static integer c__1 = 1;
11
12 /* ----------------------------------------------------------------------- */
13 /* \BeginDoc */
14
15 /* \Name: dlaqrb */
16
17 /* \Description: */
18 /* Compute the eigenvalues and the Schur decomposition of an upper */
19 /* Hessenberg submatrix in rows and columns ILO to IHI. Only the */
20 /* last component of the Schur vectors are computed. */
21
22 /* This is mostly a modification of the LAPACK routine dlahqr. */
23
24 /* \Usage: */
25 /* call dlaqrb */
26 /* ( WANTT, N, ILO, IHI, H, LDH, WR, WI, Z, INFO ) */
27
28 /* \Arguments */
29 /* WANTT Logical variable. (INPUT) */
30 /* = .TRUE. : the full Schur form T is required; */
31 /* = .FALSE.: only eigenvalues are required. */
32
33 /* N Integer. (INPUT) */
34 /* The order of the matrix H. N >= 0. */
35
36 /* ILO Integer. (INPUT) */
37 /* IHI Integer. (INPUT) */
38 /* It is assumed that H is already upper quasi-triangular in */
39 /* rows and columns IHI+1:N, and that H(ILO,ILO-1) = 0 (unless */
40 /* ILO = 1). SLAQRB works primarily with the Hessenberg */
41 /* submatrix in rows and columns ILO to IHI, but applies */
42 /* transformations to all of H if WANTT is .TRUE.. */
43 /* 1 <= ILO <= max(1,IHI); IHI <= N. */
44
45 /* H Double precision array, dimension (LDH,N). (INPUT/OUTPUT) */
46 /* On entry, the upper Hessenberg matrix H. */
47 /* On exit, if WANTT is .TRUE., H is upper quasi-triangular in */
48 /* rows and columns ILO:IHI, with any 2-by-2 diagonal blocks in */
49 /* standard form. If WANTT is .FALSE., the contents of H are */
50 /* unspecified on exit. */
51
52 /* LDH Integer. (INPUT) */
53 /* The leading dimension of the array H. LDH >= max(1,N). */
54
55 /* WR Double precision array, dimension (N). (OUTPUT) */
56 /* WI Double precision array, dimension (N). (OUTPUT) */
57 /* The real and imaginary parts, respectively, of the computed */
58 /* eigenvalues ILO to IHI are stored in the corresponding */
59 /* elements of WR and WI. If two eigenvalues are computed as a */
60 /* complex conjugate pair, they are stored in consecutive */
61 /* elements of WR and WI, say the i-th and (i+1)th, with */
62 /* WI(i) > 0 and WI(i+1) < 0. If WANTT is .TRUE., the */
63 /* eigenvalues are stored in the same order as on the diagonal */
64 /* of the Schur form returned in H, with WR(i) = H(i,i), and, if */
65 /* H(i:i+1,i:i+1) is a 2-by-2 diagonal block, */
66 /* WI(i) = sqrt(H(i+1,i)*H(i,i+1)) and WI(i+1) = -WI(i). */
67
68 /* Z Double precision array, dimension (N). (OUTPUT) */
69 /* On exit Z contains the last components of the Schur vectors. */
70
71 /* INFO Integer. (OUPUT) */
72 /* = 0: successful exit */
73 /* > 0: SLAQRB failed to compute all the eigenvalues ILO to IHI */
74 /* in a total of 30*(IHI-ILO+1) iterations; if INFO = i, */
75 /* elements i+1:ihi of WR and WI contain those eigenvalues */
76 /* which have been successfully computed. */
77
78 /* \Remarks */
79 /* 1. None. */
80
81 /* ----------------------------------------------------------------------- */
82
83 /* \BeginLib */
84
85 /* \Local variables: */
86 /* xxxxxx real */
87
88 /* \Routines called: */
89 /* dlabad LAPACK routine that computes machine constants. */
90 /* dlamch LAPACK routine that determines machine constants. */
91 /* dlanhs LAPACK routine that computes various norms of a matrix. */
92 /* dlanv2 LAPACK routine that computes the Schur factorization of */
93 /* 2 by 2 nonsymmetric matrix in standard form. */
94 /* dlarfg LAPACK Householder reflection construction routine. */
95 /* dcopy Level 1 BLAS that copies one vector to another. */
96 /* drot Level 1 BLAS that applies a rotation to a 2 by 2 matrix. */
97
98 /* \Author */
99 /* Danny Sorensen Phuong Vu */
100 /* Richard Lehoucq CRPC / Rice University */
101 /* Dept. of Computational & Houston, Texas */
102 /* Applied Mathematics */
103 /* Rice University */
104 /* Houston, Texas */
105
106 /* \Revision history: */
107 /* xx/xx/92: Version ' 2.4' */
108 /* Modified from the LAPACK routine dlahqr so that only the */
109 /* last component of the Schur vectors are computed. */
110
111 /* \SCCS Information: @(#) */
112 /* FILE: laqrb.F SID: 2.2 DATE OF SID: 8/27/96 RELEASE: 2 */
113
114 /* \Remarks */
115 /* 1. None */
116
117 /* \EndLib */
118
119 /* ----------------------------------------------------------------------- */
120
121 /* Subroutine */ int dlaqrb_(logical *wantt, integer *n, integer *ilo,
122 integer *ihi, doublereal *h__, integer *ldh, doublereal *wr,
123 doublereal *wi, doublereal *z__, integer *info)
124 {
125 /* System generated locals */
126 integer h_dim1, h_offset, i__1, i__2, i__3, i__4;
127 doublereal d__1, d__2;
128
129 /* Local variables */
130 static integer i__, j, k, l, m;
131 static doublereal s, v[3];
132 static integer i1, i2;
133 static doublereal t1, t2, t3, v1, v2, v3, h00, h10, h11, h12, h21, h22,
134 h33, h44;
135 static integer nh;
136 static doublereal cs;
137 static integer nr;
138 static doublereal sn, h33s, h44s;
139 static integer itn, its;
140 static doublereal ulp, sum, tst1, h43h34, unfl, ovfl;
141 extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
142 doublereal *, integer *, doublereal *, doublereal *);
143 static doublereal work[1];
144 extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
145 doublereal *, integer *), dlanv2_(doublereal *, doublereal *,
146 doublereal *, doublereal *, doublereal *, doublereal *,
147 doublereal *, doublereal *, doublereal *, doublereal *), dlabad_(
148 doublereal *, doublereal *);
149 extern doublereal dlamch_(char *, ftnlen);
150 extern /* Subroutine */ int dlarfg_(integer *, doublereal *, doublereal *,
151 integer *, doublereal *);
152 extern doublereal dlanhs_(char *, integer *, doublereal *, integer *,
153 doublereal *, ftnlen);
154 static doublereal smlnum;
155
156
157 /* %------------------% */
158 /* | Scalar Arguments | */
159 /* %------------------% */
160
161
162 /* %-----------------% */
163 /* | Array Arguments | */
164 /* %-----------------% */
165
166
167 /* %------------% */
168 /* | Parameters | */
169 /* %------------% */
170
171
172 /* %------------------------% */
173 /* | Local Scalars & Arrays | */
174 /* %------------------------% */
175
176
177 /* %--------------------% */
178 /* | External Functions | */
179 /* %--------------------% */
180
181
182 /* %----------------------% */
183 /* | External Subroutines | */
184 /* %----------------------% */
185
186
187 /* %-----------------------% */
188 /* | Executable Statements | */
189 /* %-----------------------% */
190
191 /* Parameter adjustments */
192 h_dim1 = *ldh;
193 h_offset = 1 + h_dim1;
194 h__ -= h_offset;
195 --wr;
196 --wi;
197 --z__;
198
199 /* Function Body */
200 *info = 0;
201
202 /* %--------------------------% */
203 /* | Quick return if possible | */
204 /* %--------------------------% */
205
206 if (*n == 0) {
207 return 0;
208 }
209 if (*ilo == *ihi) {
210 wr[*ilo] = h__[*ilo + *ilo * h_dim1];
211 wi[*ilo] = 0.;
212 return 0;
213 }
214
215 /* %---------------------------------------------% */
216 /* | Initialize the vector of last components of | */
217 /* | the Schur vectors for accumulation. | */
218 /* %---------------------------------------------% */
219
220 i__1 = *n - 1;
221 for (j = 1; j <= i__1; ++j) {
222 z__[j] = 0.;
223 /* L5: */
224 }
225 z__[*n] = 1.;
226
227 nh = *ihi - *ilo + 1;
228
229 /* %-------------------------------------------------------------% */
230 /* | Set machine-dependent constants for the stopping criterion. | */
231 /* | If norm(H) <= sqrt(OVFL), overflow should not occur. | */
232 /* %-------------------------------------------------------------% */
233
234 unfl = dlamch_("safe minimum", (ftnlen)12);
235 ovfl = 1. / unfl;
236 dlabad_(&unfl, &ovfl);
237 ulp = dlamch_("precision", (ftnlen)9);
238 smlnum = unfl * (nh / ulp);
239
240 /* %---------------------------------------------------------------% */
241 /* | I1 and I2 are the indices of the first row and last column | */
242 /* | of H to which transformations must be applied. If eigenvalues | */
243 /* | only are computed, I1 and I2 are set inside the main loop. | */
244 /* | Zero out H(J+2,J) = ZERO for J=1:N if WANTT = .TRUE. | */
245 /* | else H(J+2,J) for J=ILO:IHI-ILO-1 if WANTT = .FALSE. | */
246 /* %---------------------------------------------------------------% */
247
248 if (*wantt) {
249 i1 = 1;
250 i2 = *n;
251 i__1 = i2 - 2;
252 for (i__ = 1; i__ <= i__1; ++i__) {
253 h__[i1 + i__ + 1 + i__ * h_dim1] = 0.;
254 /* L8: */
255 }
256 } else {
257 i__1 = *ihi - *ilo - 1;
258 for (i__ = 1; i__ <= i__1; ++i__) {
259 h__[*ilo + i__ + 1 + (*ilo + i__ - 1) * h_dim1] = 0.;
260 /* L9: */
261 }
262 }
263
264 /* %---------------------------------------------------% */
265 /* | ITN is the total number of QR iterations allowed. | */
266 /* %---------------------------------------------------% */
267
268 itn = nh * 30;
269
270 /* ------------------------------------------------------------------ */
271 /* The main loop begins here. I is the loop index and decreases from */
272 /* IHI to ILO in steps of 1 or 2. Each iteration of the loop works */
273 /* with the active submatrix in rows and columns L to I. */
274 /* Eigenvalues I+1 to IHI have already converged. Either L = ILO or */
275 /* H(L,L-1) is negligible so that the matrix splits. */
276 /* ------------------------------------------------------------------ */
277
278 i__ = *ihi;
279 L10:
280 l = *ilo;
281 if (i__ < *ilo) {
282 goto L150;
283 }
284 /* %--------------------------------------------------------------% */
285 /* | Perform QR iterations on rows and columns ILO to I until a | */
286 /* | submatrix of order 1 or 2 splits off at the bottom because a | */
287 /* | subdiagonal element has become negligible. | */
288 /* %--------------------------------------------------------------% */
289 i__1 = itn;
290 for (its = 0; its <= i__1; ++its) {
291
292 /* %----------------------------------------------% */
293 /* | Look for a single small subdiagonal element. | */
294 /* %----------------------------------------------% */
295
296 i__2 = l + 1;
297 for (k = i__; k >= i__2; --k) {
298 tst1 = (d__1 = h__[k - 1 + (k - 1) * h_dim1], abs(d__1)) + (d__2 =
299 h__[k + k * h_dim1], abs(d__2));
300 if (tst1 == 0.) {
301 i__3 = i__ - l + 1;
302 tst1 = dlanhs_("1", &i__3, &h__[l + l * h_dim1], ldh, work, (
303 ftnlen)1);
304 }
305 /* Computing MAX */
306 d__2 = ulp * tst1;
307 if ((d__1 = h__[k + (k - 1) * h_dim1], abs(d__1)) <= max(d__2,
308 smlnum)) {
309 goto L30;
310 }
311 /* L20: */
312 }
313 L30:
314 l = k;
315 if (l > *ilo) {
316
317 /* %------------------------% */
318 /* | H(L,L-1) is negligible | */
319 /* %------------------------% */
320
321 h__[l + (l - 1) * h_dim1] = 0.;
322 }
323
324 /* %-------------------------------------------------------------% */
325 /* | Exit from loop if a submatrix of order 1 or 2 has split off | */
326 /* %-------------------------------------------------------------% */
327
328 if (l >= i__ - 1) {
329 goto L140;
330 }
331
332 /* %---------------------------------------------------------% */
333 /* | Now the active submatrix is in rows and columns L to I. | */
334 /* | If eigenvalues only are being computed, only the active | */
335 /* | submatrix need be transformed. | */
336 /* %---------------------------------------------------------% */
337
338 if (! (*wantt)) {
339 i1 = l;
340 i2 = i__;
341 }
342
343 if (its == 10 || its == 20) {
344
345 /* %-------------------% */
346 /* | Exceptional shift | */
347 /* %-------------------% */
348
349 s = (d__1 = h__[i__ + (i__ - 1) * h_dim1], abs(d__1)) + (d__2 =
350 h__[i__ - 1 + (i__ - 2) * h_dim1], abs(d__2));
351 h44 = s * .75;
352 h33 = h44;
353 h43h34 = s * -.4375 * s;
354
355 } else {
356
357 /* %-----------------------------------------% */
358 /* | Prepare to use Wilkinson's double shift | */
359 /* %-----------------------------------------% */
360
361 h44 = h__[i__ + i__ * h_dim1];
362 h33 = h__[i__ - 1 + (i__ - 1) * h_dim1];
363 h43h34 = h__[i__ + (i__ - 1) * h_dim1] * h__[i__ - 1 + i__ *
364 h_dim1];
365 }
366
367 /* %-----------------------------------------------------% */
368 /* | Look for two consecutive small subdiagonal elements | */
369 /* %-----------------------------------------------------% */
370
371 i__2 = l;
372 for (m = i__ - 2; m >= i__2; --m) {
373
374 /* %---------------------------------------------------------% */
375 /* | Determine the effect of starting the double-shift QR | */
376 /* | iteration at row M, and see if this would make H(M,M-1) | */
377 /* | negligible. | */
378 /* %---------------------------------------------------------% */
379
380 h11 = h__[m + m * h_dim1];
381 h22 = h__[m + 1 + (m + 1) * h_dim1];
382 h21 = h__[m + 1 + m * h_dim1];
383 h12 = h__[m + (m + 1) * h_dim1];
384 h44s = h44 - h11;
385 h33s = h33 - h11;
386 v1 = (h33s * h44s - h43h34) / h21 + h12;
387 v2 = h22 - h11 - h33s - h44s;
388 v3 = h__[m + 2 + (m + 1) * h_dim1];
389 s = abs(v1) + abs(v2) + abs(v3);
390 v1 /= s;
391 v2 /= s;
392 v3 /= s;
393 v[0] = v1;
394 v[1] = v2;
395 v[2] = v3;
396 if (m == l) {
397 goto L50;
398 }
399 h00 = h__[m - 1 + (m - 1) * h_dim1];
400 h10 = h__[m + (m - 1) * h_dim1];
401 tst1 = abs(v1) * (abs(h00) + abs(h11) + abs(h22));
402 if (abs(h10) * (abs(v2) + abs(v3)) <= ulp * tst1) {
403 goto L50;
404 }
405 /* L40: */
406 }
407 L50:
408
409 /* %----------------------% */
410 /* | Double-shift QR step | */
411 /* %----------------------% */
412
413 i__2 = i__ - 1;
414 for (k = m; k <= i__2; ++k) {
415
416 /* ------------------------------------------------------------ */
417 /* The first iteration of this loop determines a reflection G */
418 /* from the vector V and applies it from left and right to H, */
419 /* thus creating a nonzero bulge below the subdiagonal. */
420
421 /* Each subsequent iteration determines a reflection G to */
422 /* restore the Hessenberg form in the (K-1)th column, and thus */
423 /* chases the bulge one step toward the bottom of the active */
424 /* submatrix. NR is the order of G. */
425 /* ------------------------------------------------------------ */
426
427 /* Computing MIN */
428 i__3 = 3, i__4 = i__ - k + 1;
429 nr = min(i__3,i__4);
430 if (k > m) {
431 dcopy_(&nr, &h__[k + (k - 1) * h_dim1], &c__1, v, &c__1);
432 }
433 dlarfg_(&nr, v, &v[1], &c__1, &t1);
434 if (k > m) {
435 h__[k + (k - 1) * h_dim1] = v[0];
436 h__[k + 1 + (k - 1) * h_dim1] = 0.;
437 if (k < i__ - 1) {
438 h__[k + 2 + (k - 1) * h_dim1] = 0.;
439 }
440 } else if (m > l) {
441 h__[k + (k - 1) * h_dim1] = -h__[k + (k - 1) * h_dim1];
442 }
443 v2 = v[1];
444 t2 = t1 * v2;
445 if (nr == 3) {
446 v3 = v[2];
447 t3 = t1 * v3;
448
449 /* %------------------------------------------------% */
450 /* | Apply G from the left to transform the rows of | */
451 /* | the matrix in columns K to I2. | */
452 /* %------------------------------------------------% */
453
454 i__3 = i2;
455 for (j = k; j <= i__3; ++j) {
456 sum = h__[k + j * h_dim1] + v2 * h__[k + 1 + j * h_dim1]
457 + v3 * h__[k + 2 + j * h_dim1];
458 h__[k + j * h_dim1] -= sum * t1;
459 h__[k + 1 + j * h_dim1] -= sum * t2;
460 h__[k + 2 + j * h_dim1] -= sum * t3;
461 /* L60: */
462 }
463
464 /* %----------------------------------------------------% */
465 /* | Apply G from the right to transform the columns of | */
466 /* | the matrix in rows I1 to min(K+3,I). | */
467 /* %----------------------------------------------------% */
468
469 /* Computing MIN */
470 i__4 = k + 3;
471 i__3 = min(i__4,i__);
472 for (j = i1; j <= i__3; ++j) {
473 sum = h__[j + k * h_dim1] + v2 * h__[j + (k + 1) * h_dim1]
474 + v3 * h__[j + (k + 2) * h_dim1];
475 h__[j + k * h_dim1] -= sum * t1;
476 h__[j + (k + 1) * h_dim1] -= sum * t2;
477 h__[j + (k + 2) * h_dim1] -= sum * t3;
478 /* L70: */
479 }
480
481 /* %----------------------------------% */
482 /* | Accumulate transformations for Z | */
483 /* %----------------------------------% */
484
485 sum = z__[k] + v2 * z__[k + 1] + v3 * z__[k + 2];
486 z__[k] -= sum * t1;
487 z__[k + 1] -= sum * t2;
488 z__[k + 2] -= sum * t3;
489 } else if (nr == 2) {
490
491 /* %------------------------------------------------% */
492 /* | Apply G from the left to transform the rows of | */
493 /* | the matrix in columns K to I2. | */
494 /* %------------------------------------------------% */
495
496 i__3 = i2;
497 for (j = k; j <= i__3; ++j) {
498 sum = h__[k + j * h_dim1] + v2 * h__[k + 1 + j * h_dim1];
499 h__[k + j * h_dim1] -= sum * t1;
500 h__[k + 1 + j * h_dim1] -= sum * t2;
501 /* L90: */
502 }
503
504 /* %----------------------------------------------------% */
505 /* | Apply G from the right to transform the columns of | */
506 /* | the matrix in rows I1 to min(K+3,I). | */
507 /* %----------------------------------------------------% */
508
509 i__3 = i__;
510 for (j = i1; j <= i__3; ++j) {
511 sum = h__[j + k * h_dim1] + v2 * h__[j + (k + 1) * h_dim1]
512 ;
513 h__[j + k * h_dim1] -= sum * t1;
514 h__[j + (k + 1) * h_dim1] -= sum * t2;
515 /* L100: */
516 }
517
518 /* %----------------------------------% */
519 /* | Accumulate transformations for Z | */
520 /* %----------------------------------% */
521
522 sum = z__[k] + v2 * z__[k + 1];
523 z__[k] -= sum * t1;
524 z__[k + 1] -= sum * t2;
525 }
526 /* L120: */
527 }
528 /* L130: */
529 }
530
531 /* %-------------------------------------------------------% */
532 /* | Failure to converge in remaining number of iterations | */
533 /* %-------------------------------------------------------% */
534
535 *info = i__;
536 return 0;
537 L140:
538 if (l == i__) {
539
540 /* %------------------------------------------------------% */
541 /* | H(I,I-1) is negligible: one eigenvalue has converged | */
542 /* %------------------------------------------------------% */
543
544 wr[i__] = h__[i__ + i__ * h_dim1];
545 wi[i__] = 0.;
546 } else if (l == i__ - 1) {
547
548 /* %--------------------------------------------------------% */
549 /* | H(I-1,I-2) is negligible; | */
550 /* | a pair of eigenvalues have converged. | */
551 /* | | */
552 /* | Transform the 2-by-2 submatrix to standard Schur form, | */
553 /* | and compute and store the eigenvalues. | */
554 /* %--------------------------------------------------------% */
555
556 dlanv2_(&h__[i__ - 1 + (i__ - 1) * h_dim1], &h__[i__ - 1 + i__ *
557 h_dim1], &h__[i__ + (i__ - 1) * h_dim1], &h__[i__ + i__ *
558 h_dim1], &wr[i__ - 1], &wi[i__ - 1], &wr[i__], &wi[i__], &cs,
559 &sn);
560 if (*wantt) {
561
562 /* %-----------------------------------------------------% */
563 /* | Apply the transformation to the rest of H and to Z, | */
564 /* | as required. | */
565 /* %-----------------------------------------------------% */
566
567 if (i2 > i__) {
568 i__1 = i2 - i__;
569 drot_(&i__1, &h__[i__ - 1 + (i__ + 1) * h_dim1], ldh, &h__[
570 i__ + (i__ + 1) * h_dim1], ldh, &cs, &sn);
571 }
572 i__1 = i__ - i1 - 1;
573 drot_(&i__1, &h__[i1 + (i__ - 1) * h_dim1], &c__1, &h__[i1 + i__ *
574 h_dim1], &c__1, &cs, &sn);
575 sum = cs * z__[i__ - 1] + sn * z__[i__];
576 z__[i__] = cs * z__[i__] - sn * z__[i__ - 1];
577 z__[i__ - 1] = sum;
578 }
579 }
580
581 /* %---------------------------------------------------------% */
582 /* | Decrement number of remaining iterations, and return to | */
583 /* | start of the main loop with new value of I. | */
584 /* %---------------------------------------------------------% */
585
586 itn -= its;
587 i__ = l - 1;
588 goto L10;
589 L150:
590 return 0;
591
592 /* %---------------% */
593 /* | End of dlaqrb | */
594 /* %---------------% */
595
596 } /* dlaqrb_ */
597