3 /* Table of constant values */
5 static integer c__1 = 1;
6 static integer c__0 = 0;
7 static real c_b8 = 1.f;
9 /* Subroutine */ int slasd8_(integer *icompq, integer *k, real *d__, real *
10 z__, real *vf, real *vl, real *difl, real *difr, integer *lddifr,
11 real *dsigma, real *work, integer *info)
13 /* System generated locals */
14 integer difr_dim1, difr_offset, i__1, i__2;
17 /* Builtin functions */
18 double sqrt(doublereal), r_sign(real *, real *);
23 integer iwk1, iwk2, iwk3;
25 extern doublereal sdot_(integer *, real *, integer *, real *, integer *);
27 extern doublereal snrm2_(integer *, real *, integer *);
28 real diflj, difrj, dsigj;
29 extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
31 extern doublereal slamc3_(real *, real *);
32 extern /* Subroutine */ int slasd4_(integer *, integer *, real *, real *,
33 real *, real *, real *, real *, integer *), xerbla_(char *,
36 extern /* Subroutine */ int slascl_(char *, integer *, integer *, real *,
37 real *, integer *, integer *, real *, integer *, integer *), slaset_(char *, integer *, integer *, real *, real *,
41 /* -- LAPACK auxiliary routine (version 3.1) -- */
42 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
45 /* .. Scalar Arguments .. */
47 /* .. Array Arguments .. */
53 /* SLASD8 finds the square roots of the roots of the secular equation, */
54 /* as defined by the values in DSIGMA and Z. It makes the appropriate */
55 /* calls to SLASD4, and stores, for each element in D, the distance */
56 /* to its two nearest poles (elements in DSIGMA). It also updates */
57 /* the arrays VF and VL, the first and last components of all the */
58 /* right singular vectors of the original bidiagonal matrix. */
60 /* SLASD8 is called from SLASD6. */
65 /* ICOMPQ (input) INTEGER */
66 /* Specifies whether singular vectors are to be computed in */
67 /* factored form in the calling routine: */
68 /* = 0: Compute singular values only. */
69 /* = 1: Compute singular vectors in factored form as well. */
71 /* K (input) INTEGER */
72 /* The number of terms in the rational function to be solved */
73 /* by SLASD4. K >= 1. */
75 /* D (output) REAL array, dimension ( K ) */
76 /* On output, D contains the updated singular values. */
78 /* Z (input) REAL array, dimension ( K ) */
79 /* The first K elements of this array contain the components */
80 /* of the deflation-adjusted updating row vector. */
82 /* VF (input/output) REAL array, dimension ( K ) */
83 /* On entry, VF contains information passed through DBEDE8. */
84 /* On exit, VF contains the first K components of the first */
85 /* components of all right singular vectors of the bidiagonal */
88 /* VL (input/output) REAL array, dimension ( K ) */
89 /* On entry, VL contains information passed through DBEDE8. */
90 /* On exit, VL contains the first K components of the last */
91 /* components of all right singular vectors of the bidiagonal */
94 /* DIFL (output) REAL array, dimension ( K ) */
95 /* On exit, DIFL(I) = D(I) - DSIGMA(I). */
97 /* DIFR (output) REAL array, */
98 /* dimension ( LDDIFR, 2 ) if ICOMPQ = 1 and */
99 /* dimension ( K ) if ICOMPQ = 0. */
100 /* On exit, DIFR(I,1) = D(I) - DSIGMA(I+1), DIFR(K,1) is not */
101 /* defined and will not be referenced. */
103 /* If ICOMPQ = 1, DIFR(1:K,2) is an array containing the */
104 /* normalizing factors for the right singular vector matrix. */
106 /* LDDIFR (input) INTEGER */
107 /* The leading dimension of DIFR, must be at least K. */
109 /* DSIGMA (input) REAL array, dimension ( K ) */
110 /* The first K elements of this array contain the old roots */
111 /* of the deflated updating problem. These are the poles */
112 /* of the secular equation. */
114 /* WORK (workspace) REAL array, dimension at least 3 * K */
116 /* INFO (output) INTEGER */
117 /* = 0: successful exit. */
118 /* < 0: if INFO = -i, the i-th argument had an illegal value. */
119 /* > 0: if INFO = 1, an singular value did not converge */
121 /* Further Details */
122 /* =============== */
124 /* Based on contributions by */
125 /* Ming Gu and Huan Ren, Computer Science Division, University of */
126 /* California at Berkeley, USA */
128 /* ===================================================================== */
130 /* .. Parameters .. */
132 /* .. Local Scalars .. */
134 /* .. External Subroutines .. */
136 /* .. External Functions .. */
138 /* .. Intrinsic Functions .. */
140 /* .. Executable Statements .. */
142 /* Test the input parameters. */
144 /* Parameter adjustments */
151 difr_offset = 1 + difr_dim1;
159 if (*icompq < 0 || *icompq > 1) {
163 } else if (*lddifr < *k) {
168 xerbla_("SLASD8", &i__1);
172 /* Quick return if possible */
175 d__[1] = dabs(z__[1]);
179 difr[(difr_dim1 << 1) + 1] = 1.f;
184 /* Modify values DSIGMA(i) to make sure all DSIGMA(i)-DSIGMA(j) can */
185 /* be computed with high relative accuracy (barring over/underflow). */
186 /* This is a problem on machines without a guard digit in */
187 /* add/subtract (Cray XMP, Cray YMP, Cray C 90 and Cray 2). */
188 /* The following code replaces DSIGMA(I) by 2*DSIGMA(I)-DSIGMA(I), */
189 /* which on any of these machines zeros out the bottommost */
190 /* bit of DSIGMA(I) if it is 1; this makes the subsequent */
191 /* subtractions DSIGMA(I)-DSIGMA(J) unproblematic when cancellation */
192 /* occurs. On binary machines with a guard digit (almost all */
193 /* machines) it does not change DSIGMA(I) at all. On hexadecimal */
194 /* and decimal machines with a guard digit, it slightly */
195 /* changes the bottommost bits of DSIGMA(I). It does not account */
196 /* for hexadecimal or decimal machines without guard digits */
197 /* (we know of none). We use a subroutine call to compute */
198 /* 2*DSIGMA(I) to prevent optimizing compilers from eliminating */
202 for (i__ = 1; i__ <= i__1; ++i__) {
203 dsigma[i__] = slamc3_(&dsigma[i__], &dsigma[i__]) - dsigma[i__];
217 rho = snrm2_(k, &z__[1], &c__1);
218 slascl_("G", &c__0, &c__0, &rho, &c_b8, k, &c__1, &z__[1], k, info);
221 /* Initialize WORK(IWK3). */
223 slaset_("A", k, &c__1, &c_b8, &c_b8, &work[iwk3], k);
225 /* Compute the updated singular values, the arrays DIFL, DIFR, */
226 /* and the updated Z. */
229 for (j = 1; j <= i__1; ++j) {
230 slasd4_(k, &j, &dsigma[1], &z__[1], &work[iwk1], &rho, &d__[j], &work[
233 /* If the root finder fails, the computation is terminated. */
238 work[iwk3i + j] = work[iwk3i + j] * work[j] * work[iwk2i + j];
240 difr[j + difr_dim1] = -work[j + 1];
242 for (i__ = 1; i__ <= i__2; ++i__) {
243 work[iwk3i + i__] = work[iwk3i + i__] * work[i__] * work[iwk2i +
244 i__] / (dsigma[i__] - dsigma[j]) / (dsigma[i__] + dsigma[
249 for (i__ = j + 1; i__ <= i__2; ++i__) {
250 work[iwk3i + i__] = work[iwk3i + i__] * work[i__] * work[iwk2i +
251 i__] / (dsigma[i__] - dsigma[j]) / (dsigma[i__] + dsigma[
258 /* Compute updated Z. */
261 for (i__ = 1; i__ <= i__1; ++i__) {
262 r__2 = sqrt((r__1 = work[iwk3i + i__], dabs(r__1)));
263 z__[i__] = r_sign(&r__2, &z__[i__]);
267 /* Update VF and VL. */
270 for (j = 1; j <= i__1; ++j) {
275 difrj = -difr[j + difr_dim1];
276 dsigjp = -dsigma[j + 1];
278 work[j] = -z__[j] / diflj / (dsigma[j] + dj);
280 for (i__ = 1; i__ <= i__2; ++i__) {
281 work[i__] = z__[i__] / (slamc3_(&dsigma[i__], &dsigj) - diflj) / (
286 for (i__ = j + 1; i__ <= i__2; ++i__) {
287 work[i__] = z__[i__] / (slamc3_(&dsigma[i__], &dsigjp) + difrj) /
291 temp = snrm2_(k, &work[1], &c__1);
292 work[iwk2i + j] = sdot_(k, &work[1], &c__1, &vf[1], &c__1) / temp;
293 work[iwk3i + j] = sdot_(k, &work[1], &c__1, &vl[1], &c__1) / temp;
295 difr[j + (difr_dim1 << 1)] = temp;
300 scopy_(k, &work[iwk2], &c__1, &vf[1], &c__1);
301 scopy_(k, &work[iwk3], &c__1, &vl[1], &c__1);