3 /* Table of constant values */
5 static integer c__1 = 1;
6 static integer c__0 = 0;
7 static doublereal c_b13 = 1.;
8 static doublereal c_b26 = 0.;
10 /* Subroutine */ int dlasd3_(integer *nl, integer *nr, integer *sqre, integer
11 *k, doublereal *d__, doublereal *q, integer *ldq, doublereal *dsigma,
12 doublereal *u, integer *ldu, doublereal *u2, integer *ldu2,
13 doublereal *vt, integer *ldvt, doublereal *vt2, integer *ldvt2,
14 integer *idxc, integer *ctot, doublereal *z__, integer *info)
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;
19 doublereal d__1, d__2;
21 /* Builtin functions */
22 double sqrt(doublereal), d_sign(doublereal *, doublereal *);
25 integer i__, j, m, n, jc;
27 integer nlp1, nlp2, nrp1;
29 extern doublereal dnrm2_(integer *, doublereal *, integer *);
30 extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
31 integer *, doublereal *, doublereal *, integer *, doublereal *,
32 integer *, doublereal *, doublereal *, integer *);
34 extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
35 doublereal *, integer *);
37 extern doublereal dlamc3_(doublereal *, doublereal *);
38 extern /* Subroutine */ int dlasd4_(integer *, integer *, doublereal *,
39 doublereal *, doublereal *, doublereal *, doublereal *,
40 doublereal *, integer *), dlascl_(char *, integer *, integer *,
41 doublereal *, doublereal *, integer *, integer *, doublereal *,
42 integer *, integer *), dlacpy_(char *, integer *, integer
43 *, doublereal *, integer *, doublereal *, integer *),
44 xerbla_(char *, integer *);
47 /* -- LAPACK auxiliary routine (version 3.1) -- */
48 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
51 /* .. Scalar Arguments .. */
53 /* .. Array Arguments .. */
59 /* DLASD3 finds all the square roots of the roots of the secular */
60 /* equation, as defined by the values in D and Z. It makes the */
61 /* appropriate calls to DLASD4 and then updates the singular */
62 /* vectors by matrix multiplication. */
64 /* This code makes very mild assumptions about floating point */
65 /* arithmetic. It will work on machines with a guard digit in */
66 /* add/subtract, or on those binary machines without guard digits */
67 /* which subtract like the Cray XMP, Cray YMP, Cray C 90, or Cray 2. */
68 /* It could conceivably fail on hexadecimal or decimal machines */
69 /* without guard digits, but we know of none. */
71 /* DLASD3 is called from DLASD1. */
76 /* NL (input) INTEGER */
77 /* The row dimension of the upper block. NL >= 1. */
79 /* NR (input) INTEGER */
80 /* The row dimension of the lower block. NR >= 1. */
82 /* SQRE (input) INTEGER */
83 /* = 0: the lower block is an NR-by-NR square matrix. */
84 /* = 1: the lower block is an NR-by-(NR+1) rectangular matrix. */
86 /* The bidiagonal matrix has N = NL + NR + 1 rows and */
87 /* M = N + SQRE >= N columns. */
89 /* K (input) INTEGER */
90 /* The size of the secular equation, 1 =< K = < N. */
92 /* D (output) DOUBLE PRECISION array, dimension(K) */
93 /* On exit the square roots of the roots of the secular equation, */
94 /* in ascending order. */
96 /* Q (workspace) DOUBLE PRECISION array, */
97 /* dimension at least (LDQ,K). */
99 /* LDQ (input) INTEGER */
100 /* The leading dimension of the array Q. LDQ >= K. */
102 /* DSIGMA (input) DOUBLE PRECISION array, dimension(K) */
103 /* The first K elements of this array contain the old roots */
104 /* of the deflated updating problem. These are the poles */
105 /* of the secular equation. */
107 /* U (output) DOUBLE PRECISION array, dimension (LDU, N) */
108 /* The last N - K columns of this matrix contain the deflated */
109 /* left singular vectors. */
111 /* LDU (input) INTEGER */
112 /* The leading dimension of the array U. LDU >= N. */
114 /* U2 (input/output) DOUBLE PRECISION array, dimension (LDU2, N) */
115 /* The first K columns of this matrix contain the non-deflated */
116 /* left singular vectors for the split problem. */
118 /* LDU2 (input) INTEGER */
119 /* The leading dimension of the array U2. LDU2 >= N. */
121 /* VT (output) DOUBLE PRECISION array, dimension (LDVT, M) */
122 /* The last M - K columns of VT' contain the deflated */
123 /* right singular vectors. */
125 /* LDVT (input) INTEGER */
126 /* The leading dimension of the array VT. LDVT >= N. */
128 /* VT2 (input/output) DOUBLE PRECISION array, dimension (LDVT2, N) */
129 /* The first K columns of VT2' contain the non-deflated */
130 /* right singular vectors for the split problem. */
132 /* LDVT2 (input) INTEGER */
133 /* The leading dimension of the array VT2. LDVT2 >= N. */
135 /* IDXC (input) INTEGER array, dimension ( N ) */
136 /* The permutation used to arrange the columns of U (and rows of */
137 /* VT) into three groups: the first group contains non-zero */
138 /* entries only at and above (or before) NL +1; the second */
139 /* contains non-zero entries only at and below (or after) NL+2; */
140 /* and the third is dense. The first column of U and the row of */
141 /* VT are treated separately, however. */
143 /* The rows of the singular vectors found by DLASD4 */
144 /* must be likewise permuted before the matrix multiplies can */
147 /* CTOT (input) INTEGER array, dimension ( 4 ) */
148 /* A count of the total number of the various types of columns */
149 /* in U (or rows in VT), as described in IDXC. The fourth column */
150 /* type is any column which has been deflated. */
152 /* Z (input) DOUBLE PRECISION array, dimension (K) */
153 /* The first K elements of this array contain the components */
154 /* of the deflation-adjusted updating row vector. */
156 /* INFO (output) INTEGER */
157 /* = 0: successful exit. */
158 /* < 0: if INFO = -i, the i-th argument had an illegal value. */
159 /* > 0: if INFO = 1, an singular value did not converge */
161 /* Further Details */
162 /* =============== */
164 /* Based on contributions by */
165 /* Ming Gu and Huan Ren, Computer Science Division, University of */
166 /* California at Berkeley, USA */
168 /* ===================================================================== */
170 /* .. Parameters .. */
172 /* .. Local Scalars .. */
174 /* .. External Functions .. */
176 /* .. External Subroutines .. */
178 /* .. Intrinsic Functions .. */
180 /* .. Executable Statements .. */
182 /* Test the input parameters. */
184 /* Parameter adjustments */
187 q_offset = 1 + q_dim1;
191 u_offset = 1 + u_dim1;
194 u2_offset = 1 + u2_dim1;
197 vt_offset = 1 + vt_dim1;
200 vt2_offset = 1 + vt2_dim1;
211 } else if (*nr < 1) {
213 } else if (*sqre != 1 && *sqre != 0) {
222 if (*k < 1 || *k > n) {
224 } else if (*ldq < *k) {
226 } else if (*ldu < n) {
228 } else if (*ldu2 < n) {
230 } else if (*ldvt < m) {
232 } else if (*ldvt2 < m) {
237 xerbla_("DLASD3", &i__1);
241 /* Quick return if possible */
244 d__[1] = abs(z__[1]);
245 dcopy_(&m, &vt2[vt2_dim1 + 1], ldvt2, &vt[vt_dim1 + 1], ldvt);
247 dcopy_(&n, &u2[u2_dim1 + 1], &c__1, &u[u_dim1 + 1], &c__1);
250 for (i__ = 1; i__ <= i__1; ++i__) {
251 u[i__ + u_dim1] = -u2[i__ + u2_dim1];
258 /* Modify values DSIGMA(i) to make sure all DSIGMA(i)-DSIGMA(j) can */
259 /* be computed with high relative accuracy (barring over/underflow). */
260 /* This is a problem on machines without a guard digit in */
261 /* add/subtract (Cray XMP, Cray YMP, Cray C 90 and Cray 2). */
262 /* The following code replaces DSIGMA(I) by 2*DSIGMA(I)-DSIGMA(I), */
263 /* which on any of these machines zeros out the bottommost */
264 /* bit of DSIGMA(I) if it is 1; this makes the subsequent */
265 /* subtractions DSIGMA(I)-DSIGMA(J) unproblematic when cancellation */
266 /* occurs. On binary machines with a guard digit (almost all */
267 /* machines) it does not change DSIGMA(I) at all. On hexadecimal */
268 /* and decimal machines with a guard digit, it slightly */
269 /* changes the bottommost bits of DSIGMA(I). It does not account */
270 /* for hexadecimal or decimal machines without guard digits */
271 /* (we know of none). We use a subroutine call to compute */
272 /* 2*DSIGMA(I) to prevent optimizing compilers from eliminating */
276 for (i__ = 1; i__ <= i__1; ++i__) {
277 dsigma[i__] = dlamc3_(&dsigma[i__], &dsigma[i__]) - dsigma[i__];
281 /* Keep a copy of Z. */
283 dcopy_(k, &z__[1], &c__1, &q[q_offset], &c__1);
287 rho = dnrm2_(k, &z__[1], &c__1);
288 dlascl_("G", &c__0, &c__0, &rho, &c_b13, k, &c__1, &z__[1], k, info);
291 /* Find the new singular values. */
294 for (j = 1; j <= i__1; ++j) {
295 dlasd4_(k, &j, &dsigma[1], &z__[1], &u[j * u_dim1 + 1], &rho, &d__[j],
296 &vt[j * vt_dim1 + 1], info);
298 /* If the zero finder fails, the computation is terminated. */
306 /* Compute updated Z. */
309 for (i__ = 1; i__ <= i__1; ++i__) {
310 z__[i__] = u[i__ + *k * u_dim1] * vt[i__ + *k * vt_dim1];
312 for (j = 1; j <= i__2; ++j) {
313 z__[i__] *= u[i__ + j * u_dim1] * vt[i__ + j * vt_dim1] / (dsigma[
314 i__] - dsigma[j]) / (dsigma[i__] + dsigma[j]);
318 for (j = i__; j <= i__2; ++j) {
319 z__[i__] *= u[i__ + j * u_dim1] * vt[i__ + j * vt_dim1] / (dsigma[
320 i__] - dsigma[j + 1]) / (dsigma[i__] + dsigma[j + 1]);
323 d__2 = sqrt((d__1 = z__[i__], abs(d__1)));
324 z__[i__] = d_sign(&d__2, &q[i__ + q_dim1]);
328 /* Compute left singular vectors of the modified diagonal matrix, */
329 /* and store related information for the right singular vectors. */
332 for (i__ = 1; i__ <= i__1; ++i__) {
333 vt[i__ * vt_dim1 + 1] = z__[1] / u[i__ * u_dim1 + 1] / vt[i__ *
335 u[i__ * u_dim1 + 1] = -1.;
337 for (j = 2; j <= i__2; ++j) {
338 vt[j + i__ * vt_dim1] = z__[j] / u[j + i__ * u_dim1] / vt[j + i__
340 u[j + i__ * u_dim1] = dsigma[j] * vt[j + i__ * vt_dim1];
343 temp = dnrm2_(k, &u[i__ * u_dim1 + 1], &c__1);
344 q[i__ * q_dim1 + 1] = u[i__ * u_dim1 + 1] / temp;
346 for (j = 2; j <= i__2; ++j) {
348 q[j + i__ * q_dim1] = u[jc + i__ * u_dim1] / temp;
354 /* Update the left singular vector matrix. */
357 dgemm_("N", "N", &n, k, k, &c_b13, &u2[u2_offset], ldu2, &q[q_offset],
358 ldq, &c_b26, &u[u_offset], ldu);
362 dgemm_("N", "N", nl, k, &ctot[1], &c_b13, &u2[(u2_dim1 << 1) + 1],
363 ldu2, &q[q_dim1 + 2], ldq, &c_b26, &u[u_dim1 + 1], ldu);
365 ktemp = ctot[1] + 2 + ctot[2];
366 dgemm_("N", "N", nl, k, &ctot[3], &c_b13, &u2[ktemp * u2_dim1 + 1]
367 , ldu2, &q[ktemp + q_dim1], ldq, &c_b13, &u[u_dim1 + 1],
370 } else if (ctot[3] > 0) {
371 ktemp = ctot[1] + 2 + ctot[2];
372 dgemm_("N", "N", nl, k, &ctot[3], &c_b13, &u2[ktemp * u2_dim1 + 1],
373 ldu2, &q[ktemp + q_dim1], ldq, &c_b26, &u[u_dim1 + 1], ldu);
375 dlacpy_("F", nl, k, &u2[u2_offset], ldu2, &u[u_offset], ldu);
377 dcopy_(k, &q[q_dim1 + 1], ldq, &u[nlp1 + u_dim1], ldu);
379 ctemp = ctot[2] + ctot[3];
380 dgemm_("N", "N", nr, k, &ctemp, &c_b13, &u2[nlp2 + ktemp * u2_dim1], ldu2,
381 &q[ktemp + q_dim1], ldq, &c_b26, &u[nlp2 + u_dim1], ldu);
383 /* Generate the right singular vectors. */
387 for (i__ = 1; i__ <= i__1; ++i__) {
388 temp = dnrm2_(k, &vt[i__ * vt_dim1 + 1], &c__1);
389 q[i__ + q_dim1] = vt[i__ * vt_dim1 + 1] / temp;
391 for (j = 2; j <= i__2; ++j) {
393 q[i__ + j * q_dim1] = vt[jc + i__ * vt_dim1] / temp;
399 /* Update the right singular vector matrix. */
402 dgemm_("N", "N", k, &m, k, &c_b13, &q[q_offset], ldq, &vt2[vt2_offset]
403 , ldvt2, &c_b26, &vt[vt_offset], ldvt);
407 dgemm_("N", "N", k, &nlp1, &ktemp, &c_b13, &q[q_dim1 + 1], ldq, &vt2[
408 vt2_dim1 + 1], ldvt2, &c_b26, &vt[vt_dim1 + 1], ldvt);
409 ktemp = ctot[1] + 2 + ctot[2];
410 if (ktemp <= *ldvt2) {
411 dgemm_("N", "N", k, &nlp1, &ctot[3], &c_b13, &q[ktemp * q_dim1 + 1],
412 ldq, &vt2[ktemp + vt2_dim1], ldvt2, &c_b13, &vt[vt_dim1 + 1],
420 for (i__ = 1; i__ <= i__1; ++i__) {
421 q[i__ + ktemp * q_dim1] = q[i__ + q_dim1];
425 for (i__ = nlp2; i__ <= i__1; ++i__) {
426 vt2[ktemp + i__ * vt2_dim1] = vt2[i__ * vt2_dim1 + 1];
430 ctemp = ctot[2] + 1 + ctot[3];
431 dgemm_("N", "N", k, &nrp1, &ctemp, &c_b13, &q[ktemp * q_dim1 + 1], ldq, &
432 vt2[ktemp + nlp2 * vt2_dim1], ldvt2, &c_b26, &vt[nlp2 * vt_dim1 +