00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016
00017
00018 static doublereal c_b3 = -1.;
00019 static integer c__1 = 1;
00020
00021 int zlaed8_(integer *k, integer *n, integer *qsiz,
00022 doublecomplex *q, integer *ldq, doublereal *d__, doublereal *rho,
00023 integer *cutpnt, doublereal *z__, doublereal *dlamda, doublecomplex *
00024 q2, integer *ldq2, doublereal *w, integer *indxp, integer *indx,
00025 integer *indxq, integer *perm, integer *givptr, integer *givcol,
00026 doublereal *givnum, integer *info)
00027 {
00028
00029 integer q_dim1, q_offset, q2_dim1, q2_offset, i__1;
00030 doublereal d__1;
00031
00032
00033 double sqrt(doublereal);
00034
00035
00036 doublereal c__;
00037 integer i__, j;
00038 doublereal s, t;
00039 integer k2, n1, n2, jp, n1p1;
00040 doublereal eps, tau, tol;
00041 integer jlam, imax, jmax;
00042 extern int dscal_(integer *, doublereal *, doublereal *,
00043 integer *), dcopy_(integer *, doublereal *, integer *, doublereal
00044 *, integer *), zdrot_(integer *, doublecomplex *, integer *,
00045 doublecomplex *, integer *, doublereal *, doublereal *), zcopy_(
00046 integer *, doublecomplex *, integer *, doublecomplex *, integer *)
00047 ;
00048 extern doublereal dlapy2_(doublereal *, doublereal *), dlamch_(char *);
00049 extern integer idamax_(integer *, doublereal *, integer *);
00050 extern int dlamrg_(integer *, integer *, doublereal *,
00051 integer *, integer *, integer *), xerbla_(char *, integer *), zlacpy_(char *, integer *, integer *, doublecomplex *,
00052 integer *, doublecomplex *, integer *);
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 q_dim1 = *ldq;
00192 q_offset = 1 + q_dim1;
00193 q -= q_offset;
00194 --d__;
00195 --z__;
00196 --dlamda;
00197 q2_dim1 = *ldq2;
00198 q2_offset = 1 + q2_dim1;
00199 q2 -= q2_offset;
00200 --w;
00201 --indxp;
00202 --indx;
00203 --indxq;
00204 --perm;
00205 givcol -= 3;
00206 givnum -= 3;
00207
00208
00209 *info = 0;
00210
00211 if (*n < 0) {
00212 *info = -2;
00213 } else if (*qsiz < *n) {
00214 *info = -3;
00215 } else if (*ldq < max(1,*n)) {
00216 *info = -5;
00217 } else if (*cutpnt < min(1,*n) || *cutpnt > *n) {
00218 *info = -8;
00219 } else if (*ldq2 < max(1,*n)) {
00220 *info = -12;
00221 }
00222 if (*info != 0) {
00223 i__1 = -(*info);
00224 xerbla_("ZLAED8", &i__1);
00225 return 0;
00226 }
00227
00228
00229
00230 if (*n == 0) {
00231 return 0;
00232 }
00233
00234 n1 = *cutpnt;
00235 n2 = *n - n1;
00236 n1p1 = n1 + 1;
00237
00238 if (*rho < 0.) {
00239 dscal_(&n2, &c_b3, &z__[n1p1], &c__1);
00240 }
00241
00242
00243
00244 t = 1. / sqrt(2.);
00245 i__1 = *n;
00246 for (j = 1; j <= i__1; ++j) {
00247 indx[j] = j;
00248
00249 }
00250 dscal_(n, &t, &z__[1], &c__1);
00251 *rho = (d__1 = *rho * 2., abs(d__1));
00252
00253
00254
00255 i__1 = *n;
00256 for (i__ = *cutpnt + 1; i__ <= i__1; ++i__) {
00257 indxq[i__] += *cutpnt;
00258
00259 }
00260 i__1 = *n;
00261 for (i__ = 1; i__ <= i__1; ++i__) {
00262 dlamda[i__] = d__[indxq[i__]];
00263 w[i__] = z__[indxq[i__]];
00264
00265 }
00266 i__ = 1;
00267 j = *cutpnt + 1;
00268 dlamrg_(&n1, &n2, &dlamda[1], &c__1, &c__1, &indx[1]);
00269 i__1 = *n;
00270 for (i__ = 1; i__ <= i__1; ++i__) {
00271 d__[i__] = dlamda[indx[i__]];
00272 z__[i__] = w[indx[i__]];
00273
00274 }
00275
00276
00277
00278 imax = idamax_(n, &z__[1], &c__1);
00279 jmax = idamax_(n, &d__[1], &c__1);
00280 eps = dlamch_("Epsilon");
00281 tol = eps * 8. * (d__1 = d__[jmax], abs(d__1));
00282
00283
00284
00285
00286
00287 if (*rho * (d__1 = z__[imax], abs(d__1)) <= tol) {
00288 *k = 0;
00289 i__1 = *n;
00290 for (j = 1; j <= i__1; ++j) {
00291 perm[j] = indxq[indx[j]];
00292 zcopy_(qsiz, &q[perm[j] * q_dim1 + 1], &c__1, &q2[j * q2_dim1 + 1]
00293 , &c__1);
00294
00295 }
00296 zlacpy_("A", qsiz, n, &q2[q2_dim1 + 1], ldq2, &q[q_dim1 + 1], ldq);
00297 return 0;
00298 }
00299
00300
00301
00302
00303
00304
00305
00306 *k = 0;
00307 *givptr = 0;
00308 k2 = *n + 1;
00309 i__1 = *n;
00310 for (j = 1; j <= i__1; ++j) {
00311 if (*rho * (d__1 = z__[j], abs(d__1)) <= tol) {
00312
00313
00314
00315 --k2;
00316 indxp[k2] = j;
00317 if (j == *n) {
00318 goto L100;
00319 }
00320 } else {
00321 jlam = j;
00322 goto L70;
00323 }
00324
00325 }
00326 L70:
00327 ++j;
00328 if (j > *n) {
00329 goto L90;
00330 }
00331 if (*rho * (d__1 = z__[j], abs(d__1)) <= tol) {
00332
00333
00334
00335 --k2;
00336 indxp[k2] = j;
00337 } else {
00338
00339
00340
00341 s = z__[jlam];
00342 c__ = z__[j];
00343
00344
00345
00346
00347 tau = dlapy2_(&c__, &s);
00348 t = d__[j] - d__[jlam];
00349 c__ /= tau;
00350 s = -s / tau;
00351 if ((d__1 = t * c__ * s, abs(d__1)) <= tol) {
00352
00353
00354
00355 z__[j] = tau;
00356 z__[jlam] = 0.;
00357
00358
00359
00360 ++(*givptr);
00361 givcol[(*givptr << 1) + 1] = indxq[indx[jlam]];
00362 givcol[(*givptr << 1) + 2] = indxq[indx[j]];
00363 givnum[(*givptr << 1) + 1] = c__;
00364 givnum[(*givptr << 1) + 2] = s;
00365 zdrot_(qsiz, &q[indxq[indx[jlam]] * q_dim1 + 1], &c__1, &q[indxq[
00366 indx[j]] * q_dim1 + 1], &c__1, &c__, &s);
00367 t = d__[jlam] * c__ * c__ + d__[j] * s * s;
00368 d__[j] = d__[jlam] * s * s + d__[j] * c__ * c__;
00369 d__[jlam] = t;
00370 --k2;
00371 i__ = 1;
00372 L80:
00373 if (k2 + i__ <= *n) {
00374 if (d__[jlam] < d__[indxp[k2 + i__]]) {
00375 indxp[k2 + i__ - 1] = indxp[k2 + i__];
00376 indxp[k2 + i__] = jlam;
00377 ++i__;
00378 goto L80;
00379 } else {
00380 indxp[k2 + i__ - 1] = jlam;
00381 }
00382 } else {
00383 indxp[k2 + i__ - 1] = jlam;
00384 }
00385 jlam = j;
00386 } else {
00387 ++(*k);
00388 w[*k] = z__[jlam];
00389 dlamda[*k] = d__[jlam];
00390 indxp[*k] = jlam;
00391 jlam = j;
00392 }
00393 }
00394 goto L70;
00395 L90:
00396
00397
00398
00399 ++(*k);
00400 w[*k] = z__[jlam];
00401 dlamda[*k] = d__[jlam];
00402 indxp[*k] = jlam;
00403
00404 L100:
00405
00406
00407
00408
00409
00410
00411 i__1 = *n;
00412 for (j = 1; j <= i__1; ++j) {
00413 jp = indxp[j];
00414 dlamda[j] = d__[jp];
00415 perm[j] = indxq[indx[jp]];
00416 zcopy_(qsiz, &q[perm[j] * q_dim1 + 1], &c__1, &q2[j * q2_dim1 + 1], &
00417 c__1);
00418
00419 }
00420
00421
00422
00423
00424 if (*k < *n) {
00425 i__1 = *n - *k;
00426 dcopy_(&i__1, &dlamda[*k + 1], &c__1, &d__[*k + 1], &c__1);
00427 i__1 = *n - *k;
00428 zlacpy_("A", qsiz, &i__1, &q2[(*k + 1) * q2_dim1 + 1], ldq2, &q[(*k +
00429 1) * q_dim1 + 1], ldq);
00430 }
00431
00432 return 0;
00433
00434
00435
00436 }