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 dlaed2_(integer *k, integer *n, integer *n1, doublereal *
00022 d__, doublereal *q, integer *ldq, integer *indxq, doublereal *rho,
00023 doublereal *z__, doublereal *dlamda, doublereal *w, doublereal *q2,
00024 integer *indx, integer *indxc, integer *indxp, integer *coltyp,
00025 integer *info)
00026 {
00027
00028 integer q_dim1, q_offset, i__1, i__2;
00029 doublereal d__1, d__2, d__3, d__4;
00030
00031
00032 double sqrt(doublereal);
00033
00034
00035 doublereal c__;
00036 integer i__, j;
00037 doublereal s, t;
00038 integer k2, n2, ct, nj, pj, js, iq1, iq2, n1p1;
00039 doublereal eps, tau, tol;
00040 integer psm[4], imax, jmax;
00041 extern int drot_(integer *, doublereal *, integer *,
00042 doublereal *, integer *, doublereal *, doublereal *);
00043 integer ctot[4];
00044 extern int dscal_(integer *, doublereal *, doublereal *,
00045 integer *), dcopy_(integer *, doublereal *, integer *, doublereal
00046 *, integer *);
00047 extern doublereal dlapy2_(doublereal *, doublereal *), dlamch_(char *);
00048 extern integer idamax_(integer *, doublereal *, integer *);
00049 extern int dlamrg_(integer *, integer *, doublereal *,
00050 integer *, integer *, integer *), dlacpy_(char *, integer *,
00051 integer *, doublereal *, integer *, doublereal *, integer *), xerbla_(char *, integer *);
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 --d__;
00193 q_dim1 = *ldq;
00194 q_offset = 1 + q_dim1;
00195 q -= q_offset;
00196 --indxq;
00197 --z__;
00198 --dlamda;
00199 --w;
00200 --q2;
00201 --indx;
00202 --indxc;
00203 --indxp;
00204 --coltyp;
00205
00206
00207 *info = 0;
00208
00209 if (*n < 0) {
00210 *info = -2;
00211 } else if (*ldq < max(1,*n)) {
00212 *info = -6;
00213 } else {
00214
00215 i__1 = 1, i__2 = *n / 2;
00216 if (min(i__1,i__2) > *n1 || *n / 2 < *n1) {
00217 *info = -3;
00218 }
00219 }
00220 if (*info != 0) {
00221 i__1 = -(*info);
00222 xerbla_("DLAED2", &i__1);
00223 return 0;
00224 }
00225
00226
00227
00228 if (*n == 0) {
00229 return 0;
00230 }
00231
00232 n2 = *n - *n1;
00233 n1p1 = *n1 + 1;
00234
00235 if (*rho < 0.) {
00236 dscal_(&n2, &c_b3, &z__[n1p1], &c__1);
00237 }
00238
00239
00240
00241
00242 t = 1. / sqrt(2.);
00243 dscal_(n, &t, &z__[1], &c__1);
00244
00245
00246
00247 *rho = (d__1 = *rho * 2., abs(d__1));
00248
00249
00250
00251 i__1 = *n;
00252 for (i__ = n1p1; i__ <= i__1; ++i__) {
00253 indxq[i__] += *n1;
00254
00255 }
00256
00257
00258
00259 i__1 = *n;
00260 for (i__ = 1; i__ <= i__1; ++i__) {
00261 dlamda[i__] = d__[indxq[i__]];
00262
00263 }
00264 dlamrg_(n1, &n2, &dlamda[1], &c__1, &c__1, &indxc[1]);
00265 i__1 = *n;
00266 for (i__ = 1; i__ <= i__1; ++i__) {
00267 indx[i__] = indxq[indxc[i__]];
00268
00269 }
00270
00271
00272
00273 imax = idamax_(n, &z__[1], &c__1);
00274 jmax = idamax_(n, &d__[1], &c__1);
00275 eps = dlamch_("Epsilon");
00276
00277 d__3 = (d__1 = d__[jmax], abs(d__1)), d__4 = (d__2 = z__[imax], abs(d__2))
00278 ;
00279 tol = eps * 8. * max(d__3,d__4);
00280
00281
00282
00283
00284
00285 if (*rho * (d__1 = z__[imax], abs(d__1)) <= tol) {
00286 *k = 0;
00287 iq2 = 1;
00288 i__1 = *n;
00289 for (j = 1; j <= i__1; ++j) {
00290 i__ = indx[j];
00291 dcopy_(n, &q[i__ * q_dim1 + 1], &c__1, &q2[iq2], &c__1);
00292 dlamda[j] = d__[i__];
00293 iq2 += *n;
00294
00295 }
00296 dlacpy_("A", n, n, &q2[1], n, &q[q_offset], ldq);
00297 dcopy_(n, &dlamda[1], &c__1, &d__[1], &c__1);
00298 goto L190;
00299 }
00300
00301
00302
00303
00304
00305
00306
00307 i__1 = *n1;
00308 for (i__ = 1; i__ <= i__1; ++i__) {
00309 coltyp[i__] = 1;
00310
00311 }
00312 i__1 = *n;
00313 for (i__ = n1p1; i__ <= i__1; ++i__) {
00314 coltyp[i__] = 3;
00315
00316 }
00317
00318
00319 *k = 0;
00320 k2 = *n + 1;
00321 i__1 = *n;
00322 for (j = 1; j <= i__1; ++j) {
00323 nj = indx[j];
00324 if (*rho * (d__1 = z__[nj], abs(d__1)) <= tol) {
00325
00326
00327
00328 --k2;
00329 coltyp[nj] = 4;
00330 indxp[k2] = nj;
00331 if (j == *n) {
00332 goto L100;
00333 }
00334 } else {
00335 pj = nj;
00336 goto L80;
00337 }
00338
00339 }
00340 L80:
00341 ++j;
00342 nj = indx[j];
00343 if (j > *n) {
00344 goto L100;
00345 }
00346 if (*rho * (d__1 = z__[nj], abs(d__1)) <= tol) {
00347
00348
00349
00350 --k2;
00351 coltyp[nj] = 4;
00352 indxp[k2] = nj;
00353 } else {
00354
00355
00356
00357 s = z__[pj];
00358 c__ = z__[nj];
00359
00360
00361
00362
00363 tau = dlapy2_(&c__, &s);
00364 t = d__[nj] - d__[pj];
00365 c__ /= tau;
00366 s = -s / tau;
00367 if ((d__1 = t * c__ * s, abs(d__1)) <= tol) {
00368
00369
00370
00371 z__[nj] = tau;
00372 z__[pj] = 0.;
00373 if (coltyp[nj] != coltyp[pj]) {
00374 coltyp[nj] = 2;
00375 }
00376 coltyp[pj] = 4;
00377 drot_(n, &q[pj * q_dim1 + 1], &c__1, &q[nj * q_dim1 + 1], &c__1, &
00378 c__, &s);
00379
00380 d__1 = c__;
00381
00382 d__2 = s;
00383 t = d__[pj] * (d__1 * d__1) + d__[nj] * (d__2 * d__2);
00384
00385 d__1 = s;
00386
00387 d__2 = c__;
00388 d__[nj] = d__[pj] * (d__1 * d__1) + d__[nj] * (d__2 * d__2);
00389 d__[pj] = t;
00390 --k2;
00391 i__ = 1;
00392 L90:
00393 if (k2 + i__ <= *n) {
00394 if (d__[pj] < d__[indxp[k2 + i__]]) {
00395 indxp[k2 + i__ - 1] = indxp[k2 + i__];
00396 indxp[k2 + i__] = pj;
00397 ++i__;
00398 goto L90;
00399 } else {
00400 indxp[k2 + i__ - 1] = pj;
00401 }
00402 } else {
00403 indxp[k2 + i__ - 1] = pj;
00404 }
00405 pj = nj;
00406 } else {
00407 ++(*k);
00408 dlamda[*k] = d__[pj];
00409 w[*k] = z__[pj];
00410 indxp[*k] = pj;
00411 pj = nj;
00412 }
00413 }
00414 goto L80;
00415 L100:
00416
00417
00418
00419 ++(*k);
00420 dlamda[*k] = d__[pj];
00421 w[*k] = z__[pj];
00422 indxp[*k] = pj;
00423
00424
00425
00426
00427
00428
00429 for (j = 1; j <= 4; ++j) {
00430 ctot[j - 1] = 0;
00431
00432 }
00433 i__1 = *n;
00434 for (j = 1; j <= i__1; ++j) {
00435 ct = coltyp[j];
00436 ++ctot[ct - 1];
00437
00438 }
00439
00440
00441
00442 psm[0] = 1;
00443 psm[1] = ctot[0] + 1;
00444 psm[2] = psm[1] + ctot[1];
00445 psm[3] = psm[2] + ctot[2];
00446 *k = *n - ctot[3];
00447
00448
00449
00450
00451
00452 i__1 = *n;
00453 for (j = 1; j <= i__1; ++j) {
00454 js = indxp[j];
00455 ct = coltyp[js];
00456 indx[psm[ct - 1]] = js;
00457 indxc[psm[ct - 1]] = j;
00458 ++psm[ct - 1];
00459
00460 }
00461
00462
00463
00464
00465
00466
00467 i__ = 1;
00468 iq1 = 1;
00469 iq2 = (ctot[0] + ctot[1]) * *n1 + 1;
00470 i__1 = ctot[0];
00471 for (j = 1; j <= i__1; ++j) {
00472 js = indx[i__];
00473 dcopy_(n1, &q[js * q_dim1 + 1], &c__1, &q2[iq1], &c__1);
00474 z__[i__] = d__[js];
00475 ++i__;
00476 iq1 += *n1;
00477
00478 }
00479
00480 i__1 = ctot[1];
00481 for (j = 1; j <= i__1; ++j) {
00482 js = indx[i__];
00483 dcopy_(n1, &q[js * q_dim1 + 1], &c__1, &q2[iq1], &c__1);
00484 dcopy_(&n2, &q[*n1 + 1 + js * q_dim1], &c__1, &q2[iq2], &c__1);
00485 z__[i__] = d__[js];
00486 ++i__;
00487 iq1 += *n1;
00488 iq2 += n2;
00489
00490 }
00491
00492 i__1 = ctot[2];
00493 for (j = 1; j <= i__1; ++j) {
00494 js = indx[i__];
00495 dcopy_(&n2, &q[*n1 + 1 + js * q_dim1], &c__1, &q2[iq2], &c__1);
00496 z__[i__] = d__[js];
00497 ++i__;
00498 iq2 += n2;
00499
00500 }
00501
00502 iq1 = iq2;
00503 i__1 = ctot[3];
00504 for (j = 1; j <= i__1; ++j) {
00505 js = indx[i__];
00506 dcopy_(n, &q[js * q_dim1 + 1], &c__1, &q2[iq2], &c__1);
00507 iq2 += *n;
00508 z__[i__] = d__[js];
00509 ++i__;
00510
00511 }
00512
00513
00514
00515
00516 dlacpy_("A", n, &ctot[3], &q2[iq1], n, &q[(*k + 1) * q_dim1 + 1], ldq);
00517 i__1 = *n - *k;
00518 dcopy_(&i__1, &z__[*k + 1], &c__1, &d__[*k + 1], &c__1);
00519
00520
00521
00522 for (j = 1; j <= 4; ++j) {
00523 coltyp[j] = ctot[j - 1];
00524
00525 }
00526
00527 L190:
00528 return 0;
00529
00530
00531
00532 }