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 dlasq2_(integer *n, doublereal *z__, integer *info)
14 /* System generated locals */
15 integer i__1, i__2, i__3;
16 doublereal d__1, d__2;
18 /* Builtin functions */
19 double sqrt(doublereal);
28 doublereal dn1, dn2, eps, tau, tol;
33 doublereal dmin__, emin, emax;
35 doublereal qmin, temp, qmax, zmax;
37 doublereal dmin1, dmin2;
39 doublereal desig, trace, sigma;
41 extern /* Subroutine */ int dlazq3_(integer *, integer *, doublereal *,
42 integer *, doublereal *, doublereal *, doublereal *, doublereal *,
43 integer *, integer *, integer *, logical *, integer *,
44 doublereal *, doublereal *, doublereal *, doublereal *,
45 doublereal *, doublereal *);
46 extern doublereal dlamch_(char *);
47 integer iwhila, iwhilb;
48 doublereal oldemn, safmin;
49 extern /* Subroutine */ int xerbla_(char *, integer *);
50 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
51 integer *, integer *);
52 extern /* Subroutine */ int dlasrt_(char *, integer *, doublereal *,
56 /* -- LAPACK routine (version 3.1) -- */
57 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
60 /* Modified to call DLAZQ3 in place of DLASQ3, 13 Feb 03, SJH. */
62 /* .. Scalar Arguments .. */
64 /* .. Array Arguments .. */
70 /* DLASQ2 computes all the eigenvalues of the symmetric positive */
71 /* definite tridiagonal matrix associated with the qd array Z to high */
72 /* relative accuracy are computed to high relative accuracy, in the */
73 /* absence of denormalization, underflow and overflow. */
75 /* To see the relation of Z to the tridiagonal matrix, let L be a */
76 /* unit lower bidiagonal matrix with subdiagonals Z(2,4,6,,..) and */
77 /* let U be an upper bidiagonal matrix with 1's above and diagonal */
78 /* Z(1,3,5,,..). The tridiagonal is L*U or, if you prefer, the */
79 /* symmetric tridiagonal to which it is similar. */
81 /* Note : DLASQ2 defines a logical variable, IEEE, which is true */
82 /* on machines which follow ieee-754 floating-point standard in their */
83 /* handling of infinities and NaNs, and false otherwise. This variable */
84 /* is passed to DLAZQ3. */
89 /* N (input) INTEGER */
90 /* The number of rows and columns in the matrix. N >= 0. */
92 /* Z (workspace) DOUBLE PRECISION array, dimension ( 4*N ) */
93 /* On entry Z holds the qd array. On exit, entries 1 to N hold */
94 /* the eigenvalues in decreasing order, Z( 2*N+1 ) holds the */
95 /* trace, and Z( 2*N+2 ) holds the sum of the eigenvalues. If */
96 /* N > 2, then Z( 2*N+3 ) holds the iteration count, Z( 2*N+4 ) */
97 /* holds NDIVS/NIN^2, and Z( 2*N+5 ) holds the percentage of */
98 /* shifts that failed. */
100 /* INFO (output) INTEGER */
101 /* = 0: successful exit */
102 /* < 0: if the i-th argument is a scalar and had an illegal */
103 /* value, then INFO = -i, if the i-th argument is an */
104 /* array and the j-entry had an illegal value, then */
105 /* INFO = -(i*100+j) */
106 /* > 0: the algorithm failed */
107 /* = 1, a split was marked by a positive value in E */
108 /* = 2, current block of Z not diagonalized after 30*N */
109 /* iterations (in inner while loop) */
110 /* = 3, termination criterion of outer while loop not met */
111 /* (program created more than N unreduced blocks) */
113 /* Further Details */
114 /* =============== */
115 /* Local Variables: I0:N0 defines a current unreduced segment of Z. */
116 /* The shifts are accumulated in SIGMA. Iteration count is in ITER. */
117 /* Ping-pong is controlled by PP (alternates between 0 and 1). */
119 /* ===================================================================== */
121 /* .. Parameters .. */
123 /* .. Local Scalars .. */
125 /* .. External Subroutines .. */
127 /* .. External Functions .. */
129 /* .. Intrinsic Functions .. */
131 /* .. Executable Statements .. */
133 /* Test the input arguments. */
134 /* (in case DLASQ2 is not called by DLASQ1) */
136 /* Parameter adjustments */
141 eps = dlamch_("Precision");
142 safmin = dlamch_("Safe minimum");
144 /* Computing 2nd power */
150 xerbla_("DLASQ2", &c__1);
152 } else if (*n == 0) {
154 } else if (*n == 1) {
160 xerbla_("DLASQ2", &c__2);
163 } else if (*n == 2) {
167 if (z__[2] < 0. || z__[3] < 0.) {
169 xerbla_("DLASQ2", &c__2);
171 } else if (z__[3] > z__[1]) {
176 z__[5] = z__[1] + z__[2] + z__[3];
177 if (z__[2] > z__[3] * tol2) {
178 t = (z__[1] - z__[3] + z__[2]) * .5;
179 s = z__[3] * (z__[2] / t);
181 s = z__[3] * (z__[2] / (t * (sqrt(s / t + 1.) + 1.)));
183 s = z__[3] * (z__[2] / (t + sqrt(t) * sqrt(t + s)));
185 t = z__[1] + (s + z__[2]);
186 z__[3] *= z__[1] / t;
190 z__[6] = z__[2] + z__[1];
194 /* Check for negative data and compute sums of q's and e's. */
204 for (k = 1; k <= i__1; k += 2) {
207 xerbla_("DLASQ2", &c__2);
209 } else if (z__[k + 1] < 0.) {
211 xerbla_("DLASQ2", &c__2);
217 d__1 = qmax, d__2 = z__[k];
218 qmax = max(d__1,d__2);
220 d__1 = emin, d__2 = z__[k + 1];
221 emin = min(d__1,d__2);
223 d__1 = max(qmax,zmax), d__2 = z__[k + 1];
224 zmax = max(d__1,d__2);
227 if (z__[(*n << 1) - 1] < 0.) {
228 *info = -((*n << 1) + 199);
229 xerbla_("DLASQ2", &c__2);
232 d__ += z__[(*n << 1) - 1];
234 d__1 = qmax, d__2 = z__[(*n << 1) - 1];
235 qmax = max(d__1,d__2);
236 zmax = max(qmax,zmax);
238 /* Check for diagonality. */
242 for (k = 2; k <= i__1; ++k) {
243 z__[k] = z__[(k << 1) - 1];
246 dlasrt_("D", n, &z__[1], &iinfo);
247 z__[(*n << 1) - 1] = d__;
253 /* Check for zero data. */
256 z__[(*n << 1) - 1] = 0.;
260 /* Check whether the machine is IEEE conformable. */
262 ieee = ilaenv_(&c__10, "DLASQ2", "N", &c__1, &c__2, &c__3, &c__4) == 1 && ilaenv_(&c__11, "DLASQ2", "N", &c__1, &c__2,
265 /* Rearrange data for locality: Z=(q1,qq1,e1,ee1,q2,qq2,e2,ee2,...). */
267 for (k = *n << 1; k >= 2; k += -2) {
269 z__[(k << 1) - 1] = z__[k];
270 z__[(k << 1) - 2] = 0.;
271 z__[(k << 1) - 3] = z__[k - 1];
278 /* Reverse the qd-array, if warranted. */
280 if (z__[(i0 << 2) - 3] * 1.5 < z__[(n0 << 2) - 3]) {
282 i__1 = i0 + n0 - 1 << 1;
283 for (i4 = i0 << 2; i4 <= i__1; i4 += 4) {
285 z__[i4 - 3] = z__[ipn4 - i4 - 3];
286 z__[ipn4 - i4 - 3] = temp;
288 z__[i4 - 1] = z__[ipn4 - i4 - 5];
289 z__[ipn4 - i4 - 5] = temp;
294 /* Initial split checking via dqd and Li's test. */
298 for (k = 1; k <= 2; ++k) {
300 d__ = z__[(n0 << 2) + pp - 3];
301 i__1 = (i0 << 2) + pp;
302 for (i4 = (n0 - 1 << 2) + pp; i4 >= i__1; i4 += -4) {
303 if (z__[i4 - 1] <= tol2 * d__) {
307 d__ = z__[i4 - 3] * (d__ / (d__ + z__[i4 - 1]));
312 /* dqd maps Z to ZZ plus Li's test. */
314 emin = z__[(i0 << 2) + pp + 1];
315 d__ = z__[(i0 << 2) + pp - 3];
316 i__1 = (n0 - 1 << 2) + pp;
317 for (i4 = (i0 << 2) + pp; i4 <= i__1; i4 += 4) {
318 z__[i4 - (pp << 1) - 2] = d__ + z__[i4 - 1];
319 if (z__[i4 - 1] <= tol2 * d__) {
321 z__[i4 - (pp << 1) - 2] = d__;
322 z__[i4 - (pp << 1)] = 0.;
324 } else if (safmin * z__[i4 + 1] < z__[i4 - (pp << 1) - 2] &&
325 safmin * z__[i4 - (pp << 1) - 2] < z__[i4 + 1]) {
326 temp = z__[i4 + 1] / z__[i4 - (pp << 1) - 2];
327 z__[i4 - (pp << 1)] = z__[i4 - 1] * temp;
330 z__[i4 - (pp << 1)] = z__[i4 + 1] * (z__[i4 - 1] / z__[i4 - (
332 d__ = z__[i4 + 1] * (d__ / z__[i4 - (pp << 1) - 2]);
335 d__1 = emin, d__2 = z__[i4 - (pp << 1)];
336 emin = min(d__1,d__2);
339 z__[(n0 << 2) - pp - 2] = d__;
343 qmax = z__[(i0 << 2) - pp - 2];
344 i__1 = (n0 << 2) - pp - 2;
345 for (i4 = (i0 << 2) - pp + 2; i4 <= i__1; i4 += 4) {
347 d__1 = qmax, d__2 = z__[i4];
348 qmax = max(d__1,d__2);
352 /* Prepare for the next iteration on K. */
358 /* Initialise variables to pass to DLAZQ3 */
373 for (iwhila = 1; iwhila <= i__1; ++iwhila) {
378 /* While array unfinished do */
380 /* E(N0) holds the value of SIGMA when submatrix in I0:N0 */
381 /* splits from the rest of the array, but is negated. */
387 sigma = -z__[(n0 << 2) - 1];
394 /* Find last unreduced submatrix's top index I0, find QMAX and */
395 /* EMIN. Find Gershgorin-type bound if Q's much greater than E's. */
399 emin = (d__1 = z__[(n0 << 2) - 5], abs(d__1));
403 qmin = z__[(n0 << 2) - 3];
405 for (i4 = n0 << 2; i4 >= 8; i4 += -4) {
406 if (z__[i4 - 5] <= 0.) {
409 if (qmin >= emax * 4.) {
411 d__1 = qmin, d__2 = z__[i4 - 3];
412 qmin = min(d__1,d__2);
414 d__1 = emax, d__2 = z__[i4 - 5];
415 emax = max(d__1,d__2);
418 d__1 = qmax, d__2 = z__[i4 - 7] + z__[i4 - 5];
419 qmax = max(d__1,d__2);
421 d__1 = emin, d__2 = z__[i4 - 5];
422 emin = min(d__1,d__2);
430 /* Store EMIN for passing to DLAZQ3. */
432 z__[(n0 << 2) - 1] = emin;
434 /* Put -(initial shift) into DMIN. */
437 d__1 = 0., d__2 = qmin - sqrt(qmin) * 2. * sqrt(emax);
438 dmin__ = -max(d__1,d__2);
440 /* Now I0:N0 is unreduced. PP = 0 for ping, PP = 1 for pong. */
444 nbig = (n0 - i0 + 1) * 30;
446 for (iwhilb = 1; iwhilb <= i__2; ++iwhilb) {
451 /* While submatrix unfinished take a good dqds step. */
453 dlazq3_(&i0, &n0, &z__[1], &pp, &dmin__, &sigma, &desig, &qmax, &
454 nfail, &iter, &ndiv, &ieee, &ttype, &dmin1, &dmin2, &dn, &
459 /* When EMIN is very small check for splits. */
461 if (pp == 0 && n0 - i0 >= 3) {
462 if (z__[n0 * 4] <= tol2 * qmax || z__[(n0 << 2) - 1] <= tol2 *
465 qmax = z__[(i0 << 2) - 3];
466 emin = z__[(i0 << 2) - 1];
467 oldemn = z__[i0 * 4];
469 for (i4 = i0 << 2; i4 <= i__3; i4 += 4) {
470 if (z__[i4] <= tol2 * z__[i4 - 3] || z__[i4 - 1] <=
472 z__[i4 - 1] = -sigma;
476 oldemn = z__[i4 + 4];
479 d__1 = qmax, d__2 = z__[i4 + 1];
480 qmax = max(d__1,d__2);
482 d__1 = emin, d__2 = z__[i4 - 1];
483 emin = min(d__1,d__2);
485 d__1 = oldemn, d__2 = z__[i4];
486 oldemn = min(d__1,d__2);
490 z__[(n0 << 2) - 1] = emin;
491 z__[n0 * 4] = oldemn;
517 /* Move q's to the front. */
520 for (k = 2; k <= i__1; ++k) {
521 z__[k] = z__[(k << 2) - 3];
525 /* Sort and compute sum of eigenvalues. */
527 dlasrt_("D", n, &z__[1], &iinfo);
530 for (k = *n; k >= 1; --k) {
535 /* Store trace, sum(eigenvalues) and information on performance. */
537 z__[(*n << 1) + 1] = trace;
538 z__[(*n << 1) + 2] = e;
539 z__[(*n << 1) + 3] = (doublereal) iter;
540 /* Computing 2nd power */
542 z__[(*n << 1) + 4] = (doublereal) ndiv / (doublereal) (i__1 * i__1);
543 z__[(*n << 1) + 5] = nfail * 100. / (doublereal) iter;