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