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 doublecomplex c_b1 = {1.,0.};
00019 static integer c__1 = 1;
00020
00021 int zpbrfs_(char *uplo, integer *n, integer *kd, integer *
00022 nrhs, doublecomplex *ab, integer *ldab, doublecomplex *afb, integer *
00023 ldafb, doublecomplex *b, integer *ldb, doublecomplex *x, integer *ldx,
00024 doublereal *ferr, doublereal *berr, doublecomplex *work, doublereal *
00025 rwork, integer *info)
00026 {
00027
00028 integer ab_dim1, ab_offset, afb_dim1, afb_offset, b_dim1, b_offset,
00029 x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5;
00030 doublereal d__1, d__2, d__3, d__4;
00031 doublecomplex z__1;
00032
00033
00034 double d_imag(doublecomplex *);
00035
00036
00037 integer i__, j, k, l;
00038 doublereal s, xk;
00039 integer nz;
00040 doublereal eps;
00041 integer kase;
00042 doublereal safe1, safe2;
00043 extern logical lsame_(char *, char *);
00044 integer isave[3];
00045 extern int zhbmv_(char *, integer *, integer *,
00046 doublecomplex *, doublecomplex *, integer *, doublecomplex *,
00047 integer *, doublecomplex *, doublecomplex *, integer *);
00048 integer count;
00049 logical upper;
00050 extern int zcopy_(integer *, doublecomplex *, integer *,
00051 doublecomplex *, integer *), zaxpy_(integer *, doublecomplex *,
00052 doublecomplex *, integer *, doublecomplex *, integer *), zlacn2_(
00053 integer *, doublecomplex *, doublecomplex *, doublereal *,
00054 integer *, integer *);
00055 extern doublereal dlamch_(char *);
00056 doublereal safmin;
00057 extern int xerbla_(char *, integer *);
00058 doublereal lstres;
00059 extern int zpbtrs_(char *, integer *, integer *, integer
00060 *, doublecomplex *, integer *, doublecomplex *, integer *,
00061 integer *);
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 ab_dim1 = *ldab;
00184 ab_offset = 1 + ab_dim1;
00185 ab -= ab_offset;
00186 afb_dim1 = *ldafb;
00187 afb_offset = 1 + afb_dim1;
00188 afb -= afb_offset;
00189 b_dim1 = *ldb;
00190 b_offset = 1 + b_dim1;
00191 b -= b_offset;
00192 x_dim1 = *ldx;
00193 x_offset = 1 + x_dim1;
00194 x -= x_offset;
00195 --ferr;
00196 --berr;
00197 --work;
00198 --rwork;
00199
00200
00201 *info = 0;
00202 upper = lsame_(uplo, "U");
00203 if (! upper && ! lsame_(uplo, "L")) {
00204 *info = -1;
00205 } else if (*n < 0) {
00206 *info = -2;
00207 } else if (*kd < 0) {
00208 *info = -3;
00209 } else if (*nrhs < 0) {
00210 *info = -4;
00211 } else if (*ldab < *kd + 1) {
00212 *info = -6;
00213 } else if (*ldafb < *kd + 1) {
00214 *info = -8;
00215 } else if (*ldb < max(1,*n)) {
00216 *info = -10;
00217 } else if (*ldx < max(1,*n)) {
00218 *info = -12;
00219 }
00220 if (*info != 0) {
00221 i__1 = -(*info);
00222 xerbla_("ZPBRFS", &i__1);
00223 return 0;
00224 }
00225
00226
00227
00228 if (*n == 0 || *nrhs == 0) {
00229 i__1 = *nrhs;
00230 for (j = 1; j <= i__1; ++j) {
00231 ferr[j] = 0.;
00232 berr[j] = 0.;
00233
00234 }
00235 return 0;
00236 }
00237
00238
00239
00240
00241 i__1 = *n + 1, i__2 = (*kd << 1) + 2;
00242 nz = min(i__1,i__2);
00243 eps = dlamch_("Epsilon");
00244 safmin = dlamch_("Safe minimum");
00245 safe1 = nz * safmin;
00246 safe2 = safe1 / eps;
00247
00248
00249
00250 i__1 = *nrhs;
00251 for (j = 1; j <= i__1; ++j) {
00252
00253 count = 1;
00254 lstres = 3.;
00255 L20:
00256
00257
00258
00259
00260
00261 zcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1);
00262 z__1.r = -1., z__1.i = -0.;
00263 zhbmv_(uplo, n, kd, &z__1, &ab[ab_offset], ldab, &x[j * x_dim1 + 1], &
00264 c__1, &c_b1, &work[1], &c__1);
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 i__2 = *n;
00276 for (i__ = 1; i__ <= i__2; ++i__) {
00277 i__3 = i__ + j * b_dim1;
00278 rwork[i__] = (d__1 = b[i__3].r, abs(d__1)) + (d__2 = d_imag(&b[
00279 i__ + j * b_dim1]), abs(d__2));
00280
00281 }
00282
00283
00284
00285 if (upper) {
00286 i__2 = *n;
00287 for (k = 1; k <= i__2; ++k) {
00288 s = 0.;
00289 i__3 = k + j * x_dim1;
00290 xk = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[k + j *
00291 x_dim1]), abs(d__2));
00292 l = *kd + 1 - k;
00293
00294 i__3 = 1, i__4 = k - *kd;
00295 i__5 = k - 1;
00296 for (i__ = max(i__3,i__4); i__ <= i__5; ++i__) {
00297 i__3 = l + i__ + k * ab_dim1;
00298 rwork[i__] += ((d__1 = ab[i__3].r, abs(d__1)) + (d__2 =
00299 d_imag(&ab[l + i__ + k * ab_dim1]), abs(d__2))) *
00300 xk;
00301 i__3 = l + i__ + k * ab_dim1;
00302 i__4 = i__ + j * x_dim1;
00303 s += ((d__1 = ab[i__3].r, abs(d__1)) + (d__2 = d_imag(&ab[
00304 l + i__ + k * ab_dim1]), abs(d__2))) * ((d__3 = x[
00305 i__4].r, abs(d__3)) + (d__4 = d_imag(&x[i__ + j *
00306 x_dim1]), abs(d__4)));
00307
00308 }
00309 i__5 = *kd + 1 + k * ab_dim1;
00310 rwork[k] = rwork[k] + (d__1 = ab[i__5].r, abs(d__1)) * xk + s;
00311
00312 }
00313 } else {
00314 i__2 = *n;
00315 for (k = 1; k <= i__2; ++k) {
00316 s = 0.;
00317 i__5 = k + j * x_dim1;
00318 xk = (d__1 = x[i__5].r, abs(d__1)) + (d__2 = d_imag(&x[k + j *
00319 x_dim1]), abs(d__2));
00320 i__5 = k * ab_dim1 + 1;
00321 rwork[k] += (d__1 = ab[i__5].r, abs(d__1)) * xk;
00322 l = 1 - k;
00323
00324 i__3 = *n, i__4 = k + *kd;
00325 i__5 = min(i__3,i__4);
00326 for (i__ = k + 1; i__ <= i__5; ++i__) {
00327 i__3 = l + i__ + k * ab_dim1;
00328 rwork[i__] += ((d__1 = ab[i__3].r, abs(d__1)) + (d__2 =
00329 d_imag(&ab[l + i__ + k * ab_dim1]), abs(d__2))) *
00330 xk;
00331 i__3 = l + i__ + k * ab_dim1;
00332 i__4 = i__ + j * x_dim1;
00333 s += ((d__1 = ab[i__3].r, abs(d__1)) + (d__2 = d_imag(&ab[
00334 l + i__ + k * ab_dim1]), abs(d__2))) * ((d__3 = x[
00335 i__4].r, abs(d__3)) + (d__4 = d_imag(&x[i__ + j *
00336 x_dim1]), abs(d__4)));
00337
00338 }
00339 rwork[k] += s;
00340
00341 }
00342 }
00343 s = 0.;
00344 i__2 = *n;
00345 for (i__ = 1; i__ <= i__2; ++i__) {
00346 if (rwork[i__] > safe2) {
00347
00348 i__5 = i__;
00349 d__3 = s, d__4 = ((d__1 = work[i__5].r, abs(d__1)) + (d__2 =
00350 d_imag(&work[i__]), abs(d__2))) / rwork[i__];
00351 s = max(d__3,d__4);
00352 } else {
00353
00354 i__5 = i__;
00355 d__3 = s, d__4 = ((d__1 = work[i__5].r, abs(d__1)) + (d__2 =
00356 d_imag(&work[i__]), abs(d__2)) + safe1) / (rwork[i__]
00357 + safe1);
00358 s = max(d__3,d__4);
00359 }
00360
00361 }
00362 berr[j] = s;
00363
00364
00365
00366
00367
00368
00369
00370 if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) {
00371
00372
00373
00374 zpbtrs_(uplo, n, kd, &c__1, &afb[afb_offset], ldafb, &work[1], n,
00375 info);
00376 zaxpy_(n, &c_b1, &work[1], &c__1, &x[j * x_dim1 + 1], &c__1);
00377 lstres = berr[j];
00378 ++count;
00379 goto L20;
00380 }
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404 i__2 = *n;
00405 for (i__ = 1; i__ <= i__2; ++i__) {
00406 if (rwork[i__] > safe2) {
00407 i__5 = i__;
00408 rwork[i__] = (d__1 = work[i__5].r, abs(d__1)) + (d__2 =
00409 d_imag(&work[i__]), abs(d__2)) + nz * eps * rwork[i__]
00410 ;
00411 } else {
00412 i__5 = i__;
00413 rwork[i__] = (d__1 = work[i__5].r, abs(d__1)) + (d__2 =
00414 d_imag(&work[i__]), abs(d__2)) + nz * eps * rwork[i__]
00415 + safe1;
00416 }
00417
00418 }
00419
00420 kase = 0;
00421 L100:
00422 zlacn2_(n, &work[*n + 1], &work[1], &ferr[j], &kase, isave);
00423 if (kase != 0) {
00424 if (kase == 1) {
00425
00426
00427
00428 zpbtrs_(uplo, n, kd, &c__1, &afb[afb_offset], ldafb, &work[1],
00429 n, info);
00430 i__2 = *n;
00431 for (i__ = 1; i__ <= i__2; ++i__) {
00432 i__5 = i__;
00433 i__3 = i__;
00434 i__4 = i__;
00435 z__1.r = rwork[i__3] * work[i__4].r, z__1.i = rwork[i__3]
00436 * work[i__4].i;
00437 work[i__5].r = z__1.r, work[i__5].i = z__1.i;
00438
00439 }
00440 } else if (kase == 2) {
00441
00442
00443
00444 i__2 = *n;
00445 for (i__ = 1; i__ <= i__2; ++i__) {
00446 i__5 = i__;
00447 i__3 = i__;
00448 i__4 = i__;
00449 z__1.r = rwork[i__3] * work[i__4].r, z__1.i = rwork[i__3]
00450 * work[i__4].i;
00451 work[i__5].r = z__1.r, work[i__5].i = z__1.i;
00452
00453 }
00454 zpbtrs_(uplo, n, kd, &c__1, &afb[afb_offset], ldafb, &work[1],
00455 n, info);
00456 }
00457 goto L100;
00458 }
00459
00460
00461
00462 lstres = 0.;
00463 i__2 = *n;
00464 for (i__ = 1; i__ <= i__2; ++i__) {
00465
00466 i__5 = i__ + j * x_dim1;
00467 d__3 = lstres, d__4 = (d__1 = x[i__5].r, abs(d__1)) + (d__2 =
00468 d_imag(&x[i__ + j * x_dim1]), abs(d__2));
00469 lstres = max(d__3,d__4);
00470
00471 }
00472 if (lstres != 0.) {
00473 ferr[j] /= lstres;
00474 }
00475
00476
00477 }
00478
00479 return 0;
00480
00481
00482
00483 }