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 dlaed8_(integer *icompq, integer *k, integer *n, integer
00022 *qsiz, doublereal *d__, doublereal *q, integer *ldq, integer *indxq,
00023 doublereal *rho, integer *cutpnt, doublereal *z__, doublereal *dlamda,
00024 doublereal *q2, integer *ldq2, doublereal *w, integer *perm, integer
00025 *givptr, integer *givcol, doublereal *givnum, integer *indxp, integer
00026 *indx, 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 drot_(integer *, doublereal *, integer *,
00043 doublereal *, integer *, doublereal *, doublereal *), dscal_(
00044 integer *, doublereal *, doublereal *, integer *), dcopy_(integer
00045 *, doublereal *, integer *, doublereal *, integer *);
00046 extern doublereal dlapy2_(doublereal *, doublereal *), dlamch_(char *);
00047 extern integer idamax_(integer *, doublereal *, integer *);
00048 extern int dlamrg_(integer *, integer *, doublereal *,
00049 integer *, integer *, integer *), dlacpy_(char *, integer *,
00050 integer *, doublereal *, integer *, doublereal *, integer *), xerbla_(char *, integer *);
00051
00052
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
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 --d__;
00204 q_dim1 = *ldq;
00205 q_offset = 1 + q_dim1;
00206 q -= q_offset;
00207 --indxq;
00208 --z__;
00209 --dlamda;
00210 q2_dim1 = *ldq2;
00211 q2_offset = 1 + q2_dim1;
00212 q2 -= q2_offset;
00213 --w;
00214 --perm;
00215 givcol -= 3;
00216 givnum -= 3;
00217 --indxp;
00218 --indx;
00219
00220
00221 *info = 0;
00222
00223 if (*icompq < 0 || *icompq > 1) {
00224 *info = -1;
00225 } else if (*n < 0) {
00226 *info = -3;
00227 } else if (*icompq == 1 && *qsiz < *n) {
00228 *info = -4;
00229 } else if (*ldq < max(1,*n)) {
00230 *info = -7;
00231 } else if (*cutpnt < min(1,*n) || *cutpnt > *n) {
00232 *info = -10;
00233 } else if (*ldq2 < max(1,*n)) {
00234 *info = -14;
00235 }
00236 if (*info != 0) {
00237 i__1 = -(*info);
00238 xerbla_("DLAED8", &i__1);
00239 return 0;
00240 }
00241
00242
00243
00244 if (*n == 0) {
00245 return 0;
00246 }
00247
00248 n1 = *cutpnt;
00249 n2 = *n - n1;
00250 n1p1 = n1 + 1;
00251
00252 if (*rho < 0.) {
00253 dscal_(&n2, &c_b3, &z__[n1p1], &c__1);
00254 }
00255
00256
00257
00258 t = 1. / sqrt(2.);
00259 i__1 = *n;
00260 for (j = 1; j <= i__1; ++j) {
00261 indx[j] = j;
00262
00263 }
00264 dscal_(n, &t, &z__[1], &c__1);
00265 *rho = (d__1 = *rho * 2., abs(d__1));
00266
00267
00268
00269 i__1 = *n;
00270 for (i__ = *cutpnt + 1; i__ <= i__1; ++i__) {
00271 indxq[i__] += *cutpnt;
00272
00273 }
00274 i__1 = *n;
00275 for (i__ = 1; i__ <= i__1; ++i__) {
00276 dlamda[i__] = d__[indxq[i__]];
00277 w[i__] = z__[indxq[i__]];
00278
00279 }
00280 i__ = 1;
00281 j = *cutpnt + 1;
00282 dlamrg_(&n1, &n2, &dlamda[1], &c__1, &c__1, &indx[1]);
00283 i__1 = *n;
00284 for (i__ = 1; i__ <= i__1; ++i__) {
00285 d__[i__] = dlamda[indx[i__]];
00286 z__[i__] = w[indx[i__]];
00287
00288 }
00289
00290
00291
00292 imax = idamax_(n, &z__[1], &c__1);
00293 jmax = idamax_(n, &d__[1], &c__1);
00294 eps = dlamch_("Epsilon");
00295 tol = eps * 8. * (d__1 = d__[jmax], abs(d__1));
00296
00297
00298
00299
00300
00301 if (*rho * (d__1 = z__[imax], abs(d__1)) <= tol) {
00302 *k = 0;
00303 if (*icompq == 0) {
00304 i__1 = *n;
00305 for (j = 1; j <= i__1; ++j) {
00306 perm[j] = indxq[indx[j]];
00307
00308 }
00309 } else {
00310 i__1 = *n;
00311 for (j = 1; j <= i__1; ++j) {
00312 perm[j] = indxq[indx[j]];
00313 dcopy_(qsiz, &q[perm[j] * q_dim1 + 1], &c__1, &q2[j * q2_dim1
00314 + 1], &c__1);
00315
00316 }
00317 dlacpy_("A", qsiz, n, &q2[q2_dim1 + 1], ldq2, &q[q_dim1 + 1], ldq);
00318 }
00319 return 0;
00320 }
00321
00322
00323
00324
00325
00326
00327
00328 *k = 0;
00329 *givptr = 0;
00330 k2 = *n + 1;
00331 i__1 = *n;
00332 for (j = 1; j <= i__1; ++j) {
00333 if (*rho * (d__1 = z__[j], abs(d__1)) <= tol) {
00334
00335
00336
00337 --k2;
00338 indxp[k2] = j;
00339 if (j == *n) {
00340 goto L110;
00341 }
00342 } else {
00343 jlam = j;
00344 goto L80;
00345 }
00346
00347 }
00348 L80:
00349 ++j;
00350 if (j > *n) {
00351 goto L100;
00352 }
00353 if (*rho * (d__1 = z__[j], abs(d__1)) <= tol) {
00354
00355
00356
00357 --k2;
00358 indxp[k2] = j;
00359 } else {
00360
00361
00362
00363 s = z__[jlam];
00364 c__ = z__[j];
00365
00366
00367
00368
00369 tau = dlapy2_(&c__, &s);
00370 t = d__[j] - d__[jlam];
00371 c__ /= tau;
00372 s = -s / tau;
00373 if ((d__1 = t * c__ * s, abs(d__1)) <= tol) {
00374
00375
00376
00377 z__[j] = tau;
00378 z__[jlam] = 0.;
00379
00380
00381
00382 ++(*givptr);
00383 givcol[(*givptr << 1) + 1] = indxq[indx[jlam]];
00384 givcol[(*givptr << 1) + 2] = indxq[indx[j]];
00385 givnum[(*givptr << 1) + 1] = c__;
00386 givnum[(*givptr << 1) + 2] = s;
00387 if (*icompq == 1) {
00388 drot_(qsiz, &q[indxq[indx[jlam]] * q_dim1 + 1], &c__1, &q[
00389 indxq[indx[j]] * q_dim1 + 1], &c__1, &c__, &s);
00390 }
00391 t = d__[jlam] * c__ * c__ + d__[j] * s * s;
00392 d__[j] = d__[jlam] * s * s + d__[j] * c__ * c__;
00393 d__[jlam] = t;
00394 --k2;
00395 i__ = 1;
00396 L90:
00397 if (k2 + i__ <= *n) {
00398 if (d__[jlam] < d__[indxp[k2 + i__]]) {
00399 indxp[k2 + i__ - 1] = indxp[k2 + i__];
00400 indxp[k2 + i__] = jlam;
00401 ++i__;
00402 goto L90;
00403 } else {
00404 indxp[k2 + i__ - 1] = jlam;
00405 }
00406 } else {
00407 indxp[k2 + i__ - 1] = jlam;
00408 }
00409 jlam = j;
00410 } else {
00411 ++(*k);
00412 w[*k] = z__[jlam];
00413 dlamda[*k] = d__[jlam];
00414 indxp[*k] = jlam;
00415 jlam = j;
00416 }
00417 }
00418 goto L80;
00419 L100:
00420
00421
00422
00423 ++(*k);
00424 w[*k] = z__[jlam];
00425 dlamda[*k] = d__[jlam];
00426 indxp[*k] = jlam;
00427
00428 L110:
00429
00430
00431
00432
00433
00434
00435 if (*icompq == 0) {
00436 i__1 = *n;
00437 for (j = 1; j <= i__1; ++j) {
00438 jp = indxp[j];
00439 dlamda[j] = d__[jp];
00440 perm[j] = indxq[indx[jp]];
00441
00442 }
00443 } else {
00444 i__1 = *n;
00445 for (j = 1; j <= i__1; ++j) {
00446 jp = indxp[j];
00447 dlamda[j] = d__[jp];
00448 perm[j] = indxq[indx[jp]];
00449 dcopy_(qsiz, &q[perm[j] * q_dim1 + 1], &c__1, &q2[j * q2_dim1 + 1]
00450 , &c__1);
00451
00452 }
00453 }
00454
00455
00456
00457
00458 if (*k < *n) {
00459 if (*icompq == 0) {
00460 i__1 = *n - *k;
00461 dcopy_(&i__1, &dlamda[*k + 1], &c__1, &d__[*k + 1], &c__1);
00462 } else {
00463 i__1 = *n - *k;
00464 dcopy_(&i__1, &dlamda[*k + 1], &c__1, &d__[*k + 1], &c__1);
00465 i__1 = *n - *k;
00466 dlacpy_("A", qsiz, &i__1, &q2[(*k + 1) * q2_dim1 + 1], ldq2, &q[(*
00467 k + 1) * q_dim1 + 1], ldq);
00468 }
00469 }
00470
00471 return 0;
00472
00473
00474
00475 }