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