3 /* Table of constant values */
5 static integer c__1 = 1;
6 static integer c__2 = 2;
7 static integer c__10 = 10;
8 static integer c__3 = 3;
9 static integer c__4 = 4;
10 static integer c__11 = 11;
12 /* Subroutine */ int slasq2_(integer *n, real *z__, integer *info)
14 /* System generated locals */
15 integer i__1, i__2, i__3;
18 /* Builtin functions */
19 double sqrt(doublereal);
28 real dn1, dn2, eps, tau, tol;
33 real dmin__, emin, emax;
35 real qmin, temp, qmax, zmax;
39 real desig, trace, sigma;
41 extern /* Subroutine */ int slazq3_(integer *, integer *, real *, integer
42 *, real *, real *, real *, real *, integer *, integer *, integer *
43 , logical *, integer *, real *, real *, real *, real *, real *,
45 extern doublereal slamch_(char *);
46 integer iwhila, iwhilb;
48 extern /* Subroutine */ int xerbla_(char *, integer *);
49 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
50 integer *, integer *);
51 extern /* Subroutine */ int slasrt_(char *, integer *, real *, integer *);
54 /* -- LAPACK routine (version 3.1) -- */
55 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
58 /* Modified to call SLAZQ3 in place of SLASQ3, 13 Feb 03, SJH. */
60 /* .. Scalar Arguments .. */
62 /* .. Array Arguments .. */
68 /* SLASQ2 computes all the eigenvalues of the symmetric positive */
69 /* definite tridiagonal matrix associated with the qd array Z to high */
70 /* relative accuracy are computed to high relative accuracy, in the */
71 /* absence of denormalization, underflow and overflow. */
73 /* To see the relation of Z to the tridiagonal matrix, let L be a */
74 /* unit lower bidiagonal matrix with subdiagonals Z(2,4,6,,..) and */
75 /* let U be an upper bidiagonal matrix with 1's above and diagonal */
76 /* Z(1,3,5,,..). The tridiagonal is L*U or, if you prefer, the */
77 /* symmetric tridiagonal to which it is similar. */
79 /* Note : SLASQ2 defines a logical variable, IEEE, which is true */
80 /* on machines which follow ieee-754 floating-point standard in their */
81 /* handling of infinities and NaNs, and false otherwise. This variable */
82 /* is passed to SLAZQ3. */
87 /* N (input) INTEGER */
88 /* The number of rows and columns in the matrix. N >= 0. */
90 /* Z (workspace) REAL array, dimension (4*N) */
91 /* On entry Z holds the qd array. On exit, entries 1 to N hold */
92 /* the eigenvalues in decreasing order, Z( 2*N+1 ) holds the */
93 /* trace, and Z( 2*N+2 ) holds the sum of the eigenvalues. If */
94 /* N > 2, then Z( 2*N+3 ) holds the iteration count, Z( 2*N+4 ) */
95 /* holds NDIVS/NIN^2, and Z( 2*N+5 ) holds the percentage of */
96 /* shifts that failed. */
98 /* INFO (output) INTEGER */
99 /* = 0: successful exit */
100 /* < 0: if the i-th argument is a scalar and had an illegal */
101 /* value, then INFO = -i, if the i-th argument is an */
102 /* array and the j-entry had an illegal value, then */
103 /* INFO = -(i*100+j) */
104 /* > 0: the algorithm failed */
105 /* = 1, a split was marked by a positive value in E */
106 /* = 2, current block of Z not diagonalized after 30*N */
107 /* iterations (in inner while loop) */
108 /* = 3, termination criterion of outer while loop not met */
109 /* (program created more than N unreduced blocks) */
111 /* Further Details */
112 /* =============== */
113 /* Local Variables: I0:N0 defines a current unreduced segment of Z. */
114 /* The shifts are accumulated in SIGMA. Iteration count is in ITER. */
115 /* Ping-pong is controlled by PP (alternates between 0 and 1). */
117 /* ===================================================================== */
119 /* .. Parameters .. */
121 /* .. Local Scalars .. */
123 /* .. External Subroutines .. */
125 /* .. External Functions .. */
127 /* .. Intrinsic Functions .. */
129 /* .. Executable Statements .. */
131 /* Test the input arguments. */
132 /* (in case SLASQ2 is not called by SLASQ1) */
134 /* Parameter adjustments */
139 eps = slamch_("Precision");
140 safmin = slamch_("Safe minimum");
142 /* Computing 2nd power */
148 xerbla_("SLASQ2", &c__1);
150 } else if (*n == 0) {
152 } else if (*n == 1) {
158 xerbla_("SLASQ2", &c__2);
161 } else if (*n == 2) {
165 if (z__[2] < 0.f || z__[3] < 0.f) {
167 xerbla_("SLASQ2", &c__2);
169 } else if (z__[3] > z__[1]) {
174 z__[5] = z__[1] + z__[2] + z__[3];
175 if (z__[2] > z__[3] * tol2) {
176 t = (z__[1] - z__[3] + z__[2]) * .5f;
177 s = z__[3] * (z__[2] / t);
179 s = z__[3] * (z__[2] / (t * (sqrt(s / t + 1.f) + 1.f)));
181 s = z__[3] * (z__[2] / (t + sqrt(t) * sqrt(t + s)));
183 t = z__[1] + (s + z__[2]);
184 z__[3] *= z__[1] / t;
188 z__[6] = z__[2] + z__[1];
192 /* Check for negative data and compute sums of q's and e's. */
202 for (k = 1; k <= i__1; k += 2) {
205 xerbla_("SLASQ2", &c__2);
207 } else if (z__[k + 1] < 0.f) {
209 xerbla_("SLASQ2", &c__2);
215 r__1 = qmax, r__2 = z__[k];
216 qmax = dmax(r__1,r__2);
218 r__1 = emin, r__2 = z__[k + 1];
219 emin = dmin(r__1,r__2);
221 r__1 = max(qmax,zmax), r__2 = z__[k + 1];
222 zmax = dmax(r__1,r__2);
225 if (z__[(*n << 1) - 1] < 0.f) {
226 *info = -((*n << 1) + 199);
227 xerbla_("SLASQ2", &c__2);
230 d__ += z__[(*n << 1) - 1];
232 r__1 = qmax, r__2 = z__[(*n << 1) - 1];
233 qmax = dmax(r__1,r__2);
234 zmax = dmax(qmax,zmax);
236 /* Check for diagonality. */
240 for (k = 2; k <= i__1; ++k) {
241 z__[k] = z__[(k << 1) - 1];
244 slasrt_("D", n, &z__[1], &iinfo);
245 z__[(*n << 1) - 1] = d__;
251 /* Check for zero data. */
254 z__[(*n << 1) - 1] = 0.f;
258 /* Check whether the machine is IEEE conformable. */
260 ieee = ilaenv_(&c__10, "SLASQ2", "N", &c__1, &c__2, &c__3, &c__4) == 1 && ilaenv_(&c__11, "SLASQ2", "N", &c__1, &c__2,
263 /* Rearrange data for locality: Z=(q1,qq1,e1,ee1,q2,qq2,e2,ee2,...). */
265 for (k = *n << 1; k >= 2; k += -2) {
267 z__[(k << 1) - 1] = z__[k];
268 z__[(k << 1) - 2] = 0.f;
269 z__[(k << 1) - 3] = z__[k - 1];
276 /* Reverse the qd-array, if warranted. */
278 if (z__[(i0 << 2) - 3] * 1.5f < z__[(n0 << 2) - 3]) {
280 i__1 = i0 + n0 - 1 << 1;
281 for (i4 = i0 << 2; i4 <= i__1; i4 += 4) {
283 z__[i4 - 3] = z__[ipn4 - i4 - 3];
284 z__[ipn4 - i4 - 3] = temp;
286 z__[i4 - 1] = z__[ipn4 - i4 - 5];
287 z__[ipn4 - i4 - 5] = temp;
292 /* Initial split checking via dqd and Li's test. */
296 for (k = 1; k <= 2; ++k) {
298 d__ = z__[(n0 << 2) + pp - 3];
299 i__1 = (i0 << 2) + pp;
300 for (i4 = (n0 - 1 << 2) + pp; i4 >= i__1; i4 += -4) {
301 if (z__[i4 - 1] <= tol2 * d__) {
305 d__ = z__[i4 - 3] * (d__ / (d__ + z__[i4 - 1]));
310 /* dqd maps Z to ZZ plus Li's test. */
312 emin = z__[(i0 << 2) + pp + 1];
313 d__ = z__[(i0 << 2) + pp - 3];
314 i__1 = (n0 - 1 << 2) + pp;
315 for (i4 = (i0 << 2) + pp; i4 <= i__1; i4 += 4) {
316 z__[i4 - (pp << 1) - 2] = d__ + z__[i4 - 1];
317 if (z__[i4 - 1] <= tol2 * d__) {
319 z__[i4 - (pp << 1) - 2] = d__;
320 z__[i4 - (pp << 1)] = 0.f;
322 } else if (safmin * z__[i4 + 1] < z__[i4 - (pp << 1) - 2] &&
323 safmin * z__[i4 - (pp << 1) - 2] < z__[i4 + 1]) {
324 temp = z__[i4 + 1] / z__[i4 - (pp << 1) - 2];
325 z__[i4 - (pp << 1)] = z__[i4 - 1] * temp;
328 z__[i4 - (pp << 1)] = z__[i4 + 1] * (z__[i4 - 1] / z__[i4 - (
330 d__ = z__[i4 + 1] * (d__ / z__[i4 - (pp << 1) - 2]);
333 r__1 = emin, r__2 = z__[i4 - (pp << 1)];
334 emin = dmin(r__1,r__2);
337 z__[(n0 << 2) - pp - 2] = d__;
341 qmax = z__[(i0 << 2) - pp - 2];
342 i__1 = (n0 << 2) - pp - 2;
343 for (i4 = (i0 << 2) - pp + 2; i4 <= i__1; i4 += 4) {
345 r__1 = qmax, r__2 = z__[i4];
346 qmax = dmax(r__1,r__2);
350 /* Prepare for the next iteration on K. */
356 /* Initialise variables to pass to SLAZQ3 */
371 for (iwhila = 1; iwhila <= i__1; ++iwhila) {
376 /* While array unfinished do */
378 /* E(N0) holds the value of SIGMA when submatrix in I0:N0 */
379 /* splits from the rest of the array, but is negated. */
385 sigma = -z__[(n0 << 2) - 1];
392 /* Find last unreduced submatrix's top index I0, find QMAX and */
393 /* EMIN. Find Gershgorin-type bound if Q's much greater than E's. */
397 emin = (r__1 = z__[(n0 << 2) - 5], dabs(r__1));
401 qmin = z__[(n0 << 2) - 3];
403 for (i4 = n0 << 2; i4 >= 8; i4 += -4) {
404 if (z__[i4 - 5] <= 0.f) {
407 if (qmin >= emax * 4.f) {
409 r__1 = qmin, r__2 = z__[i4 - 3];
410 qmin = dmin(r__1,r__2);
412 r__1 = emax, r__2 = z__[i4 - 5];
413 emax = dmax(r__1,r__2);
416 r__1 = qmax, r__2 = z__[i4 - 7] + z__[i4 - 5];
417 qmax = dmax(r__1,r__2);
419 r__1 = emin, r__2 = z__[i4 - 5];
420 emin = dmin(r__1,r__2);
428 /* Store EMIN for passing to SLAZQ3. */
430 z__[(n0 << 2) - 1] = emin;
432 /* Put -(initial shift) into DMIN. */
435 r__1 = 0.f, r__2 = qmin - sqrt(qmin) * 2.f * sqrt(emax);
436 dmin__ = -dmax(r__1,r__2);
438 /* Now I0:N0 is unreduced. PP = 0 for ping, PP = 1 for pong. */
442 nbig = (n0 - i0 + 1) * 30;
444 for (iwhilb = 1; iwhilb <= i__2; ++iwhilb) {
449 /* While submatrix unfinished take a good dqds step. */
451 slazq3_(&i0, &n0, &z__[1], &pp, &dmin__, &sigma, &desig, &qmax, &
452 nfail, &iter, &ndiv, &ieee, &ttype, &dmin1, &dmin2, &dn, &
457 /* When EMIN is very small check for splits. */
459 if (pp == 0 && n0 - i0 >= 3) {
460 if (z__[n0 * 4] <= tol2 * qmax || z__[(n0 << 2) - 1] <= tol2 *
463 qmax = z__[(i0 << 2) - 3];
464 emin = z__[(i0 << 2) - 1];
465 oldemn = z__[i0 * 4];
467 for (i4 = i0 << 2; i4 <= i__3; i4 += 4) {
468 if (z__[i4] <= tol2 * z__[i4 - 3] || z__[i4 - 1] <=
470 z__[i4 - 1] = -sigma;
474 oldemn = z__[i4 + 4];
477 r__1 = qmax, r__2 = z__[i4 + 1];
478 qmax = dmax(r__1,r__2);
480 r__1 = emin, r__2 = z__[i4 - 1];
481 emin = dmin(r__1,r__2);
483 r__1 = oldemn, r__2 = z__[i4];
484 oldemn = dmin(r__1,r__2);
488 z__[(n0 << 2) - 1] = emin;
489 z__[n0 * 4] = oldemn;
515 /* Move q's to the front. */
518 for (k = 2; k <= i__1; ++k) {
519 z__[k] = z__[(k << 2) - 3];
523 /* Sort and compute sum of eigenvalues. */
525 slasrt_("D", n, &z__[1], &iinfo);
528 for (k = *n; k >= 1; --k) {
533 /* Store trace, sum(eigenvalues) and information on performance. */
535 z__[(*n << 1) + 1] = trace;
536 z__[(*n << 1) + 2] = e;
537 z__[(*n << 1) + 3] = (real) iter;
538 /* Computing 2nd power */
540 z__[(*n << 1) + 4] = (real) ndiv / (real) (i__1 * i__1);
541 z__[(*n << 1) + 5] = nfail * 100.f / (real) iter;