3 /* Table of constant values */
5 static doublereal c_b5 = -1.;
6 static integer c__1 = 1;
7 static doublereal c_b11 = 1.;
8 static doublereal c_b13 = 0.;
9 static integer c__0 = 0;
11 /* Subroutine */ int dlals0_(integer *icompq, integer *nl, integer *nr,
12 integer *sqre, integer *nrhs, doublereal *b, integer *ldb, doublereal
13 *bx, integer *ldbx, integer *perm, integer *givptr, integer *givcol,
14 integer *ldgcol, doublereal *givnum, integer *ldgnum, doublereal *
15 poles, doublereal *difl, doublereal *difr, doublereal *z__, integer *
16 k, doublereal *c__, doublereal *s, doublereal *work, integer *info)
18 /* System generated locals */
19 integer givcol_dim1, givcol_offset, b_dim1, b_offset, bx_dim1, bx_offset,
20 difr_dim1, difr_offset, givnum_dim1, givnum_offset, poles_dim1,
21 poles_offset, i__1, i__2;
29 extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
30 doublereal *, integer *, doublereal *, doublereal *);
31 extern doublereal dnrm2_(integer *, doublereal *, integer *);
32 extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
34 doublereal diflj, difrj, dsigj;
35 extern /* Subroutine */ int dgemv_(char *, integer *, integer *,
36 doublereal *, doublereal *, integer *, doublereal *, integer *,
37 doublereal *, doublereal *, integer *), dcopy_(integer *,
38 doublereal *, integer *, doublereal *, integer *);
39 extern doublereal dlamc3_(doublereal *, doublereal *);
40 extern /* Subroutine */ int 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 *);
48 /* -- LAPACK routine (version 3.1) -- */
49 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
52 /* .. Scalar Arguments .. */
54 /* .. Array Arguments .. */
60 /* DLALS0 applies back the multiplying factors of either the left or the */
61 /* right singular vector matrix of a diagonal matrix appended by a row */
62 /* to the right hand side matrix B in solving the least squares problem */
63 /* using the divide-and-conquer SVD approach. */
65 /* For the left singular vector matrix, three types of orthogonal */
66 /* matrices are involved: */
68 /* (1L) Givens rotations: the number of such rotations is GIVPTR; the */
69 /* pairs of columns/rows they were applied to are stored in GIVCOL; */
70 /* and the C- and S-values of these rotations are stored in GIVNUM. */
72 /* (2L) Permutation. The (NL+1)-st row of B is to be moved to the first */
73 /* row, and for J=2:N, PERM(J)-th row of B is to be moved to the */
76 /* (3L) The left singular vector matrix of the remaining matrix. */
78 /* For the right singular vector matrix, four types of orthogonal */
79 /* matrices are involved: */
81 /* (1R) The right singular vector matrix of the remaining matrix. */
83 /* (2R) If SQRE = 1, one extra Givens rotation to generate the right */
86 /* (3R) The inverse transformation of (2L). */
88 /* (4R) The inverse transformation of (1L). */
93 /* ICOMPQ (input) INTEGER */
94 /* Specifies whether singular vectors are to be computed in */
96 /* = 0: Left singular vector matrix. */
97 /* = 1: Right singular vector matrix. */
99 /* NL (input) INTEGER */
100 /* The row dimension of the upper block. NL >= 1. */
102 /* NR (input) INTEGER */
103 /* The row dimension of the lower block. NR >= 1. */
105 /* SQRE (input) INTEGER */
106 /* = 0: the lower block is an NR-by-NR square matrix. */
107 /* = 1: the lower block is an NR-by-(NR+1) rectangular matrix. */
109 /* The bidiagonal matrix has row dimension N = NL + NR + 1, */
110 /* and column dimension M = N + SQRE. */
112 /* NRHS (input) INTEGER */
113 /* The number of columns of B and BX. NRHS must be at least 1. */
115 /* B (input/output) DOUBLE PRECISION array, dimension ( LDB, NRHS ) */
116 /* On input, B contains the right hand sides of the least */
117 /* squares problem in rows 1 through M. On output, B contains */
118 /* the solution X in rows 1 through N. */
120 /* LDB (input) INTEGER */
121 /* The leading dimension of B. LDB must be at least */
122 /* max(1,MAX( M, N ) ). */
124 /* BX (workspace) DOUBLE PRECISION array, dimension ( LDBX, NRHS ) */
126 /* LDBX (input) INTEGER */
127 /* The leading dimension of BX. */
129 /* PERM (input) INTEGER array, dimension ( N ) */
130 /* The permutations (from deflation and sorting) applied */
131 /* to the two blocks. */
133 /* GIVPTR (input) INTEGER */
134 /* The number of Givens rotations which took place in this */
137 /* GIVCOL (input) INTEGER array, dimension ( LDGCOL, 2 ) */
138 /* Each pair of numbers indicates a pair of rows/columns */
139 /* involved in a Givens rotation. */
141 /* LDGCOL (input) INTEGER */
142 /* The leading dimension of GIVCOL, must be at least N. */
144 /* GIVNUM (input) DOUBLE PRECISION array, dimension ( LDGNUM, 2 ) */
145 /* Each number indicates the C or S value used in the */
146 /* corresponding Givens rotation. */
148 /* LDGNUM (input) INTEGER */
149 /* The leading dimension of arrays DIFR, POLES and */
150 /* GIVNUM, must be at least K. */
152 /* POLES (input) DOUBLE PRECISION array, dimension ( LDGNUM, 2 ) */
153 /* On entry, POLES(1:K, 1) contains the new singular */
154 /* values obtained from solving the secular equation, and */
155 /* POLES(1:K, 2) is an array containing the poles in the secular */
158 /* DIFL (input) DOUBLE PRECISION array, dimension ( K ). */
159 /* On entry, DIFL(I) is the distance between I-th updated */
160 /* (undeflated) singular value and the I-th (undeflated) old */
161 /* singular value. */
163 /* DIFR (input) DOUBLE PRECISION array, dimension ( LDGNUM, 2 ). */
164 /* On entry, DIFR(I, 1) contains the distances between I-th */
165 /* updated (undeflated) singular value and the I+1-th */
166 /* (undeflated) old singular value. And DIFR(I, 2) is the */
167 /* normalizing factor for the I-th right singular vector. */
169 /* Z (input) DOUBLE PRECISION array, dimension ( K ) */
170 /* Contain the components of the deflation-adjusted updating row */
173 /* K (input) INTEGER */
174 /* Contains the dimension of the non-deflated matrix, */
175 /* This is the order of the related secular equation. 1 <= K <=N. */
177 /* C (input) DOUBLE PRECISION */
178 /* C contains garbage if SQRE =0 and the C-value of a Givens */
179 /* rotation related to the right null space if SQRE = 1. */
181 /* S (input) DOUBLE PRECISION */
182 /* S contains garbage if SQRE =0 and the S-value of a Givens */
183 /* rotation related to the right null space if SQRE = 1. */
185 /* WORK (workspace) DOUBLE PRECISION array, dimension ( K ) */
187 /* INFO (output) INTEGER */
188 /* = 0: successful exit. */
189 /* < 0: if INFO = -i, the i-th argument had an illegal value. */
191 /* Further Details */
192 /* =============== */
194 /* Based on contributions by */
195 /* Ming Gu and Ren-Cang Li, Computer Science Division, University of */
196 /* California at Berkeley, USA */
197 /* Osni Marques, LBNL/NERSC, USA */
199 /* ===================================================================== */
201 /* .. Parameters .. */
203 /* .. Local Scalars .. */
205 /* .. External Subroutines .. */
207 /* .. External Functions .. */
209 /* .. Intrinsic Functions .. */
211 /* .. Executable Statements .. */
213 /* Test the input parameters. */
215 /* Parameter adjustments */
217 b_offset = 1 + b_dim1;
220 bx_offset = 1 + bx_dim1;
223 givcol_dim1 = *ldgcol;
224 givcol_offset = 1 + givcol_dim1;
225 givcol -= givcol_offset;
227 difr_offset = 1 + difr_dim1;
229 poles_dim1 = *ldgnum;
230 poles_offset = 1 + poles_dim1;
231 poles -= poles_offset;
232 givnum_dim1 = *ldgnum;
233 givnum_offset = 1 + givnum_dim1;
234 givnum -= givnum_offset;
242 if (*icompq < 0 || *icompq > 1) {
244 } else if (*nl < 1) {
246 } else if (*nr < 1) {
248 } else if (*sqre < 0 || *sqre > 1) {
256 } else if (*ldb < n) {
258 } else if (*ldbx < n) {
260 } else if (*givptr < 0) {
262 } else if (*ldgcol < n) {
264 } else if (*ldgnum < n) {
271 xerbla_("DLALS0", &i__1);
280 /* Apply back orthogonal transformations from the left. */
282 /* Step (1L): apply back the Givens rotations performed. */
285 for (i__ = 1; i__ <= i__1; ++i__) {
286 drot_(nrhs, &b[givcol[i__ + (givcol_dim1 << 1)] + b_dim1], ldb, &
287 b[givcol[i__ + givcol_dim1] + b_dim1], ldb, &givnum[i__ +
288 (givnum_dim1 << 1)], &givnum[i__ + givnum_dim1]);
292 /* Step (2L): permute rows of B. */
294 dcopy_(nrhs, &b[nlp1 + b_dim1], ldb, &bx[bx_dim1 + 1], ldbx);
296 for (i__ = 2; i__ <= i__1; ++i__) {
297 dcopy_(nrhs, &b[perm[i__] + b_dim1], ldb, &bx[i__ + bx_dim1],
302 /* Step (3L): apply the inverse of the left singular vector */
306 dcopy_(nrhs, &bx[bx_offset], ldbx, &b[b_offset], ldb);
308 dscal_(nrhs, &c_b5, &b[b_offset], ldb);
312 for (j = 1; j <= i__1; ++j) {
314 dj = poles[j + poles_dim1];
315 dsigj = -poles[j + (poles_dim1 << 1)];
317 difrj = -difr[j + difr_dim1];
318 dsigjp = -poles[j + 1 + (poles_dim1 << 1)];
320 if (z__[j] == 0. || poles[j + (poles_dim1 << 1)] == 0.) {
323 work[j] = -poles[j + (poles_dim1 << 1)] * z__[j] / diflj /
324 (poles[j + (poles_dim1 << 1)] + dj);
327 for (i__ = 1; i__ <= i__2; ++i__) {
328 if (z__[i__] == 0. || poles[i__ + (poles_dim1 << 1)] ==
332 work[i__] = poles[i__ + (poles_dim1 << 1)] * z__[i__]
333 / (dlamc3_(&poles[i__ + (poles_dim1 << 1)], &
334 dsigj) - diflj) / (poles[i__ + (poles_dim1 <<
340 for (i__ = j + 1; i__ <= i__2; ++i__) {
341 if (z__[i__] == 0. || poles[i__ + (poles_dim1 << 1)] ==
345 work[i__] = poles[i__ + (poles_dim1 << 1)] * z__[i__]
346 / (dlamc3_(&poles[i__ + (poles_dim1 << 1)], &
347 dsigjp) + difrj) / (poles[i__ + (poles_dim1 <<
353 temp = dnrm2_(k, &work[1], &c__1);
354 dgemv_("T", k, nrhs, &c_b11, &bx[bx_offset], ldbx, &work[1], &
355 c__1, &c_b13, &b[j + b_dim1], ldb);
356 dlascl_("G", &c__0, &c__0, &temp, &c_b11, &c__1, nrhs, &b[j +
362 /* Move the deflated rows of BX to B also. */
366 dlacpy_("A", &i__1, nrhs, &bx[*k + 1 + bx_dim1], ldbx, &b[*k + 1
371 /* Apply back the right orthogonal transformations. */
373 /* Step (1R): apply back the new right singular vector matrix */
377 dcopy_(nrhs, &b[b_offset], ldb, &bx[bx_offset], ldbx);
380 for (j = 1; j <= i__1; ++j) {
381 dsigj = poles[j + (poles_dim1 << 1)];
385 work[j] = -z__[j] / difl[j] / (dsigj + poles[j +
386 poles_dim1]) / difr[j + (difr_dim1 << 1)];
389 for (i__ = 1; i__ <= i__2; ++i__) {
393 d__1 = -poles[i__ + 1 + (poles_dim1 << 1)];
394 work[i__] = z__[j] / (dlamc3_(&dsigj, &d__1) - difr[
395 i__ + difr_dim1]) / (dsigj + poles[i__ +
396 poles_dim1]) / difr[i__ + (difr_dim1 << 1)];
401 for (i__ = j + 1; i__ <= i__2; ++i__) {
405 d__1 = -poles[i__ + (poles_dim1 << 1)];
406 work[i__] = z__[j] / (dlamc3_(&dsigj, &d__1) - difl[
407 i__]) / (dsigj + poles[i__ + poles_dim1]) /
408 difr[i__ + (difr_dim1 << 1)];
412 dgemv_("T", k, nrhs, &c_b11, &b[b_offset], ldb, &work[1], &
413 c__1, &c_b13, &bx[j + bx_dim1], ldbx);
418 /* Step (2R): if SQRE = 1, apply back the rotation that is */
419 /* related to the right null space of the subproblem. */
422 dcopy_(nrhs, &b[m + b_dim1], ldb, &bx[m + bx_dim1], ldbx);
423 drot_(nrhs, &bx[bx_dim1 + 1], ldbx, &bx[m + bx_dim1], ldbx, c__,
428 dlacpy_("A", &i__1, nrhs, &b[*k + 1 + b_dim1], ldb, &bx[*k + 1 +
432 /* Step (3R): permute rows of B. */
434 dcopy_(nrhs, &bx[bx_dim1 + 1], ldbx, &b[nlp1 + b_dim1], ldb);
436 dcopy_(nrhs, &bx[m + bx_dim1], ldbx, &b[m + b_dim1], ldb);
439 for (i__ = 2; i__ <= i__1; ++i__) {
440 dcopy_(nrhs, &bx[i__ + bx_dim1], ldbx, &b[perm[i__] + b_dim1],
445 /* Step (4R): apply back the Givens rotations performed. */
447 for (i__ = *givptr; i__ >= 1; --i__) {
448 d__1 = -givnum[i__ + givnum_dim1];
449 drot_(nrhs, &b[givcol[i__ + (givcol_dim1 << 1)] + b_dim1], ldb, &
450 b[givcol[i__ + givcol_dim1] + b_dim1], ldb, &givnum[i__ +
451 (givnum_dim1 << 1)], &d__1);