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