3 /* Table of constant values */
5 static integer c__0 = 0;
6 static doublereal c_b11 = 0.;
7 static doublereal c_b12 = 1.;
8 static integer c__1 = 1;
9 static integer c__2 = 2;
11 /* Subroutine */ int dlasda_(integer *icompq, integer *smlsiz, integer *n,
12 integer *sqre, doublereal *d__, doublereal *e, doublereal *u, integer
13 *ldu, doublereal *vt, integer *k, doublereal *difl, doublereal *difr,
14 doublereal *z__, doublereal *poles, integer *givptr, integer *givcol,
15 integer *ldgcol, integer *perm, doublereal *givnum, doublereal *c__,
16 doublereal *s, doublereal *work, integer *iwork, integer *info)
18 /* System generated locals */
19 integer givcol_dim1, givcol_offset, perm_dim1, perm_offset, difl_dim1,
20 difl_offset, difr_dim1, difr_offset, givnum_dim1, givnum_offset,
21 poles_dim1, poles_offset, u_dim1, u_offset, vt_dim1, vt_offset,
22 z_dim1, z_offset, i__1, i__2;
24 /* Builtin functions */
25 integer pow_ii(integer *, integer *);
28 integer i__, j, m, i1, ic, lf, nd, ll, nl, vf, nr, vl, im1, ncc, nlf, nrf,
29 vfi, iwk, vli, lvl, nru, ndb1, nlp1, lvl2, nrp1;
33 integer inode, ndiml, ndimr, idxqi, itemp;
34 extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
35 doublereal *, integer *);
37 extern /* Subroutine */ int dlasd6_(integer *, integer *, integer *,
38 integer *, doublereal *, doublereal *, doublereal *, doublereal *,
39 doublereal *, integer *, integer *, integer *, integer *,
40 integer *, doublereal *, integer *, doublereal *, doublereal *,
41 doublereal *, doublereal *, integer *, doublereal *, doublereal *,
42 doublereal *, integer *, integer *);
43 integer nwork1, nwork2;
44 extern /* Subroutine */ int dlasdq_(char *, integer *, integer *, integer
45 *, integer *, integer *, doublereal *, doublereal *, doublereal *,
46 integer *, doublereal *, integer *, doublereal *, integer *,
47 doublereal *, integer *), dlasdt_(integer *, integer *,
48 integer *, integer *, integer *, integer *, integer *), dlaset_(
49 char *, integer *, integer *, doublereal *, doublereal *,
50 doublereal *, integer *), xerbla_(char *, integer *);
54 /* -- LAPACK auxiliary routine (version 3.1) -- */
55 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
58 /* .. Scalar Arguments .. */
60 /* .. Array Arguments .. */
66 /* Using a divide and conquer approach, DLASDA computes the singular */
67 /* value decomposition (SVD) of a real upper bidiagonal N-by-M matrix */
68 /* B with diagonal D and offdiagonal E, where M = N + SQRE. The */
69 /* algorithm computes the singular values in the SVD B = U * S * VT. */
70 /* The orthogonal matrices U and VT are optionally computed in */
73 /* A related subroutine, DLASD0, computes the singular values and */
74 /* the singular vectors in explicit form. */
79 /* ICOMPQ (input) INTEGER */
80 /* Specifies whether singular vectors are to be computed */
81 /* in compact form, as follows */
82 /* = 0: Compute singular values only. */
83 /* = 1: Compute singular vectors of upper bidiagonal */
84 /* matrix in compact form. */
86 /* SMLSIZ (input) INTEGER */
87 /* The maximum size of the subproblems at the bottom of the */
88 /* computation tree. */
90 /* N (input) INTEGER */
91 /* The row dimension of the upper bidiagonal matrix. This is */
92 /* also the dimension of the main diagonal array D. */
94 /* SQRE (input) INTEGER */
95 /* Specifies the column dimension of the bidiagonal matrix. */
96 /* = 0: The bidiagonal matrix has column dimension M = N; */
97 /* = 1: The bidiagonal matrix has column dimension M = N + 1. */
99 /* D (input/output) DOUBLE PRECISION array, dimension ( N ) */
100 /* On entry D contains the main diagonal of the bidiagonal */
101 /* matrix. On exit D, if INFO = 0, contains its singular values. */
103 /* E (input) DOUBLE PRECISION array, dimension ( M-1 ) */
104 /* Contains the subdiagonal entries of the bidiagonal matrix. */
105 /* On exit, E has been destroyed. */
107 /* U (output) DOUBLE PRECISION array, */
108 /* dimension ( LDU, SMLSIZ ) if ICOMPQ = 1, and not referenced */
109 /* if ICOMPQ = 0. If ICOMPQ = 1, on exit, U contains the left */
110 /* singular vector matrices of all subproblems at the bottom */
113 /* LDU (input) INTEGER, LDU = > N. */
114 /* The leading dimension of arrays U, VT, DIFL, DIFR, POLES, */
117 /* VT (output) DOUBLE PRECISION array, */
118 /* dimension ( LDU, SMLSIZ+1 ) if ICOMPQ = 1, and not referenced */
119 /* if ICOMPQ = 0. If ICOMPQ = 1, on exit, VT' contains the right */
120 /* singular vector matrices of all subproblems at the bottom */
123 /* K (output) INTEGER array, */
124 /* dimension ( N ) if ICOMPQ = 1 and dimension 1 if ICOMPQ = 0. */
125 /* If ICOMPQ = 1, on exit, K(I) is the dimension of the I-th */
126 /* secular equation on the computation tree. */
128 /* DIFL (output) DOUBLE PRECISION array, dimension ( LDU, NLVL ), */
129 /* where NLVL = floor(log_2 (N/SMLSIZ))). */
131 /* DIFR (output) DOUBLE PRECISION array, */
132 /* dimension ( LDU, 2 * NLVL ) if ICOMPQ = 1 and */
133 /* dimension ( N ) if ICOMPQ = 0. */
134 /* If ICOMPQ = 1, on exit, DIFL(1:N, I) and DIFR(1:N, 2 * I - 1) */
135 /* record distances between singular values on the I-th */
136 /* level and singular values on the (I -1)-th level, and */
137 /* DIFR(1:N, 2 * I ) contains the normalizing factors for */
138 /* the right singular vector matrix. See DLASD8 for details. */
140 /* Z (output) DOUBLE PRECISION array, */
141 /* dimension ( LDU, NLVL ) if ICOMPQ = 1 and */
142 /* dimension ( N ) if ICOMPQ = 0. */
143 /* The first K elements of Z(1, I) contain the components of */
144 /* the deflation-adjusted updating row vector for subproblems */
145 /* on the I-th level. */
147 /* POLES (output) DOUBLE PRECISION array, */
148 /* dimension ( LDU, 2 * NLVL ) if ICOMPQ = 1, and not referenced */
149 /* if ICOMPQ = 0. If ICOMPQ = 1, on exit, POLES(1, 2*I - 1) and */
150 /* POLES(1, 2*I) contain the new and old singular values */
151 /* involved in the secular equations on the I-th level. */
153 /* GIVPTR (output) INTEGER array, */
154 /* dimension ( N ) if ICOMPQ = 1, and not referenced if */
155 /* ICOMPQ = 0. If ICOMPQ = 1, on exit, GIVPTR( I ) records */
156 /* the number of Givens rotations performed on the I-th */
157 /* problem on the computation tree. */
159 /* GIVCOL (output) INTEGER array, */
160 /* dimension ( LDGCOL, 2 * NLVL ) if ICOMPQ = 1, and not */
161 /* referenced if ICOMPQ = 0. If ICOMPQ = 1, on exit, for each I, */
162 /* GIVCOL(1, 2 *I - 1) and GIVCOL(1, 2 *I) record the locations */
163 /* of Givens rotations performed on the I-th level on the */
164 /* computation tree. */
166 /* LDGCOL (input) INTEGER, LDGCOL = > N. */
167 /* The leading dimension of arrays GIVCOL and PERM. */
169 /* PERM (output) INTEGER array, */
170 /* dimension ( LDGCOL, NLVL ) if ICOMPQ = 1, and not referenced */
171 /* if ICOMPQ = 0. If ICOMPQ = 1, on exit, PERM(1, I) records */
172 /* permutations done on the I-th level of the computation tree. */
174 /* GIVNUM (output) DOUBLE PRECISION array, */
175 /* dimension ( LDU, 2 * NLVL ) if ICOMPQ = 1, and not */
176 /* referenced if ICOMPQ = 0. If ICOMPQ = 1, on exit, for each I, */
177 /* GIVNUM(1, 2 *I - 1) and GIVNUM(1, 2 *I) record the C- and S- */
178 /* values of Givens rotations performed on the I-th level on */
179 /* the computation tree. */
181 /* C (output) DOUBLE PRECISION array, */
182 /* dimension ( N ) if ICOMPQ = 1, and dimension 1 if ICOMPQ = 0. */
183 /* If ICOMPQ = 1 and the I-th subproblem is not square, on exit, */
184 /* C( I ) contains the C-value of a Givens rotation related to */
185 /* the right null space of the I-th subproblem. */
187 /* S (output) DOUBLE PRECISION array, dimension ( N ) if */
188 /* ICOMPQ = 1, and dimension 1 if ICOMPQ = 0. If ICOMPQ = 1 */
189 /* and the I-th subproblem is not square, on exit, S( I ) */
190 /* contains the S-value of a Givens rotation related to */
191 /* the right null space of the I-th subproblem. */
193 /* WORK (workspace) DOUBLE PRECISION array, dimension */
194 /* (6 * N + (SMLSIZ + 1)*(SMLSIZ + 1)). */
196 /* IWORK (workspace) INTEGER array. */
197 /* Dimension must be at least (7 * N). */
199 /* INFO (output) INTEGER */
200 /* = 0: successful exit. */
201 /* < 0: if INFO = -i, the i-th argument had an illegal value. */
202 /* > 0: if INFO = 1, an singular value did not converge */
204 /* Further Details */
205 /* =============== */
207 /* Based on contributions by */
208 /* Ming Gu and Huan Ren, Computer Science Division, University of */
209 /* California at Berkeley, USA */
211 /* ===================================================================== */
213 /* .. Parameters .. */
215 /* .. Local Scalars .. */
217 /* .. External Subroutines .. */
219 /* .. Executable Statements .. */
221 /* Test the input parameters. */
223 /* Parameter adjustments */
227 givnum_offset = 1 + givnum_dim1;
228 givnum -= givnum_offset;
230 poles_offset = 1 + poles_dim1;
231 poles -= poles_offset;
233 z_offset = 1 + z_dim1;
236 difr_offset = 1 + difr_dim1;
239 difl_offset = 1 + difl_dim1;
242 vt_offset = 1 + vt_dim1;
245 u_offset = 1 + u_dim1;
250 perm_offset = 1 + perm_dim1;
252 givcol_dim1 = *ldgcol;
253 givcol_offset = 1 + givcol_dim1;
254 givcol -= givcol_offset;
263 if (*icompq < 0 || *icompq > 1) {
265 } else if (*smlsiz < 3) {
269 } else if (*sqre < 0 || *sqre > 1) {
271 } else if (*ldu < *n + *sqre) {
273 } else if (*ldgcol < *n) {
278 xerbla_("DLASDA", &i__1);
284 /* If the input matrix is too small, call DLASDQ to find the SVD. */
288 dlasdq_("U", sqre, n, &c__0, &c__0, &c__0, &d__[1], &e[1], &vt[
289 vt_offset], ldu, &u[u_offset], ldu, &u[u_offset], ldu, &
292 dlasdq_("U", sqre, n, &m, n, &c__0, &d__[1], &e[1], &vt[vt_offset]
293 , ldu, &u[u_offset], ldu, &u[u_offset], ldu, &work[1],
299 /* Book-keeping and set up the computation tree. */
310 smlszp = *smlsiz + 1;
314 nwork2 = nwork1 + smlszp * smlszp;
316 dlasdt_(n, &nlvl, &nd, &iwork[inode], &iwork[ndiml], &iwork[ndimr],
319 /* for the nodes on bottom level of the tree, solve */
320 /* their subproblems by DLASDQ. */
324 for (i__ = ndb1; i__ <= i__1; ++i__) {
326 /* IC : center row of each node */
327 /* NL : number of rows of left subproblem */
328 /* NR : number of rows of right subproblem */
329 /* NLF: starting row of the left subproblem */
330 /* NRF: starting row of the right subproblem */
333 ic = iwork[inode + i1];
334 nl = iwork[ndiml + i1];
336 nr = iwork[ndimr + i1];
339 idxqi = idxq + nlf - 2;
344 dlaset_("A", &nlp1, &nlp1, &c_b11, &c_b12, &work[nwork1], &smlszp);
345 dlasdq_("U", &sqrei, &nl, &nlp1, &nru, &ncc, &d__[nlf], &e[nlf], &
346 work[nwork1], &smlszp, &work[nwork2], &nl, &work[nwork2],
347 &nl, &work[nwork2], info);
348 itemp = nwork1 + nl * smlszp;
349 dcopy_(&nlp1, &work[nwork1], &c__1, &work[vfi], &c__1);
350 dcopy_(&nlp1, &work[itemp], &c__1, &work[vli], &c__1);
352 dlaset_("A", &nl, &nl, &c_b11, &c_b12, &u[nlf + u_dim1], ldu);
353 dlaset_("A", &nlp1, &nlp1, &c_b11, &c_b12, &vt[nlf + vt_dim1],
355 dlasdq_("U", &sqrei, &nl, &nlp1, &nl, &ncc, &d__[nlf], &e[nlf], &
356 vt[nlf + vt_dim1], ldu, &u[nlf + u_dim1], ldu, &u[nlf +
357 u_dim1], ldu, &work[nwork1], info);
358 dcopy_(&nlp1, &vt[nlf + vt_dim1], &c__1, &work[vfi], &c__1);
359 dcopy_(&nlp1, &vt[nlf + nlp1 * vt_dim1], &c__1, &work[vli], &c__1)
366 for (j = 1; j <= i__2; ++j) {
367 iwork[idxqi + j] = j;
370 if (i__ == nd && *sqre == 0) {
380 dlaset_("A", &nrp1, &nrp1, &c_b11, &c_b12, &work[nwork1], &smlszp);
381 dlasdq_("U", &sqrei, &nr, &nrp1, &nru, &ncc, &d__[nrf], &e[nrf], &
382 work[nwork1], &smlszp, &work[nwork2], &nr, &work[nwork2],
383 &nr, &work[nwork2], info);
384 itemp = nwork1 + (nrp1 - 1) * smlszp;
385 dcopy_(&nrp1, &work[nwork1], &c__1, &work[vfi], &c__1);
386 dcopy_(&nrp1, &work[itemp], &c__1, &work[vli], &c__1);
388 dlaset_("A", &nr, &nr, &c_b11, &c_b12, &u[nrf + u_dim1], ldu);
389 dlaset_("A", &nrp1, &nrp1, &c_b11, &c_b12, &vt[nrf + vt_dim1],
391 dlasdq_("U", &sqrei, &nr, &nrp1, &nr, &ncc, &d__[nrf], &e[nrf], &
392 vt[nrf + vt_dim1], ldu, &u[nrf + u_dim1], ldu, &u[nrf +
393 u_dim1], ldu, &work[nwork1], info);
394 dcopy_(&nrp1, &vt[nrf + vt_dim1], &c__1, &work[vfi], &c__1);
395 dcopy_(&nrp1, &vt[nrf + nrp1 * vt_dim1], &c__1, &work[vli], &c__1)
402 for (j = 1; j <= i__2; ++j) {
403 iwork[idxqi + j] = j;
409 /* Now conquer each subproblem bottom-up. */
411 j = pow_ii(&c__2, &nlvl);
412 for (lvl = nlvl; lvl >= 1; --lvl) {
413 lvl2 = (lvl << 1) - 1;
415 /* Find the first node LF and last node LL on */
416 /* the current level LVL. */
423 lf = pow_ii(&c__2, &i__1);
427 for (i__ = lf; i__ <= i__1; ++i__) {
429 ic = iwork[inode + im1];
430 nl = iwork[ndiml + im1];
431 nr = iwork[ndimr + im1];
441 idxqi = idxq + nlf - 1;
445 dlasd6_(icompq, &nl, &nr, &sqrei, &d__[nlf], &work[vfi], &
446 work[vli], &alpha, &beta, &iwork[idxqi], &perm[
447 perm_offset], &givptr[1], &givcol[givcol_offset],
448 ldgcol, &givnum[givnum_offset], ldu, &poles[
449 poles_offset], &difl[difl_offset], &difr[difr_offset],
450 &z__[z_offset], &k[1], &c__[1], &s[1], &work[nwork1],
454 dlasd6_(icompq, &nl, &nr, &sqrei, &d__[nlf], &work[vfi], &
455 work[vli], &alpha, &beta, &iwork[idxqi], &perm[nlf +
456 lvl * perm_dim1], &givptr[j], &givcol[nlf + lvl2 *
457 givcol_dim1], ldgcol, &givnum[nlf + lvl2 *
458 givnum_dim1], ldu, &poles[nlf + lvl2 * poles_dim1], &
459 difl[nlf + lvl * difl_dim1], &difr[nlf + lvl2 *
460 difr_dim1], &z__[nlf + lvl * z_dim1], &k[j], &c__[j],
461 &s[j], &work[nwork1], &iwork[iwk], info);