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__1 = 1;
00019
00020 int ztbrfs_(char *uplo, char *trans, char *diag, integer *n,
00021 integer *kd, integer *nrhs, doublecomplex *ab, integer *ldab,
00022 doublecomplex *b, integer *ldb, doublecomplex *x, integer *ldx,
00023 doublereal *ferr, doublereal *berr, doublecomplex *work, doublereal *
00024 rwork, integer *info)
00025 {
00026
00027 integer ab_dim1, ab_offset, b_dim1, b_offset, x_dim1, x_offset, i__1,
00028 i__2, i__3, i__4, i__5;
00029 doublereal d__1, d__2, d__3, d__4;
00030 doublecomplex z__1;
00031
00032
00033 double d_imag(doublecomplex *);
00034
00035
00036 integer i__, j, k;
00037 doublereal s, xk;
00038 integer nz;
00039 doublereal eps;
00040 integer kase;
00041 doublereal safe1, safe2;
00042 extern logical lsame_(char *, char *);
00043 integer isave[3];
00044 logical upper;
00045 extern int ztbmv_(char *, char *, char *, integer *,
00046 integer *, doublecomplex *, integer *, doublecomplex *, integer *), zcopy_(integer *, doublecomplex *,
00047 integer *, doublecomplex *, integer *), ztbsv_(char *, char *,
00048 char *, integer *, integer *, doublecomplex *, integer *,
00049 doublecomplex *, integer *), zaxpy_(
00050 integer *, doublecomplex *, doublecomplex *, integer *,
00051 doublecomplex *, integer *), zlacn2_(integer *, doublecomplex *,
00052 doublecomplex *, doublereal *, integer *, integer *);
00053 extern doublereal dlamch_(char *);
00054 doublereal safmin;
00055 extern int xerbla_(char *, integer *);
00056 logical notran;
00057 char transn[1], transt[1];
00058 logical nounit;
00059 doublereal 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
00182 ab_dim1 = *ldab;
00183 ab_offset = 1 + ab_dim1;
00184 ab -= ab_offset;
00185 b_dim1 = *ldb;
00186 b_offset = 1 + b_dim1;
00187 b -= b_offset;
00188 x_dim1 = *ldx;
00189 x_offset = 1 + x_dim1;
00190 x -= x_offset;
00191 --ferr;
00192 --berr;
00193 --work;
00194 --rwork;
00195
00196
00197 *info = 0;
00198 upper = lsame_(uplo, "U");
00199 notran = lsame_(trans, "N");
00200 nounit = lsame_(diag, "N");
00201
00202 if (! upper && ! lsame_(uplo, "L")) {
00203 *info = -1;
00204 } else if (! notran && ! lsame_(trans, "T") && !
00205 lsame_(trans, "C")) {
00206 *info = -2;
00207 } else if (! nounit && ! lsame_(diag, "U")) {
00208 *info = -3;
00209 } else if (*n < 0) {
00210 *info = -4;
00211 } else if (*kd < 0) {
00212 *info = -5;
00213 } else if (*nrhs < 0) {
00214 *info = -6;
00215 } else if (*ldab < *kd + 1) {
00216 *info = -8;
00217 } else if (*ldb < max(1,*n)) {
00218 *info = -10;
00219 } else if (*ldx < max(1,*n)) {
00220 *info = -12;
00221 }
00222 if (*info != 0) {
00223 i__1 = -(*info);
00224 xerbla_("ZTBRFS", &i__1);
00225 return 0;
00226 }
00227
00228
00229
00230 if (*n == 0 || *nrhs == 0) {
00231 i__1 = *nrhs;
00232 for (j = 1; j <= i__1; ++j) {
00233 ferr[j] = 0.;
00234 berr[j] = 0.;
00235
00236 }
00237 return 0;
00238 }
00239
00240 if (notran) {
00241 *(unsigned char *)transn = 'N';
00242 *(unsigned char *)transt = 'C';
00243 } else {
00244 *(unsigned char *)transn = 'C';
00245 *(unsigned char *)transt = 'N';
00246 }
00247
00248
00249
00250 nz = *kd + 2;
00251 eps = dlamch_("Epsilon");
00252 safmin = dlamch_("Safe minimum");
00253 safe1 = nz * safmin;
00254 safe2 = safe1 / eps;
00255
00256
00257
00258 i__1 = *nrhs;
00259 for (j = 1; j <= i__1; ++j) {
00260
00261
00262
00263
00264 zcopy_(n, &x[j * x_dim1 + 1], &c__1, &work[1], &c__1);
00265 ztbmv_(uplo, trans, diag, n, kd, &ab[ab_offset], ldab, &work[1], &
00266 c__1);
00267 z__1.r = -1., z__1.i = -0.;
00268 zaxpy_(n, &z__1, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1);
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 i__2 = *n;
00280 for (i__ = 1; i__ <= i__2; ++i__) {
00281 i__3 = i__ + j * b_dim1;
00282 rwork[i__] = (d__1 = b[i__3].r, abs(d__1)) + (d__2 = d_imag(&b[
00283 i__ + j * b_dim1]), abs(d__2));
00284
00285 }
00286
00287 if (notran) {
00288
00289
00290
00291 if (upper) {
00292 if (nounit) {
00293 i__2 = *n;
00294 for (k = 1; k <= i__2; ++k) {
00295 i__3 = k + j * x_dim1;
00296 xk = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&
00297 x[k + j * x_dim1]), abs(d__2));
00298
00299 i__3 = 1, i__4 = k - *kd;
00300 i__5 = k;
00301 for (i__ = max(i__3,i__4); i__ <= i__5; ++i__) {
00302 i__3 = *kd + 1 + i__ - k + k * ab_dim1;
00303 rwork[i__] += ((d__1 = ab[i__3].r, abs(d__1)) + (
00304 d__2 = d_imag(&ab[*kd + 1 + i__ - k + k *
00305 ab_dim1]), abs(d__2))) * xk;
00306
00307 }
00308
00309 }
00310 } else {
00311 i__2 = *n;
00312 for (k = 1; k <= i__2; ++k) {
00313 i__5 = k + j * x_dim1;
00314 xk = (d__1 = x[i__5].r, abs(d__1)) + (d__2 = d_imag(&
00315 x[k + j * x_dim1]), abs(d__2));
00316
00317 i__5 = 1, i__3 = k - *kd;
00318 i__4 = k - 1;
00319 for (i__ = max(i__5,i__3); i__ <= i__4; ++i__) {
00320 i__5 = *kd + 1 + i__ - k + k * ab_dim1;
00321 rwork[i__] += ((d__1 = ab[i__5].r, abs(d__1)) + (
00322 d__2 = d_imag(&ab[*kd + 1 + i__ - k + k *
00323 ab_dim1]), abs(d__2))) * xk;
00324
00325 }
00326 rwork[k] += xk;
00327
00328 }
00329 }
00330 } else {
00331 if (nounit) {
00332 i__2 = *n;
00333 for (k = 1; k <= i__2; ++k) {
00334 i__4 = k + j * x_dim1;
00335 xk = (d__1 = x[i__4].r, abs(d__1)) + (d__2 = d_imag(&
00336 x[k + j * x_dim1]), abs(d__2));
00337
00338 i__5 = *n, i__3 = k + *kd;
00339 i__4 = min(i__5,i__3);
00340 for (i__ = k; i__ <= i__4; ++i__) {
00341 i__5 = i__ + 1 - k + k * ab_dim1;
00342 rwork[i__] += ((d__1 = ab[i__5].r, abs(d__1)) + (
00343 d__2 = d_imag(&ab[i__ + 1 - k + k *
00344 ab_dim1]), abs(d__2))) * xk;
00345
00346 }
00347
00348 }
00349 } else {
00350 i__2 = *n;
00351 for (k = 1; k <= i__2; ++k) {
00352 i__4 = k + j * x_dim1;
00353 xk = (d__1 = x[i__4].r, abs(d__1)) + (d__2 = d_imag(&
00354 x[k + j * x_dim1]), abs(d__2));
00355
00356 i__5 = *n, i__3 = k + *kd;
00357 i__4 = min(i__5,i__3);
00358 for (i__ = k + 1; i__ <= i__4; ++i__) {
00359 i__5 = i__ + 1 - k + k * ab_dim1;
00360 rwork[i__] += ((d__1 = ab[i__5].r, abs(d__1)) + (
00361 d__2 = d_imag(&ab[i__ + 1 - k + k *
00362 ab_dim1]), abs(d__2))) * xk;
00363
00364 }
00365 rwork[k] += xk;
00366
00367 }
00368 }
00369 }
00370 } else {
00371
00372
00373
00374 if (upper) {
00375 if (nounit) {
00376 i__2 = *n;
00377 for (k = 1; k <= i__2; ++k) {
00378 s = 0.;
00379
00380 i__4 = 1, i__5 = k - *kd;
00381 i__3 = k;
00382 for (i__ = max(i__4,i__5); i__ <= i__3; ++i__) {
00383 i__4 = *kd + 1 + i__ - k + k * ab_dim1;
00384 i__5 = i__ + j * x_dim1;
00385 s += ((d__1 = ab[i__4].r, abs(d__1)) + (d__2 =
00386 d_imag(&ab[*kd + 1 + i__ - k + k *
00387 ab_dim1]), abs(d__2))) * ((d__3 = x[i__5]
00388 .r, abs(d__3)) + (d__4 = d_imag(&x[i__ +
00389 j * x_dim1]), abs(d__4)));
00390
00391 }
00392 rwork[k] += s;
00393
00394 }
00395 } else {
00396 i__2 = *n;
00397 for (k = 1; k <= i__2; ++k) {
00398 i__3 = k + j * x_dim1;
00399 s = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[
00400 k + j * x_dim1]), abs(d__2));
00401
00402 i__3 = 1, i__4 = k - *kd;
00403 i__5 = k - 1;
00404 for (i__ = max(i__3,i__4); i__ <= i__5; ++i__) {
00405 i__3 = *kd + 1 + i__ - k + k * ab_dim1;
00406 i__4 = i__ + j * x_dim1;
00407 s += ((d__1 = ab[i__3].r, abs(d__1)) + (d__2 =
00408 d_imag(&ab[*kd + 1 + i__ - k + k *
00409 ab_dim1]), abs(d__2))) * ((d__3 = x[i__4]
00410 .r, abs(d__3)) + (d__4 = d_imag(&x[i__ +
00411 j * x_dim1]), abs(d__4)));
00412
00413 }
00414 rwork[k] += s;
00415
00416 }
00417 }
00418 } else {
00419 if (nounit) {
00420 i__2 = *n;
00421 for (k = 1; k <= i__2; ++k) {
00422 s = 0.;
00423
00424 i__3 = *n, i__4 = k + *kd;
00425 i__5 = min(i__3,i__4);
00426 for (i__ = k; i__ <= i__5; ++i__) {
00427 i__3 = i__ + 1 - k + k * ab_dim1;
00428 i__4 = i__ + j * x_dim1;
00429 s += ((d__1 = ab[i__3].r, abs(d__1)) + (d__2 =
00430 d_imag(&ab[i__ + 1 - k + k * ab_dim1]),
00431 abs(d__2))) * ((d__3 = x[i__4].r, abs(
00432 d__3)) + (d__4 = d_imag(&x[i__ + j *
00433 x_dim1]), abs(d__4)));
00434
00435 }
00436 rwork[k] += s;
00437
00438 }
00439 } else {
00440 i__2 = *n;
00441 for (k = 1; k <= i__2; ++k) {
00442 i__5 = k + j * x_dim1;
00443 s = (d__1 = x[i__5].r, abs(d__1)) + (d__2 = d_imag(&x[
00444 k + j * x_dim1]), abs(d__2));
00445
00446 i__3 = *n, i__4 = k + *kd;
00447 i__5 = min(i__3,i__4);
00448 for (i__ = k + 1; i__ <= i__5; ++i__) {
00449 i__3 = i__ + 1 - k + k * ab_dim1;
00450 i__4 = i__ + j * x_dim1;
00451 s += ((d__1 = ab[i__3].r, abs(d__1)) + (d__2 =
00452 d_imag(&ab[i__ + 1 - k + k * ab_dim1]),
00453 abs(d__2))) * ((d__3 = x[i__4].r, abs(
00454 d__3)) + (d__4 = d_imag(&x[i__ + j *
00455 x_dim1]), abs(d__4)));
00456
00457 }
00458 rwork[k] += s;
00459
00460 }
00461 }
00462 }
00463 }
00464 s = 0.;
00465 i__2 = *n;
00466 for (i__ = 1; i__ <= i__2; ++i__) {
00467 if (rwork[i__] > safe2) {
00468
00469 i__5 = i__;
00470 d__3 = s, d__4 = ((d__1 = work[i__5].r, abs(d__1)) + (d__2 =
00471 d_imag(&work[i__]), abs(d__2))) / rwork[i__];
00472 s = max(d__3,d__4);
00473 } else {
00474
00475 i__5 = i__;
00476 d__3 = s, d__4 = ((d__1 = work[i__5].r, abs(d__1)) + (d__2 =
00477 d_imag(&work[i__]), abs(d__2)) + safe1) / (rwork[i__]
00478 + safe1);
00479 s = max(d__3,d__4);
00480 }
00481
00482 }
00483 berr[j] = s;
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507 i__2 = *n;
00508 for (i__ = 1; i__ <= i__2; ++i__) {
00509 if (rwork[i__] > safe2) {
00510 i__5 = i__;
00511 rwork[i__] = (d__1 = work[i__5].r, abs(d__1)) + (d__2 =
00512 d_imag(&work[i__]), abs(d__2)) + nz * eps * rwork[i__]
00513 ;
00514 } else {
00515 i__5 = i__;
00516 rwork[i__] = (d__1 = work[i__5].r, abs(d__1)) + (d__2 =
00517 d_imag(&work[i__]), abs(d__2)) + nz * eps * rwork[i__]
00518 + safe1;
00519 }
00520
00521 }
00522
00523 kase = 0;
00524 L210:
00525 zlacn2_(n, &work[*n + 1], &work[1], &ferr[j], &kase, isave);
00526 if (kase != 0) {
00527 if (kase == 1) {
00528
00529
00530
00531 ztbsv_(uplo, transt, diag, n, kd, &ab[ab_offset], ldab, &work[
00532 1], &c__1);
00533 i__2 = *n;
00534 for (i__ = 1; i__ <= i__2; ++i__) {
00535 i__5 = i__;
00536 i__3 = i__;
00537 i__4 = i__;
00538 z__1.r = rwork[i__3] * work[i__4].r, z__1.i = rwork[i__3]
00539 * work[i__4].i;
00540 work[i__5].r = z__1.r, work[i__5].i = z__1.i;
00541
00542 }
00543 } else {
00544
00545
00546
00547 i__2 = *n;
00548 for (i__ = 1; i__ <= i__2; ++i__) {
00549 i__5 = i__;
00550 i__3 = i__;
00551 i__4 = i__;
00552 z__1.r = rwork[i__3] * work[i__4].r, z__1.i = rwork[i__3]
00553 * work[i__4].i;
00554 work[i__5].r = z__1.r, work[i__5].i = z__1.i;
00555
00556 }
00557 ztbsv_(uplo, transn, diag, n, kd, &ab[ab_offset], ldab, &work[
00558 1], &c__1);
00559 }
00560 goto L210;
00561 }
00562
00563
00564
00565 lstres = 0.;
00566 i__2 = *n;
00567 for (i__ = 1; i__ <= i__2; ++i__) {
00568
00569 i__5 = i__ + j * x_dim1;
00570 d__3 = lstres, d__4 = (d__1 = x[i__5].r, abs(d__1)) + (d__2 =
00571 d_imag(&x[i__ + j * x_dim1]), abs(d__2));
00572 lstres = max(d__3,d__4);
00573
00574 }
00575 if (lstres != 0.) {
00576 ferr[j] /= lstres;
00577 }
00578
00579
00580 }
00581
00582 return 0;
00583
00584
00585
00586 }