3 /* Table of constant values */
5 static real c_b3 = -1.f;
6 static integer c__1 = 1;
8 /* Subroutine */ int slaed2_(integer *k, integer *n, integer *n1, real *d__,
9 real *q, integer *ldq, integer *indxq, real *rho, real *z__, real *
10 dlamda, real *w, real *q2, integer *indx, integer *indxc, integer *
11 indxp, integer *coltyp, integer *info)
13 /* System generated locals */
14 integer q_dim1, q_offset, i__1, i__2;
15 real r__1, r__2, r__3, r__4;
17 /* Builtin functions */
18 double sqrt(doublereal);
24 integer k2, n2, ct, nj, pj, js, iq1, iq2, n1p1;
26 integer psm[4], imax, jmax, ctot[4];
27 extern /* Subroutine */ int srot_(integer *, real *, integer *, real *,
28 integer *, real *, real *), sscal_(integer *, real *, real *,
29 integer *), scopy_(integer *, real *, integer *, real *, integer *
31 extern doublereal slapy2_(real *, real *), slamch_(char *);
32 extern /* Subroutine */ int xerbla_(char *, integer *);
33 extern integer isamax_(integer *, real *, integer *);
34 extern /* Subroutine */ int slamrg_(integer *, integer *, real *, integer
35 *, integer *, integer *), slacpy_(char *, integer *, integer *,
36 real *, integer *, real *, integer *);
39 /* -- LAPACK routine (version 3.1) -- */
40 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
43 /* .. Scalar Arguments .. */
45 /* .. Array Arguments .. */
51 /* SLAED2 merges the two sets of eigenvalues together into a single */
52 /* sorted set. Then it tries to deflate the size of the problem. */
53 /* There are two ways in which deflation can occur: when two or more */
54 /* eigenvalues are close together or if there is a tiny entry in the */
55 /* Z vector. For each such occurrence the order of the related secular */
56 /* equation problem is reduced by one. */
61 /* K (output) INTEGER */
62 /* The number of non-deflated eigenvalues, and the order of the */
63 /* related secular equation. 0 <= K <=N. */
65 /* N (input) INTEGER */
66 /* The dimension of the symmetric tridiagonal matrix. N >= 0. */
68 /* N1 (input) INTEGER */
69 /* The location of the last eigenvalue in the leading sub-matrix. */
70 /* min(1,N) <= N1 <= N/2. */
72 /* D (input/output) REAL array, dimension (N) */
73 /* On entry, D contains the eigenvalues of the two submatrices to */
75 /* On exit, D contains the trailing (N-K) updated eigenvalues */
76 /* (those which were deflated) sorted into increasing order. */
78 /* Q (input/output) REAL array, dimension (LDQ, N) */
79 /* On entry, Q contains the eigenvectors of two submatrices in */
80 /* the two square blocks with corners at (1,1), (N1,N1) */
81 /* and (N1+1, N1+1), (N,N). */
82 /* On exit, Q contains the trailing (N-K) updated eigenvectors */
83 /* (those which were deflated) in its last N-K columns. */
85 /* LDQ (input) INTEGER */
86 /* The leading dimension of the array Q. LDQ >= max(1,N). */
88 /* INDXQ (input/output) INTEGER array, dimension (N) */
89 /* The permutation which separately sorts the two sub-problems */
90 /* in D into ascending order. Note that elements in the second */
91 /* half of this permutation must first have N1 added to their */
92 /* values. Destroyed on exit. */
94 /* RHO (input/output) REAL */
95 /* On entry, the off-diagonal element associated with the rank-1 */
96 /* cut which originally split the two submatrices which are now */
97 /* being recombined. */
98 /* On exit, RHO has been modified to the value required by */
101 /* Z (input) REAL array, dimension (N) */
102 /* On entry, Z contains the updating vector (the last */
103 /* row of the first sub-eigenvector matrix and the first row of */
104 /* the second sub-eigenvector matrix). */
105 /* On exit, the contents of Z have been destroyed by the updating */
108 /* DLAMDA (output) REAL array, dimension (N) */
109 /* A copy of the first K eigenvalues which will be used by */
110 /* SLAED3 to form the secular equation. */
112 /* W (output) REAL array, dimension (N) */
113 /* The first k values of the final deflation-altered z-vector */
114 /* which will be passed to SLAED3. */
116 /* Q2 (output) REAL array, dimension (N1**2+(N-N1)**2) */
117 /* A copy of the first K eigenvectors which will be used by */
118 /* SLAED3 in a matrix multiply (SGEMM) to solve for the new */
121 /* INDX (workspace) INTEGER array, dimension (N) */
122 /* The permutation used to sort the contents of DLAMDA into */
123 /* ascending order. */
125 /* INDXC (output) INTEGER array, dimension (N) */
126 /* The permutation used to arrange the columns of the deflated */
127 /* Q matrix into three groups: the first group contains non-zero */
128 /* elements only at and above N1, the second contains */
129 /* non-zero elements only below N1, and the third is dense. */
131 /* INDXP (workspace) INTEGER array, dimension (N) */
132 /* The permutation used to place deflated values of D at the end */
133 /* of the array. INDXP(1:K) points to the nondeflated D-values */
134 /* and INDXP(K+1:N) points to the deflated eigenvalues. */
136 /* COLTYP (workspace/output) INTEGER array, dimension (N) */
137 /* During execution, a label which will indicate which of the */
138 /* following types a column in the Q2 matrix is: */
139 /* 1 : non-zero in the upper half only; */
141 /* 3 : non-zero in the lower half only; */
143 /* On exit, COLTYP(i) is the number of columns of type i, */
144 /* for i=1 to 4 only. */
146 /* INFO (output) INTEGER */
147 /* = 0: successful exit. */
148 /* < 0: if INFO = -i, the i-th argument had an illegal value. */
150 /* Further Details */
151 /* =============== */
153 /* Based on contributions by */
154 /* Jeff Rutter, Computer Science Division, University of California */
155 /* at Berkeley, USA */
156 /* Modified by Francoise Tisseur, University of Tennessee. */
158 /* ===================================================================== */
160 /* .. Parameters .. */
162 /* .. Local Arrays .. */
164 /* .. Local Scalars .. */
166 /* .. External Functions .. */
168 /* .. External Subroutines .. */
170 /* .. Intrinsic Functions .. */
172 /* .. Executable Statements .. */
174 /* Test the input parameters. */
176 /* Parameter adjustments */
179 q_offset = 1 + q_dim1;
196 } else if (*ldq < max(1,*n)) {
198 } else /* if(complicated condition) */ {
200 i__1 = 1, i__2 = *n / 2;
201 if (min(i__1,i__2) > *n1 || *n / 2 < *n1) {
207 xerbla_("SLAED2", &i__1);
211 /* Quick return if possible */
221 sscal_(&n2, &c_b3, &z__[n1p1], &c__1);
224 /* Normalize z so that norm(z) = 1. Since z is the concatenation of */
225 /* two normalized vectors, norm2(z) = sqrt(2). */
228 sscal_(n, &t, &z__[1], &c__1);
230 /* RHO = ABS( norm(z)**2 * RHO ) */
232 *rho = (r__1 = *rho * 2.f, dabs(r__1));
234 /* Sort the eigenvalues into increasing order */
237 for (i__ = n1p1; i__ <= i__1; ++i__) {
242 /* re-integrate the deflated parts from the last pass */
245 for (i__ = 1; i__ <= i__1; ++i__) {
246 dlamda[i__] = d__[indxq[i__]];
249 slamrg_(n1, &n2, &dlamda[1], &c__1, &c__1, &indxc[1]);
251 for (i__ = 1; i__ <= i__1; ++i__) {
252 indx[i__] = indxq[indxc[i__]];
256 /* Calculate the allowable deflation tolerance */
258 imax = isamax_(n, &z__[1], &c__1);
259 jmax = isamax_(n, &d__[1], &c__1);
260 eps = slamch_("Epsilon");
262 r__3 = (r__1 = d__[jmax], dabs(r__1)), r__4 = (r__2 = z__[imax], dabs(
264 tol = eps * 8.f * dmax(r__3,r__4);
266 /* If the rank-1 modifier is small enough, no more needs to be done */
267 /* except to reorganize Q so that its columns correspond with the */
270 if (*rho * (r__1 = z__[imax], dabs(r__1)) <= tol) {
274 for (j = 1; j <= i__1; ++j) {
276 scopy_(n, &q[i__ * q_dim1 + 1], &c__1, &q2[iq2], &c__1);
277 dlamda[j] = d__[i__];
281 slacpy_("A", n, n, &q2[1], n, &q[q_offset], ldq);
282 scopy_(n, &dlamda[1], &c__1, &d__[1], &c__1);
286 /* If there are multiple eigenvalues then the problem deflates. Here */
287 /* the number of equal eigenvalues are found. As each equal */
288 /* eigenvalue is found, an elementary reflector is computed to rotate */
289 /* the corresponding eigensubspace so that the corresponding */
290 /* components of Z are zero in this new basis. */
293 for (i__ = 1; i__ <= i__1; ++i__) {
298 for (i__ = n1p1; i__ <= i__1; ++i__) {
307 for (j = 1; j <= i__1; ++j) {
309 if (*rho * (r__1 = z__[nj], dabs(r__1)) <= tol) {
311 /* Deflate due to small z component. */
331 if (*rho * (r__1 = z__[nj], dabs(r__1)) <= tol) {
333 /* Deflate due to small z component. */
340 /* Check if eigenvalues are close enough to allow deflation. */
345 /* Find sqrt(a**2+b**2) without overflow or */
346 /* destructive underflow. */
348 tau = slapy2_(&c__, &s);
349 t = d__[nj] - d__[pj];
352 if ((r__1 = t * c__ * s, dabs(r__1)) <= tol) {
354 /* Deflation is possible. */
358 if (coltyp[nj] != coltyp[pj]) {
362 srot_(n, &q[pj * q_dim1 + 1], &c__1, &q[nj * q_dim1 + 1], &c__1, &
364 /* Computing 2nd power */
366 /* Computing 2nd power */
368 t = d__[pj] * (r__1 * r__1) + d__[nj] * (r__2 * r__2);
369 /* Computing 2nd power */
371 /* Computing 2nd power */
373 d__[nj] = d__[pj] * (r__1 * r__1) + d__[nj] * (r__2 * r__2);
378 if (k2 + i__ <= *n) {
379 if (d__[pj] < d__[indxp[k2 + i__]]) {
380 indxp[k2 + i__ - 1] = indxp[k2 + i__];
381 indxp[k2 + i__] = pj;
385 indxp[k2 + i__ - 1] = pj;
388 indxp[k2 + i__ - 1] = pj;
393 dlamda[*k] = d__[pj];
402 /* Record the last eigenvalue. */
405 dlamda[*k] = d__[pj];
409 /* Count up the total number of the various types of columns, then */
410 /* form a permutation which positions the four column types into */
411 /* four uniform groups (although one or more of these groups may be */
414 for (j = 1; j <= 4; ++j) {
419 for (j = 1; j <= i__1; ++j) {
425 /* PSM(*) = Position in SubMatrix (of types 1 through 4) */
428 psm[1] = ctot[0] + 1;
429 psm[2] = psm[1] + ctot[1];
430 psm[3] = psm[2] + ctot[2];
433 /* Fill out the INDXC array so that the permutation which it induces */
434 /* will place all type-1 columns first, all type-2 columns next, */
435 /* then all type-3's, and finally all type-4's. */
438 for (j = 1; j <= i__1; ++j) {
441 indx[psm[ct - 1]] = js;
442 indxc[psm[ct - 1]] = j;
447 /* Sort the eigenvalues and corresponding eigenvectors into DLAMDA */
448 /* and Q2 respectively. The eigenvalues/vectors which were not */
449 /* deflated go into the first K slots of DLAMDA and Q2 respectively, */
450 /* while those which were deflated go into the last N - K slots. */
454 iq2 = (ctot[0] + ctot[1]) * *n1 + 1;
456 for (j = 1; j <= i__1; ++j) {
458 scopy_(n1, &q[js * q_dim1 + 1], &c__1, &q2[iq1], &c__1);
466 for (j = 1; j <= i__1; ++j) {
468 scopy_(n1, &q[js * q_dim1 + 1], &c__1, &q2[iq1], &c__1);
469 scopy_(&n2, &q[*n1 + 1 + js * q_dim1], &c__1, &q2[iq2], &c__1);
478 for (j = 1; j <= i__1; ++j) {
480 scopy_(&n2, &q[*n1 + 1 + js * q_dim1], &c__1, &q2[iq2], &c__1);
489 for (j = 1; j <= i__1; ++j) {
491 scopy_(n, &q[js * q_dim1 + 1], &c__1, &q2[iq2], &c__1);
498 /* The deflated eigenvalues and their corresponding vectors go back */
499 /* into the last N - K slots of D and Q respectively. */
501 slacpy_("A", n, &ctot[3], &q2[iq1], n, &q[(*k + 1) * q_dim1 + 1], ldq);
503 scopy_(&i__1, &z__[*k + 1], &c__1, &d__[*k + 1], &c__1);
505 /* Copy CTOT into COLTYP for referencing in SLAED3. */
507 for (j = 1; j <= 4; ++j) {
508 coltyp[j] = ctot[j - 1];