3 /* Table of constant values */
5 static integer c__0 = 0;
6 static real c_b7 = 1.f;
7 static integer c__1 = 1;
8 static integer c_n1 = -1;
10 /* Subroutine */ int slasd6_(integer *icompq, integer *nl, integer *nr,
11 integer *sqre, real *d__, real *vf, real *vl, real *alpha, real *beta,
12 integer *idxq, integer *perm, integer *givptr, integer *givcol,
13 integer *ldgcol, real *givnum, integer *ldgnum, real *poles, real *
14 difl, real *difr, real *z__, integer *k, real *c__, real *s, real *
15 work, integer *iwork, integer *info)
17 /* System generated locals */
18 integer givcol_dim1, givcol_offset, givnum_dim1, givnum_offset,
19 poles_dim1, poles_offset, i__1;
23 integer i__, m, n, n1, n2, iw, idx, idxc, idxp, ivfw, ivlw;
24 extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
25 integer *), slasd7_(integer *, integer *, integer *, integer *,
26 integer *, real *, real *, real *, real *, real *, real *, real *,
27 real *, real *, real *, integer *, integer *, integer *, integer
28 *, integer *, integer *, integer *, real *, integer *, real *,
29 real *, integer *), slasd8_(integer *, integer *, real *, real *,
30 real *, real *, real *, real *, integer *, real *, real *,
33 extern /* Subroutine */ int xerbla_(char *, integer *), slascl_(
34 char *, integer *, integer *, real *, real *, integer *, integer *
35 , real *, integer *, integer *), slamrg_(integer *,
36 integer *, real *, integer *, integer *, integer *);
40 /* -- LAPACK auxiliary routine (version 3.1) -- */
41 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
44 /* .. Scalar Arguments .. */
46 /* .. Array Arguments .. */
52 /* SLASD6 computes the SVD of an updated upper bidiagonal matrix B */
53 /* obtained by merging two smaller ones by appending a row. This */
54 /* routine is used only for the problem which requires all singular */
55 /* values and optionally singular vector matrices in factored form. */
56 /* B is an N-by-M matrix with N = NL + NR + 1 and M = N + SQRE. */
57 /* A related subroutine, SLASD1, handles the case in which all singular */
58 /* values and singular vectors of the bidiagonal matrix are desired. */
60 /* SLASD6 computes the SVD as follows: */
62 /* ( D1(in) 0 0 0 ) */
63 /* B = U(in) * ( Z1' a Z2' b ) * VT(in) */
64 /* ( 0 0 D2(in) 0 ) */
66 /* = U(out) * ( D(out) 0) * VT(out) */
68 /* where Z' = (Z1' a Z2' b) = u' VT', and u is a vector of dimension M */
69 /* with ALPHA and BETA in the NL+1 and NL+2 th entries and zeros */
70 /* elsewhere; and the entry b is empty if SQRE = 0. */
72 /* The singular values of B can be computed using D1, D2, the first */
73 /* components of all the right singular vectors of the lower block, and */
74 /* the last components of all the right singular vectors of the upper */
75 /* block. These components are stored and updated in VF and VL, */
76 /* respectively, in SLASD6. Hence U and VT are not explicitly */
79 /* The singular values are stored in D. The algorithm consists of two */
82 /* The first stage consists of deflating the size of the problem */
83 /* when there are multiple singular values or if there is a zero */
84 /* in the Z vector. For each such occurence the dimension of the */
85 /* secular equation problem is reduced by one. This stage is */
86 /* performed by the routine SLASD7. */
88 /* The second stage consists of calculating the updated */
89 /* singular values. This is done by finding the roots of the */
90 /* secular equation via the routine SLASD4 (as called by SLASD8). */
91 /* This routine also updates VF and VL and computes the distances */
92 /* between the updated singular values and the old singular */
95 /* SLASD6 is called from SLASDA. */
100 /* ICOMPQ (input) INTEGER */
101 /* Specifies whether singular vectors are to be computed in */
103 /* = 0: Compute singular values only. */
104 /* = 1: Compute singular vectors in factored form as well. */
106 /* NL (input) INTEGER */
107 /* The row dimension of the upper block. NL >= 1. */
109 /* NR (input) INTEGER */
110 /* The row dimension of the lower block. NR >= 1. */
112 /* SQRE (input) INTEGER */
113 /* = 0: the lower block is an NR-by-NR square matrix. */
114 /* = 1: the lower block is an NR-by-(NR+1) rectangular matrix. */
116 /* The bidiagonal matrix has row dimension N = NL + NR + 1, */
117 /* and column dimension M = N + SQRE. */
119 /* D (input/output) REAL array, dimension (NL+NR+1). */
120 /* On entry D(1:NL,1:NL) contains the singular values of the */
121 /* upper block, and D(NL+2:N) contains the singular values */
122 /* of the lower block. On exit D(1:N) contains the singular */
123 /* values of the modified matrix. */
125 /* VF (input/output) REAL array, dimension (M) */
126 /* On entry, VF(1:NL+1) contains the first components of all */
127 /* right singular vectors of the upper block; and VF(NL+2:M) */
128 /* contains the first components of all right singular vectors */
129 /* of the lower block. On exit, VF contains the first components */
130 /* of all right singular vectors of the bidiagonal matrix. */
132 /* VL (input/output) REAL array, dimension (M) */
133 /* On entry, VL(1:NL+1) contains the last components of all */
134 /* right singular vectors of the upper block; and VL(NL+2:M) */
135 /* contains the last components of all right singular vectors of */
136 /* the lower block. On exit, VL contains the last components of */
137 /* all right singular vectors of the bidiagonal matrix. */
139 /* ALPHA (input/output) REAL */
140 /* Contains the diagonal element associated with the added row. */
142 /* BETA (input/output) REAL */
143 /* Contains the off-diagonal element associated with the added */
146 /* IDXQ (output) INTEGER array, dimension (N) */
147 /* This contains the permutation which will reintegrate the */
148 /* subproblem just solved back into sorted order, i.e. */
149 /* D( IDXQ( I = 1, N ) ) will be in ascending order. */
151 /* PERM (output) INTEGER array, dimension ( N ) */
152 /* The permutations (from deflation and sorting) to be applied */
153 /* to each block. Not referenced if ICOMPQ = 0. */
155 /* GIVPTR (output) INTEGER */
156 /* The number of Givens rotations which took place in this */
157 /* subproblem. Not referenced if ICOMPQ = 0. */
159 /* GIVCOL (output) INTEGER array, dimension ( LDGCOL, 2 ) */
160 /* Each pair of numbers indicates a pair of columns to take place */
161 /* in a Givens rotation. Not referenced if ICOMPQ = 0. */
163 /* LDGCOL (input) INTEGER */
164 /* leading dimension of GIVCOL, must be at least N. */
166 /* GIVNUM (output) REAL array, dimension ( LDGNUM, 2 ) */
167 /* Each number indicates the C or S value to be used in the */
168 /* corresponding Givens rotation. Not referenced if ICOMPQ = 0. */
170 /* LDGNUM (input) INTEGER */
171 /* The leading dimension of GIVNUM and POLES, must be at least N. */
173 /* POLES (output) REAL array, dimension ( LDGNUM, 2 ) */
174 /* On exit, POLES(1,*) is an array containing the new singular */
175 /* values obtained from solving the secular equation, and */
176 /* POLES(2,*) is an array containing the poles in the secular */
177 /* equation. Not referenced if ICOMPQ = 0. */
179 /* DIFL (output) REAL array, dimension ( N ) */
180 /* On exit, DIFL(I) is the distance between I-th updated */
181 /* (undeflated) singular value and the I-th (undeflated) old */
182 /* singular value. */
184 /* DIFR (output) REAL array, */
185 /* dimension ( LDGNUM, 2 ) if ICOMPQ = 1 and */
186 /* dimension ( N ) if ICOMPQ = 0. */
187 /* On exit, DIFR(I, 1) is the distance between I-th updated */
188 /* (undeflated) singular value and the I+1-th (undeflated) old */
189 /* singular value. */
191 /* If ICOMPQ = 1, DIFR(1:K,2) is an array containing the */
192 /* normalizing factors for the right singular vector matrix. */
194 /* See SLASD8 for details on DIFL and DIFR. */
196 /* Z (output) REAL array, dimension ( M ) */
197 /* The first elements of this array contain the components */
198 /* of the deflation-adjusted updating row vector. */
200 /* K (output) INTEGER */
201 /* Contains the dimension of the non-deflated matrix, */
202 /* This is the order of the related secular equation. 1 <= K <=N. */
204 /* C (output) REAL */
205 /* C contains garbage if SQRE =0 and the C-value of a Givens */
206 /* rotation related to the right null space if SQRE = 1. */
208 /* S (output) REAL */
209 /* S contains garbage if SQRE =0 and the S-value of a Givens */
210 /* rotation related to the right null space if SQRE = 1. */
212 /* WORK (workspace) REAL array, dimension ( 4 * M ) */
214 /* IWORK (workspace) INTEGER array, dimension ( 3 * N ) */
216 /* INFO (output) INTEGER */
217 /* = 0: successful exit. */
218 /* < 0: if INFO = -i, the i-th argument had an illegal value. */
219 /* > 0: if INFO = 1, an singular value did not converge */
221 /* Further Details */
222 /* =============== */
224 /* Based on contributions by */
225 /* Ming Gu and Huan Ren, Computer Science Division, University of */
226 /* California at Berkeley, USA */
228 /* ===================================================================== */
230 /* .. Parameters .. */
232 /* .. Local Scalars .. */
234 /* .. External Subroutines .. */
236 /* .. Intrinsic Functions .. */
238 /* .. Executable Statements .. */
240 /* Test the input parameters. */
242 /* Parameter adjustments */
248 givcol_dim1 = *ldgcol;
249 givcol_offset = 1 + givcol_dim1;
250 givcol -= givcol_offset;
251 poles_dim1 = *ldgnum;
252 poles_offset = 1 + poles_dim1;
253 poles -= poles_offset;
254 givnum_dim1 = *ldgnum;
255 givnum_offset = 1 + givnum_dim1;
256 givnum -= givnum_offset;
268 if (*icompq < 0 || *icompq > 1) {
270 } else if (*nl < 1) {
272 } else if (*nr < 1) {
274 } else if (*sqre < 0 || *sqre > 1) {
276 } else if (*ldgcol < n) {
278 } else if (*ldgnum < n) {
283 xerbla_("SLASD6", &i__1);
287 /* The following values are for bookkeeping purposes only. They are */
288 /* integer pointers which indicate the portion of the workspace */
289 /* used by a particular array in SLASD7 and SLASD8. */
303 r__1 = dabs(*alpha), r__2 = dabs(*beta);
304 orgnrm = dmax(r__1,r__2);
307 for (i__ = 1; i__ <= i__1; ++i__) {
308 if ((r__1 = d__[i__], dabs(r__1)) > orgnrm) {
309 orgnrm = (r__1 = d__[i__], dabs(r__1));
313 slascl_("G", &c__0, &c__0, &orgnrm, &c_b7, &n, &c__1, &d__[1], &n, info);
317 /* Sort and Deflate singular values. */
319 slasd7_(icompq, nl, nr, sqre, k, &d__[1], &z__[1], &work[iw], &vf[1], &
320 work[ivfw], &vl[1], &work[ivlw], alpha, beta, &work[isigma], &
321 iwork[idx], &iwork[idxp], &idxq[1], &perm[1], givptr, &givcol[
322 givcol_offset], ldgcol, &givnum[givnum_offset], ldgnum, c__, s,
325 /* Solve Secular Equation, compute DIFL, DIFR, and update VF, VL. */
327 slasd8_(icompq, k, &d__[1], &z__[1], &vf[1], &vl[1], &difl[1], &difr[1],
328 ldgnum, &work[isigma], &work[iw], info);
330 /* Save the poles if ICOMPQ = 1. */
333 scopy_(k, &d__[1], &c__1, &poles[poles_dim1 + 1], &c__1);
334 scopy_(k, &work[isigma], &c__1, &poles[(poles_dim1 << 1) + 1], &c__1);
339 slascl_("G", &c__0, &c__0, &c_b7, &orgnrm, &n, &c__1, &d__[1], &n, info);
341 /* Prepare the IDXQ sorting permutation. */
345 slamrg_(&n1, &n2, &d__[1], &c__1, &c_n1, &idxq[1]);