3 /* Table of constant values */
5 static integer c__1 = 1;
6 static integer c__0 = 0;
7 static real c_b13 = 1.f;
8 static real c_b26 = 0.f;
10 /* Subroutine */ int slasd3_(integer *nl, integer *nr, integer *sqre, integer
11 *k, real *d__, real *q, integer *ldq, real *dsigma, real *u, integer *
12 ldu, real *u2, integer *ldu2, real *vt, integer *ldvt, real *vt2,
13 integer *ldvt2, integer *idxc, integer *ctot, real *z__, integer *
16 /* System generated locals */
17 integer q_dim1, q_offset, u_dim1, u_offset, u2_dim1, u2_offset, vt_dim1,
18 vt_offset, vt2_dim1, vt2_offset, i__1, i__2;
21 /* Builtin functions */
22 double sqrt(doublereal), r_sign(real *, real *);
25 integer i__, j, m, n, jc;
27 integer nlp1, nlp2, nrp1;
29 extern doublereal snrm2_(integer *, real *, integer *);
31 extern /* Subroutine */ int sgemm_(char *, char *, integer *, integer *,
32 integer *, real *, real *, integer *, real *, integer *, real *,
35 extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
37 extern doublereal slamc3_(real *, real *);
38 extern /* Subroutine */ int slasd4_(integer *, integer *, real *, real *,
39 real *, real *, real *, real *, integer *), xerbla_(char *,
40 integer *), slascl_(char *, integer *, integer *, real *,
41 real *, integer *, integer *, real *, integer *, integer *), slacpy_(char *, integer *, integer *, real *, integer *,
45 /* -- LAPACK auxiliary routine (version 3.1) -- */
46 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
49 /* .. Scalar Arguments .. */
51 /* .. Array Arguments .. */
57 /* SLASD3 finds all the square roots of the roots of the secular */
58 /* equation, as defined by the values in D and Z. It makes the */
59 /* appropriate calls to SLASD4 and then updates the singular */
60 /* vectors by matrix multiplication. */
62 /* This code makes very mild assumptions about floating point */
63 /* arithmetic. It will work on machines with a guard digit in */
64 /* add/subtract, or on those binary machines without guard digits */
65 /* which subtract like the Cray XMP, Cray YMP, Cray C 90, or Cray 2. */
66 /* It could conceivably fail on hexadecimal or decimal machines */
67 /* without guard digits, but we know of none. */
69 /* SLASD3 is called from SLASD1. */
74 /* NL (input) INTEGER */
75 /* The row dimension of the upper block. NL >= 1. */
77 /* NR (input) INTEGER */
78 /* The row dimension of the lower block. NR >= 1. */
80 /* SQRE (input) INTEGER */
81 /* = 0: the lower block is an NR-by-NR square matrix. */
82 /* = 1: the lower block is an NR-by-(NR+1) rectangular matrix. */
84 /* The bidiagonal matrix has N = NL + NR + 1 rows and */
85 /* M = N + SQRE >= N columns. */
87 /* K (input) INTEGER */
88 /* The size of the secular equation, 1 =< K = < N. */
90 /* D (output) REAL array, dimension(K) */
91 /* On exit the square roots of the roots of the secular equation, */
92 /* in ascending order. */
94 /* Q (workspace) REAL array, */
95 /* dimension at least (LDQ,K). */
97 /* LDQ (input) INTEGER */
98 /* The leading dimension of the array Q. LDQ >= K. */
100 /* DSIGMA (input/output) REAL array, dimension(K) */
101 /* The first K elements of this array contain the old roots */
102 /* of the deflated updating problem. These are the poles */
103 /* of the secular equation. */
105 /* U (output) REAL array, dimension (LDU, N) */
106 /* The last N - K columns of this matrix contain the deflated */
107 /* left singular vectors. */
109 /* LDU (input) INTEGER */
110 /* The leading dimension of the array U. LDU >= N. */
112 /* U2 (input) REAL array, dimension (LDU2, N) */
113 /* The first K columns of this matrix contain the non-deflated */
114 /* left singular vectors for the split problem. */
116 /* LDU2 (input) INTEGER */
117 /* The leading dimension of the array U2. LDU2 >= N. */
119 /* VT (output) REAL array, dimension (LDVT, M) */
120 /* The last M - K columns of VT' contain the deflated */
121 /* right singular vectors. */
123 /* LDVT (input) INTEGER */
124 /* The leading dimension of the array VT. LDVT >= N. */
126 /* VT2 (input/output) REAL array, dimension (LDVT2, N) */
127 /* The first K columns of VT2' contain the non-deflated */
128 /* right singular vectors for the split problem. */
130 /* LDVT2 (input) INTEGER */
131 /* The leading dimension of the array VT2. LDVT2 >= N. */
133 /* IDXC (input) INTEGER array, dimension (N) */
134 /* The permutation used to arrange the columns of U (and rows of */
135 /* VT) into three groups: the first group contains non-zero */
136 /* entries only at and above (or before) NL +1; the second */
137 /* contains non-zero entries only at and below (or after) NL+2; */
138 /* and the third is dense. The first column of U and the row of */
139 /* VT are treated separately, however. */
141 /* The rows of the singular vectors found by SLASD4 */
142 /* must be likewise permuted before the matrix multiplies can */
145 /* CTOT (input) INTEGER array, dimension (4) */
146 /* A count of the total number of the various types of columns */
147 /* in U (or rows in VT), as described in IDXC. The fourth column */
148 /* type is any column which has been deflated. */
150 /* Z (input/output) REAL array, dimension (K) */
151 /* The first K elements of this array contain the components */
152 /* of the deflation-adjusted updating row vector. */
154 /* INFO (output) INTEGER */
155 /* = 0: successful exit. */
156 /* < 0: if INFO = -i, the i-th argument had an illegal value. */
157 /* > 0: if INFO = 1, an singular value did not converge */
159 /* Further Details */
160 /* =============== */
162 /* Based on contributions by */
163 /* Ming Gu and Huan Ren, Computer Science Division, University of */
164 /* California at Berkeley, USA */
166 /* ===================================================================== */
168 /* .. Parameters .. */
170 /* .. Local Scalars .. */
172 /* .. External Functions .. */
174 /* .. External Subroutines .. */
176 /* .. Intrinsic Functions .. */
178 /* .. Executable Statements .. */
180 /* Test the input parameters. */
182 /* Parameter adjustments */
185 q_offset = 1 + q_dim1;
189 u_offset = 1 + u_dim1;
192 u2_offset = 1 + u2_dim1;
195 vt_offset = 1 + vt_dim1;
198 vt2_offset = 1 + vt2_dim1;
209 } else if (*nr < 1) {
211 } else if (*sqre != 1 && *sqre != 0) {
220 if (*k < 1 || *k > n) {
222 } else if (*ldq < *k) {
224 } else if (*ldu < n) {
226 } else if (*ldu2 < n) {
228 } else if (*ldvt < m) {
230 } else if (*ldvt2 < m) {
235 xerbla_("SLASD3", &i__1);
239 /* Quick return if possible */
242 d__[1] = dabs(z__[1]);
243 scopy_(&m, &vt2[vt2_dim1 + 1], ldvt2, &vt[vt_dim1 + 1], ldvt);
245 scopy_(&n, &u2[u2_dim1 + 1], &c__1, &u[u_dim1 + 1], &c__1);
248 for (i__ = 1; i__ <= i__1; ++i__) {
249 u[i__ + u_dim1] = -u2[i__ + u2_dim1];
256 /* Modify values DSIGMA(i) to make sure all DSIGMA(i)-DSIGMA(j) can */
257 /* be computed with high relative accuracy (barring over/underflow). */
258 /* This is a problem on machines without a guard digit in */
259 /* add/subtract (Cray XMP, Cray YMP, Cray C 90 and Cray 2). */
260 /* The following code replaces DSIGMA(I) by 2*DSIGMA(I)-DSIGMA(I), */
261 /* which on any of these machines zeros out the bottommost */
262 /* bit of DSIGMA(I) if it is 1; this makes the subsequent */
263 /* subtractions DSIGMA(I)-DSIGMA(J) unproblematic when cancellation */
264 /* occurs. On binary machines with a guard digit (almost all */
265 /* machines) it does not change DSIGMA(I) at all. On hexadecimal */
266 /* and decimal machines with a guard digit, it slightly */
267 /* changes the bottommost bits of DSIGMA(I). It does not account */
268 /* for hexadecimal or decimal machines without guard digits */
269 /* (we know of none). We use a subroutine call to compute */
270 /* 2*DSIGMA(I) to prevent optimizing compilers from eliminating */
274 for (i__ = 1; i__ <= i__1; ++i__) {
275 dsigma[i__] = slamc3_(&dsigma[i__], &dsigma[i__]) - dsigma[i__];
279 /* Keep a copy of Z. */
281 scopy_(k, &z__[1], &c__1, &q[q_offset], &c__1);
285 rho = snrm2_(k, &z__[1], &c__1);
286 slascl_("G", &c__0, &c__0, &rho, &c_b13, k, &c__1, &z__[1], k, info);
289 /* Find the new singular values. */
292 for (j = 1; j <= i__1; ++j) {
293 slasd4_(k, &j, &dsigma[1], &z__[1], &u[j * u_dim1 + 1], &rho, &d__[j],
294 &vt[j * vt_dim1 + 1], info);
296 /* If the zero finder fails, the computation is terminated. */
304 /* Compute updated Z. */
307 for (i__ = 1; i__ <= i__1; ++i__) {
308 z__[i__] = u[i__ + *k * u_dim1] * vt[i__ + *k * vt_dim1];
310 for (j = 1; j <= i__2; ++j) {
311 z__[i__] *= u[i__ + j * u_dim1] * vt[i__ + j * vt_dim1] / (dsigma[
312 i__] - dsigma[j]) / (dsigma[i__] + dsigma[j]);
316 for (j = i__; j <= i__2; ++j) {
317 z__[i__] *= u[i__ + j * u_dim1] * vt[i__ + j * vt_dim1] / (dsigma[
318 i__] - dsigma[j + 1]) / (dsigma[i__] + dsigma[j + 1]);
321 r__2 = sqrt((r__1 = z__[i__], dabs(r__1)));
322 z__[i__] = r_sign(&r__2, &q[i__ + q_dim1]);
326 /* Compute left singular vectors of the modified diagonal matrix, */
327 /* and store related information for the right singular vectors. */
330 for (i__ = 1; i__ <= i__1; ++i__) {
331 vt[i__ * vt_dim1 + 1] = z__[1] / u[i__ * u_dim1 + 1] / vt[i__ *
333 u[i__ * u_dim1 + 1] = -1.f;
335 for (j = 2; j <= i__2; ++j) {
336 vt[j + i__ * vt_dim1] = z__[j] / u[j + i__ * u_dim1] / vt[j + i__
338 u[j + i__ * u_dim1] = dsigma[j] * vt[j + i__ * vt_dim1];
341 temp = snrm2_(k, &u[i__ * u_dim1 + 1], &c__1);
342 q[i__ * q_dim1 + 1] = u[i__ * u_dim1 + 1] / temp;
344 for (j = 2; j <= i__2; ++j) {
346 q[j + i__ * q_dim1] = u[jc + i__ * u_dim1] / temp;
352 /* Update the left singular vector matrix. */
355 sgemm_("N", "N", &n, k, k, &c_b13, &u2[u2_offset], ldu2, &q[q_offset],
356 ldq, &c_b26, &u[u_offset], ldu);
360 sgemm_("N", "N", nl, k, &ctot[1], &c_b13, &u2[(u2_dim1 << 1) + 1],
361 ldu2, &q[q_dim1 + 2], ldq, &c_b26, &u[u_dim1 + 1], ldu);
363 ktemp = ctot[1] + 2 + ctot[2];
364 sgemm_("N", "N", nl, k, &ctot[3], &c_b13, &u2[ktemp * u2_dim1 + 1]
365 , ldu2, &q[ktemp + q_dim1], ldq, &c_b13, &u[u_dim1 + 1],
368 } else if (ctot[3] > 0) {
369 ktemp = ctot[1] + 2 + ctot[2];
370 sgemm_("N", "N", nl, k, &ctot[3], &c_b13, &u2[ktemp * u2_dim1 + 1],
371 ldu2, &q[ktemp + q_dim1], ldq, &c_b26, &u[u_dim1 + 1], ldu);
373 slacpy_("F", nl, k, &u2[u2_offset], ldu2, &u[u_offset], ldu);
375 scopy_(k, &q[q_dim1 + 1], ldq, &u[nlp1 + u_dim1], ldu);
377 ctemp = ctot[2] + ctot[3];
378 sgemm_("N", "N", nr, k, &ctemp, &c_b13, &u2[nlp2 + ktemp * u2_dim1], ldu2,
379 &q[ktemp + q_dim1], ldq, &c_b26, &u[nlp2 + u_dim1], ldu);
381 /* Generate the right singular vectors. */
385 for (i__ = 1; i__ <= i__1; ++i__) {
386 temp = snrm2_(k, &vt[i__ * vt_dim1 + 1], &c__1);
387 q[i__ + q_dim1] = vt[i__ * vt_dim1 + 1] / temp;
389 for (j = 2; j <= i__2; ++j) {
391 q[i__ + j * q_dim1] = vt[jc + i__ * vt_dim1] / temp;
397 /* Update the right singular vector matrix. */
400 sgemm_("N", "N", k, &m, k, &c_b13, &q[q_offset], ldq, &vt2[vt2_offset]
401 , ldvt2, &c_b26, &vt[vt_offset], ldvt);
405 sgemm_("N", "N", k, &nlp1, &ktemp, &c_b13, &q[q_dim1 + 1], ldq, &vt2[
406 vt2_dim1 + 1], ldvt2, &c_b26, &vt[vt_dim1 + 1], ldvt);
407 ktemp = ctot[1] + 2 + ctot[2];
408 if (ktemp <= *ldvt2) {
409 sgemm_("N", "N", k, &nlp1, &ctot[3], &c_b13, &q[ktemp * q_dim1 + 1],
410 ldq, &vt2[ktemp + vt2_dim1], ldvt2, &c_b13, &vt[vt_dim1 + 1],
418 for (i__ = 1; i__ <= i__1; ++i__) {
419 q[i__ + ktemp * q_dim1] = q[i__ + q_dim1];
423 for (i__ = nlp2; i__ <= i__1; ++i__) {
424 vt2[ktemp + i__ * vt2_dim1] = vt2[i__ * vt2_dim1 + 1];
428 ctemp = ctot[2] + 1 + ctot[3];
429 sgemm_("N", "N", k, &nrp1, &ctemp, &c_b13, &q[ktemp * q_dim1 + 1], ldq, &
430 vt2[ktemp + nlp2 * vt2_dim1], ldvt2, &c_b26, &vt[nlp2 * vt_dim1 +