3 /* Table of constant values */
5 static doublereal c_b3 = -1.;
6 static integer c__1 = 1;
8 /* Subroutine */ int dlaed2_(integer *k, integer *n, integer *n1, doublereal *
9 d__, doublereal *q, integer *ldq, integer *indxq, doublereal *rho,
10 doublereal *z__, doublereal *dlamda, doublereal *w, doublereal *q2,
11 integer *indx, integer *indxc, integer *indxp, integer *coltyp,
14 /* System generated locals */
15 integer q_dim1, q_offset, i__1, i__2;
16 doublereal d__1, d__2, d__3, d__4;
18 /* Builtin functions */
19 double sqrt(doublereal);
25 integer k2, n2, ct, nj, pj, js, iq1, iq2, n1p1;
26 doublereal eps, tau, tol;
27 integer psm[4], imax, jmax;
28 extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
29 doublereal *, integer *, doublereal *, doublereal *);
31 extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
32 integer *), dcopy_(integer *, doublereal *, integer *, doublereal
34 extern doublereal dlapy2_(doublereal *, doublereal *), dlamch_(char *);
35 extern integer idamax_(integer *, doublereal *, integer *);
36 extern /* Subroutine */ int dlamrg_(integer *, integer *, doublereal *,
37 integer *, integer *, integer *), dlacpy_(char *, integer *,
38 integer *, doublereal *, integer *, doublereal *, integer *), xerbla_(char *, integer *);
41 /* -- LAPACK routine (version 3.1) -- */
42 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
45 /* .. Scalar Arguments .. */
47 /* .. Array Arguments .. */
53 /* DLAED2 merges the two sets of eigenvalues together into a single */
54 /* sorted set. Then it tries to deflate the size of the problem. */
55 /* There are two ways in which deflation can occur: when two or more */
56 /* eigenvalues are close together or if there is a tiny entry in the */
57 /* Z vector. For each such occurrence the order of the related secular */
58 /* equation problem is reduced by one. */
63 /* K (output) INTEGER */
64 /* The number of non-deflated eigenvalues, and the order of the */
65 /* related secular equation. 0 <= K <=N. */
67 /* N (input) INTEGER */
68 /* The dimension of the symmetric tridiagonal matrix. N >= 0. */
70 /* N1 (input) INTEGER */
71 /* The location of the last eigenvalue in the leading sub-matrix. */
72 /* min(1,N) <= N1 <= N/2. */
74 /* D (input/output) DOUBLE PRECISION array, dimension (N) */
75 /* On entry, D contains the eigenvalues of the two submatrices to */
77 /* On exit, D contains the trailing (N-K) updated eigenvalues */
78 /* (those which were deflated) sorted into increasing order. */
80 /* Q (input/output) DOUBLE PRECISION array, dimension (LDQ, N) */
81 /* On entry, Q contains the eigenvectors of two submatrices in */
82 /* the two square blocks with corners at (1,1), (N1,N1) */
83 /* and (N1+1, N1+1), (N,N). */
84 /* On exit, Q contains the trailing (N-K) updated eigenvectors */
85 /* (those which were deflated) in its last N-K columns. */
87 /* LDQ (input) INTEGER */
88 /* The leading dimension of the array Q. LDQ >= max(1,N). */
90 /* INDXQ (input/output) INTEGER array, dimension (N) */
91 /* The permutation which separately sorts the two sub-problems */
92 /* in D into ascending order. Note that elements in the second */
93 /* half of this permutation must first have N1 added to their */
94 /* values. Destroyed on exit. */
96 /* RHO (input/output) DOUBLE PRECISION */
97 /* On entry, the off-diagonal element associated with the rank-1 */
98 /* cut which originally split the two submatrices which are now */
99 /* being recombined. */
100 /* On exit, RHO has been modified to the value required by */
103 /* Z (input) DOUBLE PRECISION array, dimension (N) */
104 /* On entry, Z contains the updating vector (the last */
105 /* row of the first sub-eigenvector matrix and the first row of */
106 /* the second sub-eigenvector matrix). */
107 /* On exit, the contents of Z have been destroyed by the updating */
110 /* DLAMDA (output) DOUBLE PRECISION array, dimension (N) */
111 /* A copy of the first K eigenvalues which will be used by */
112 /* DLAED3 to form the secular equation. */
114 /* W (output) DOUBLE PRECISION array, dimension (N) */
115 /* The first k values of the final deflation-altered z-vector */
116 /* which will be passed to DLAED3. */
118 /* Q2 (output) DOUBLE PRECISION array, dimension (N1**2+(N-N1)**2) */
119 /* A copy of the first K eigenvectors which will be used by */
120 /* DLAED3 in a matrix multiply (DGEMM) to solve for the new */
123 /* INDX (workspace) INTEGER array, dimension (N) */
124 /* The permutation used to sort the contents of DLAMDA into */
125 /* ascending order. */
127 /* INDXC (output) INTEGER array, dimension (N) */
128 /* The permutation used to arrange the columns of the deflated */
129 /* Q matrix into three groups: the first group contains non-zero */
130 /* elements only at and above N1, the second contains */
131 /* non-zero elements only below N1, and the third is dense. */
133 /* INDXP (workspace) INTEGER array, dimension (N) */
134 /* The permutation used to place deflated values of D at the end */
135 /* of the array. INDXP(1:K) points to the nondeflated D-values */
136 /* and INDXP(K+1:N) points to the deflated eigenvalues. */
138 /* COLTYP (workspace/output) INTEGER array, dimension (N) */
139 /* During execution, a label which will indicate which of the */
140 /* following types a column in the Q2 matrix is: */
141 /* 1 : non-zero in the upper half only; */
143 /* 3 : non-zero in the lower half only; */
145 /* On exit, COLTYP(i) is the number of columns of type i, */
146 /* for i=1 to 4 only. */
148 /* INFO (output) INTEGER */
149 /* = 0: successful exit. */
150 /* < 0: if INFO = -i, the i-th argument had an illegal value. */
152 /* Further Details */
153 /* =============== */
155 /* Based on contributions by */
156 /* Jeff Rutter, Computer Science Division, University of California */
157 /* at Berkeley, USA */
158 /* Modified by Francoise Tisseur, University of Tennessee. */
160 /* ===================================================================== */
162 /* .. Parameters .. */
164 /* .. Local Arrays .. */
166 /* .. Local Scalars .. */
168 /* .. External Functions .. */
170 /* .. External Subroutines .. */
172 /* .. Intrinsic Functions .. */
174 /* .. Executable Statements .. */
176 /* Test the input parameters. */
178 /* Parameter adjustments */
181 q_offset = 1 + q_dim1;
198 } else if (*ldq < max(1,*n)) {
200 } else /* if(complicated condition) */ {
202 i__1 = 1, i__2 = *n / 2;
203 if (min(i__1,i__2) > *n1 || *n / 2 < *n1) {
209 xerbla_("DLAED2", &i__1);
213 /* Quick return if possible */
223 dscal_(&n2, &c_b3, &z__[n1p1], &c__1);
226 /* Normalize z so that norm(z) = 1. Since z is the concatenation of */
227 /* two normalized vectors, norm2(z) = sqrt(2). */
230 dscal_(n, &t, &z__[1], &c__1);
232 /* RHO = ABS( norm(z)**2 * RHO ) */
234 *rho = (d__1 = *rho * 2., abs(d__1));
236 /* Sort the eigenvalues into increasing order */
239 for (i__ = n1p1; i__ <= i__1; ++i__) {
244 /* re-integrate the deflated parts from the last pass */
247 for (i__ = 1; i__ <= i__1; ++i__) {
248 dlamda[i__] = d__[indxq[i__]];
251 dlamrg_(n1, &n2, &dlamda[1], &c__1, &c__1, &indxc[1]);
253 for (i__ = 1; i__ <= i__1; ++i__) {
254 indx[i__] = indxq[indxc[i__]];
258 /* Calculate the allowable deflation tolerance */
260 imax = idamax_(n, &z__[1], &c__1);
261 jmax = idamax_(n, &d__[1], &c__1);
262 eps = dlamch_("Epsilon");
264 d__3 = (d__1 = d__[jmax], abs(d__1)), d__4 = (d__2 = z__[imax], abs(d__2))
266 tol = eps * 8. * max(d__3,d__4);
268 /* If the rank-1 modifier is small enough, no more needs to be done */
269 /* except to reorganize Q so that its columns correspond with the */
272 if (*rho * (d__1 = z__[imax], abs(d__1)) <= tol) {
276 for (j = 1; j <= i__1; ++j) {
278 dcopy_(n, &q[i__ * q_dim1 + 1], &c__1, &q2[iq2], &c__1);
279 dlamda[j] = d__[i__];
283 dlacpy_("A", n, n, &q2[1], n, &q[q_offset], ldq);
284 dcopy_(n, &dlamda[1], &c__1, &d__[1], &c__1);
288 /* If there are multiple eigenvalues then the problem deflates. Here */
289 /* the number of equal eigenvalues are found. As each equal */
290 /* eigenvalue is found, an elementary reflector is computed to rotate */
291 /* the corresponding eigensubspace so that the corresponding */
292 /* components of Z are zero in this new basis. */
295 for (i__ = 1; i__ <= i__1; ++i__) {
300 for (i__ = n1p1; i__ <= i__1; ++i__) {
309 for (j = 1; j <= i__1; ++j) {
311 if (*rho * (d__1 = z__[nj], abs(d__1)) <= tol) {
313 /* Deflate due to small z component. */
333 if (*rho * (d__1 = z__[nj], abs(d__1)) <= tol) {
335 /* Deflate due to small z component. */
342 /* Check if eigenvalues are close enough to allow deflation. */
347 /* Find sqrt(a**2+b**2) without overflow or */
348 /* destructive underflow. */
350 tau = dlapy2_(&c__, &s);
351 t = d__[nj] - d__[pj];
354 if ((d__1 = t * c__ * s, abs(d__1)) <= tol) {
356 /* Deflation is possible. */
360 if (coltyp[nj] != coltyp[pj]) {
364 drot_(n, &q[pj * q_dim1 + 1], &c__1, &q[nj * q_dim1 + 1], &c__1, &
366 /* Computing 2nd power */
368 /* Computing 2nd power */
370 t = d__[pj] * (d__1 * d__1) + d__[nj] * (d__2 * d__2);
371 /* Computing 2nd power */
373 /* Computing 2nd power */
375 d__[nj] = d__[pj] * (d__1 * d__1) + d__[nj] * (d__2 * d__2);
380 if (k2 + i__ <= *n) {
381 if (d__[pj] < d__[indxp[k2 + i__]]) {
382 indxp[k2 + i__ - 1] = indxp[k2 + i__];
383 indxp[k2 + i__] = pj;
387 indxp[k2 + i__ - 1] = pj;
390 indxp[k2 + i__ - 1] = pj;
395 dlamda[*k] = d__[pj];
404 /* Record the last eigenvalue. */
407 dlamda[*k] = d__[pj];
411 /* Count up the total number of the various types of columns, then */
412 /* form a permutation which positions the four column types into */
413 /* four uniform groups (although one or more of these groups may be */
416 for (j = 1; j <= 4; ++j) {
421 for (j = 1; j <= i__1; ++j) {
427 /* PSM(*) = Position in SubMatrix (of types 1 through 4) */
430 psm[1] = ctot[0] + 1;
431 psm[2] = psm[1] + ctot[1];
432 psm[3] = psm[2] + ctot[2];
435 /* Fill out the INDXC array so that the permutation which it induces */
436 /* will place all type-1 columns first, all type-2 columns next, */
437 /* then all type-3's, and finally all type-4's. */
440 for (j = 1; j <= i__1; ++j) {
443 indx[psm[ct - 1]] = js;
444 indxc[psm[ct - 1]] = j;
449 /* Sort the eigenvalues and corresponding eigenvectors into DLAMDA */
450 /* and Q2 respectively. The eigenvalues/vectors which were not */
451 /* deflated go into the first K slots of DLAMDA and Q2 respectively, */
452 /* while those which were deflated go into the last N - K slots. */
456 iq2 = (ctot[0] + ctot[1]) * *n1 + 1;
458 for (j = 1; j <= i__1; ++j) {
460 dcopy_(n1, &q[js * q_dim1 + 1], &c__1, &q2[iq1], &c__1);
468 for (j = 1; j <= i__1; ++j) {
470 dcopy_(n1, &q[js * q_dim1 + 1], &c__1, &q2[iq1], &c__1);
471 dcopy_(&n2, &q[*n1 + 1 + js * q_dim1], &c__1, &q2[iq2], &c__1);
480 for (j = 1; j <= i__1; ++j) {
482 dcopy_(&n2, &q[*n1 + 1 + js * q_dim1], &c__1, &q2[iq2], &c__1);
491 for (j = 1; j <= i__1; ++j) {
493 dcopy_(n, &q[js * q_dim1 + 1], &c__1, &q2[iq2], &c__1);
500 /* The deflated eigenvalues and their corresponding vectors go back */
501 /* into the last N - K slots of D and Q respectively. */
503 dlacpy_("A", n, &ctot[3], &q2[iq1], n, &q[(*k + 1) * q_dim1 + 1], ldq);
505 dcopy_(&i__1, &z__[*k + 1], &c__1, &d__[*k + 1], &c__1);
507 /* Copy CTOT into COLTYP for referencing in DLAED3. */
509 for (j = 1; j <= 4; ++j) {
510 coltyp[j] = ctot[j - 1];