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 integer c__2 = 2;
00019 static integer c__1 = 1;
00020 static integer c_n1 = -1;
00021
00022 int sstein_(integer *n, real *d__, real *e, integer *m, real
00023 *w, integer *iblock, integer *isplit, real *z__, integer *ldz, real *
00024 work, integer *iwork, integer *ifail, integer *info)
00025 {
00026
00027 integer z_dim1, z_offset, i__1, i__2, i__3;
00028 real r__1, r__2, r__3, r__4, r__5;
00029
00030
00031 double sqrt(doublereal);
00032
00033
00034 integer i__, j, b1, j1, bn;
00035 real xj, scl, eps, ctr, sep, nrm, tol;
00036 integer its;
00037 real xjm, eps1;
00038 integer jblk, nblk, jmax;
00039 extern doublereal sdot_(integer *, real *, integer *, real *, integer *),
00040 snrm2_(integer *, real *, integer *);
00041 integer iseed[4], gpind, iinfo;
00042 extern int sscal_(integer *, real *, real *, integer *);
00043 extern doublereal sasum_(integer *, real *, integer *);
00044 extern int scopy_(integer *, real *, integer *, real *,
00045 integer *);
00046 real ortol;
00047 extern int saxpy_(integer *, real *, real *, integer *,
00048 real *, integer *);
00049 integer indrv1, indrv2, indrv3, indrv4, indrv5;
00050 extern doublereal slamch_(char *);
00051 extern int xerbla_(char *, integer *), slagtf_(
00052 integer *, real *, real *, real *, real *, real *, real *,
00053 integer *, integer *);
00054 integer nrmchk;
00055 extern integer isamax_(integer *, real *, integer *);
00056 extern int slagts_(integer *, integer *, real *, real *,
00057 real *, real *, integer *, real *, real *, integer *);
00058 integer blksiz;
00059 real onenrm, pertol;
00060 extern int slarnv_(integer *, integer *, integer *, real
00061 *);
00062 real stpcrt;
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 --d__;
00177 --e;
00178 --w;
00179 --iblock;
00180 --isplit;
00181 z_dim1 = *ldz;
00182 z_offset = 1 + z_dim1;
00183 z__ -= z_offset;
00184 --work;
00185 --iwork;
00186 --ifail;
00187
00188
00189 *info = 0;
00190 i__1 = *m;
00191 for (i__ = 1; i__ <= i__1; ++i__) {
00192 ifail[i__] = 0;
00193
00194 }
00195
00196 if (*n < 0) {
00197 *info = -1;
00198 } else if (*m < 0 || *m > *n) {
00199 *info = -4;
00200 } else if (*ldz < max(1,*n)) {
00201 *info = -9;
00202 } else {
00203 i__1 = *m;
00204 for (j = 2; j <= i__1; ++j) {
00205 if (iblock[j] < iblock[j - 1]) {
00206 *info = -6;
00207 goto L30;
00208 }
00209 if (iblock[j] == iblock[j - 1] && w[j] < w[j - 1]) {
00210 *info = -5;
00211 goto L30;
00212 }
00213
00214 }
00215 L30:
00216 ;
00217 }
00218
00219 if (*info != 0) {
00220 i__1 = -(*info);
00221 xerbla_("SSTEIN", &i__1);
00222 return 0;
00223 }
00224
00225
00226
00227 if (*n == 0 || *m == 0) {
00228 return 0;
00229 } else if (*n == 1) {
00230 z__[z_dim1 + 1] = 1.f;
00231 return 0;
00232 }
00233
00234
00235
00236 eps = slamch_("Precision");
00237
00238
00239
00240 for (i__ = 1; i__ <= 4; ++i__) {
00241 iseed[i__ - 1] = 1;
00242
00243 }
00244
00245
00246
00247 indrv1 = 0;
00248 indrv2 = indrv1 + *n;
00249 indrv3 = indrv2 + *n;
00250 indrv4 = indrv3 + *n;
00251 indrv5 = indrv4 + *n;
00252
00253
00254
00255 j1 = 1;
00256 i__1 = iblock[*m];
00257 for (nblk = 1; nblk <= i__1; ++nblk) {
00258
00259
00260
00261 if (nblk == 1) {
00262 b1 = 1;
00263 } else {
00264 b1 = isplit[nblk - 1] + 1;
00265 }
00266 bn = isplit[nblk];
00267 blksiz = bn - b1 + 1;
00268 if (blksiz == 1) {
00269 goto L60;
00270 }
00271 gpind = b1;
00272
00273
00274
00275 onenrm = (r__1 = d__[b1], dabs(r__1)) + (r__2 = e[b1], dabs(r__2));
00276
00277 r__3 = onenrm, r__4 = (r__1 = d__[bn], dabs(r__1)) + (r__2 = e[bn - 1]
00278 , dabs(r__2));
00279 onenrm = dmax(r__3,r__4);
00280 i__2 = bn - 1;
00281 for (i__ = b1 + 1; i__ <= i__2; ++i__) {
00282
00283 r__4 = onenrm, r__5 = (r__1 = d__[i__], dabs(r__1)) + (r__2 = e[
00284 i__ - 1], dabs(r__2)) + (r__3 = e[i__], dabs(r__3));
00285 onenrm = dmax(r__4,r__5);
00286
00287 }
00288 ortol = onenrm * .001f;
00289
00290 stpcrt = sqrt(.1f / blksiz);
00291
00292
00293
00294 L60:
00295 jblk = 0;
00296 i__2 = *m;
00297 for (j = j1; j <= i__2; ++j) {
00298 if (iblock[j] != nblk) {
00299 j1 = j;
00300 goto L160;
00301 }
00302 ++jblk;
00303 xj = w[j];
00304
00305
00306
00307 if (blksiz == 1) {
00308 work[indrv1 + 1] = 1.f;
00309 goto L120;
00310 }
00311
00312
00313
00314
00315 if (jblk > 1) {
00316 eps1 = (r__1 = eps * xj, dabs(r__1));
00317 pertol = eps1 * 10.f;
00318 sep = xj - xjm;
00319 if (sep < pertol) {
00320 xj = xjm + pertol;
00321 }
00322 }
00323
00324 its = 0;
00325 nrmchk = 0;
00326
00327
00328
00329 slarnv_(&c__2, iseed, &blksiz, &work[indrv1 + 1]);
00330
00331
00332
00333 scopy_(&blksiz, &d__[b1], &c__1, &work[indrv4 + 1], &c__1);
00334 i__3 = blksiz - 1;
00335 scopy_(&i__3, &e[b1], &c__1, &work[indrv2 + 2], &c__1);
00336 i__3 = blksiz - 1;
00337 scopy_(&i__3, &e[b1], &c__1, &work[indrv3 + 1], &c__1);
00338
00339
00340
00341 tol = 0.f;
00342 slagtf_(&blksiz, &work[indrv4 + 1], &xj, &work[indrv2 + 2], &work[
00343 indrv3 + 1], &tol, &work[indrv5 + 1], &iwork[1], &iinfo);
00344
00345
00346
00347 L70:
00348 ++its;
00349 if (its > 5) {
00350 goto L100;
00351 }
00352
00353
00354
00355
00356 r__2 = eps, r__3 = (r__1 = work[indrv4 + blksiz], dabs(r__1));
00357 scl = blksiz * onenrm * dmax(r__2,r__3) / sasum_(&blksiz, &work[
00358 indrv1 + 1], &c__1);
00359 sscal_(&blksiz, &scl, &work[indrv1 + 1], &c__1);
00360
00361
00362
00363 slagts_(&c_n1, &blksiz, &work[indrv4 + 1], &work[indrv2 + 2], &
00364 work[indrv3 + 1], &work[indrv5 + 1], &iwork[1], &work[
00365 indrv1 + 1], &tol, &iinfo);
00366
00367
00368
00369
00370 if (jblk == 1) {
00371 goto L90;
00372 }
00373 if ((r__1 = xj - xjm, dabs(r__1)) > ortol) {
00374 gpind = j;
00375 }
00376 if (gpind != j) {
00377 i__3 = j - 1;
00378 for (i__ = gpind; i__ <= i__3; ++i__) {
00379 ctr = -sdot_(&blksiz, &work[indrv1 + 1], &c__1, &z__[b1 +
00380 i__ * z_dim1], &c__1);
00381 saxpy_(&blksiz, &ctr, &z__[b1 + i__ * z_dim1], &c__1, &
00382 work[indrv1 + 1], &c__1);
00383
00384 }
00385 }
00386
00387
00388
00389 L90:
00390 jmax = isamax_(&blksiz, &work[indrv1 + 1], &c__1);
00391 nrm = (r__1 = work[indrv1 + jmax], dabs(r__1));
00392
00393
00394
00395
00396 if (nrm < stpcrt) {
00397 goto L70;
00398 }
00399 ++nrmchk;
00400 if (nrmchk < 3) {
00401 goto L70;
00402 }
00403
00404 goto L110;
00405
00406
00407
00408
00409 L100:
00410 ++(*info);
00411 ifail[*info] = j;
00412
00413
00414
00415 L110:
00416 scl = 1.f / snrm2_(&blksiz, &work[indrv1 + 1], &c__1);
00417 jmax = isamax_(&blksiz, &work[indrv1 + 1], &c__1);
00418 if (work[indrv1 + jmax] < 0.f) {
00419 scl = -scl;
00420 }
00421 sscal_(&blksiz, &scl, &work[indrv1 + 1], &c__1);
00422 L120:
00423 i__3 = *n;
00424 for (i__ = 1; i__ <= i__3; ++i__) {
00425 z__[i__ + j * z_dim1] = 0.f;
00426
00427 }
00428 i__3 = blksiz;
00429 for (i__ = 1; i__ <= i__3; ++i__) {
00430 z__[b1 + i__ - 1 + j * z_dim1] = work[indrv1 + i__];
00431
00432 }
00433
00434
00435
00436
00437 xjm = xj;
00438
00439
00440 }
00441 L160:
00442 ;
00443 }
00444
00445 return 0;
00446
00447
00448
00449 }