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 static doublereal c_b15 = -1.;
00020 static doublereal c_b17 = 1.;
00021
00022 int dgerfs_(char *trans, integer *n, integer *nrhs,
00023 doublereal *a, integer *lda, doublereal *af, integer *ldaf, integer *
00024 ipiv, doublereal *b, integer *ldb, doublereal *x, integer *ldx,
00025 doublereal *ferr, doublereal *berr, doublereal *work, integer *iwork,
00026 integer *info)
00027 {
00028
00029 integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1,
00030 x_offset, i__1, i__2, i__3;
00031 doublereal d__1, d__2, d__3;
00032
00033
00034 integer i__, j, k;
00035 doublereal s, xk;
00036 integer nz;
00037 doublereal eps;
00038 integer kase;
00039 doublereal safe1, safe2;
00040 extern logical lsame_(char *, char *);
00041 extern int dgemv_(char *, integer *, integer *,
00042 doublereal *, doublereal *, integer *, doublereal *, integer *,
00043 doublereal *, doublereal *, integer *);
00044 integer isave[3];
00045 extern int dcopy_(integer *, doublereal *, integer *,
00046 doublereal *, integer *), daxpy_(integer *, doublereal *,
00047 doublereal *, integer *, doublereal *, integer *);
00048 integer count;
00049 extern int dlacn2_(integer *, doublereal *, doublereal *,
00050 integer *, doublereal *, integer *, integer *);
00051 extern doublereal dlamch_(char *);
00052 doublereal safmin;
00053 extern int xerbla_(char *, integer *), dgetrs_(
00054 char *, integer *, integer *, doublereal *, integer *, integer *,
00055 doublereal *, integer *, integer *);
00056 logical notran;
00057 char transt[1];
00058 doublereal lstres;
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 a_dim1 = *lda;
00173 a_offset = 1 + a_dim1;
00174 a -= a_offset;
00175 af_dim1 = *ldaf;
00176 af_offset = 1 + af_dim1;
00177 af -= af_offset;
00178 --ipiv;
00179 b_dim1 = *ldb;
00180 b_offset = 1 + b_dim1;
00181 b -= b_offset;
00182 x_dim1 = *ldx;
00183 x_offset = 1 + x_dim1;
00184 x -= x_offset;
00185 --ferr;
00186 --berr;
00187 --work;
00188 --iwork;
00189
00190
00191 *info = 0;
00192 notran = lsame_(trans, "N");
00193 if (! notran && ! lsame_(trans, "T") && ! lsame_(
00194 trans, "C")) {
00195 *info = -1;
00196 } else if (*n < 0) {
00197 *info = -2;
00198 } else if (*nrhs < 0) {
00199 *info = -3;
00200 } else if (*lda < max(1,*n)) {
00201 *info = -5;
00202 } else if (*ldaf < max(1,*n)) {
00203 *info = -7;
00204 } else if (*ldb < max(1,*n)) {
00205 *info = -10;
00206 } else if (*ldx < max(1,*n)) {
00207 *info = -12;
00208 }
00209 if (*info != 0) {
00210 i__1 = -(*info);
00211 xerbla_("DGERFS", &i__1);
00212 return 0;
00213 }
00214
00215
00216
00217 if (*n == 0 || *nrhs == 0) {
00218 i__1 = *nrhs;
00219 for (j = 1; j <= i__1; ++j) {
00220 ferr[j] = 0.;
00221 berr[j] = 0.;
00222
00223 }
00224 return 0;
00225 }
00226
00227 if (notran) {
00228 *(unsigned char *)transt = 'T';
00229 } else {
00230 *(unsigned char *)transt = 'N';
00231 }
00232
00233
00234
00235 nz = *n + 1;
00236 eps = dlamch_("Epsilon");
00237 safmin = dlamch_("Safe minimum");
00238 safe1 = nz * safmin;
00239 safe2 = safe1 / eps;
00240
00241
00242
00243 i__1 = *nrhs;
00244 for (j = 1; j <= i__1; ++j) {
00245
00246 count = 1;
00247 lstres = 3.;
00248 L20:
00249
00250
00251
00252
00253
00254
00255 dcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[*n + 1], &c__1);
00256 dgemv_(trans, n, n, &c_b15, &a[a_offset], lda, &x[j * x_dim1 + 1], &
00257 c__1, &c_b17, &work[*n + 1], &c__1);
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 i__2 = *n;
00269 for (i__ = 1; i__ <= i__2; ++i__) {
00270 work[i__] = (d__1 = b[i__ + j * b_dim1], abs(d__1));
00271
00272 }
00273
00274
00275
00276 if (notran) {
00277 i__2 = *n;
00278 for (k = 1; k <= i__2; ++k) {
00279 xk = (d__1 = x[k + j * x_dim1], abs(d__1));
00280 i__3 = *n;
00281 for (i__ = 1; i__ <= i__3; ++i__) {
00282 work[i__] += (d__1 = a[i__ + k * a_dim1], abs(d__1)) * xk;
00283
00284 }
00285
00286 }
00287 } else {
00288 i__2 = *n;
00289 for (k = 1; k <= i__2; ++k) {
00290 s = 0.;
00291 i__3 = *n;
00292 for (i__ = 1; i__ <= i__3; ++i__) {
00293 s += (d__1 = a[i__ + k * a_dim1], abs(d__1)) * (d__2 = x[
00294 i__ + j * x_dim1], abs(d__2));
00295
00296 }
00297 work[k] += s;
00298
00299 }
00300 }
00301 s = 0.;
00302 i__2 = *n;
00303 for (i__ = 1; i__ <= i__2; ++i__) {
00304 if (work[i__] > safe2) {
00305
00306 d__2 = s, d__3 = (d__1 = work[*n + i__], abs(d__1)) / work[
00307 i__];
00308 s = max(d__2,d__3);
00309 } else {
00310
00311 d__2 = s, d__3 = ((d__1 = work[*n + i__], abs(d__1)) + safe1)
00312 / (work[i__] + safe1);
00313 s = max(d__2,d__3);
00314 }
00315
00316 }
00317 berr[j] = s;
00318
00319
00320
00321
00322
00323
00324
00325 if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) {
00326
00327
00328
00329 dgetrs_(trans, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[*n
00330 + 1], n, info);
00331 daxpy_(n, &c_b17, &work[*n + 1], &c__1, &x[j * x_dim1 + 1], &c__1)
00332 ;
00333 lstres = berr[j];
00334 ++count;
00335 goto L20;
00336 }
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360 i__2 = *n;
00361 for (i__ = 1; i__ <= i__2; ++i__) {
00362 if (work[i__] > safe2) {
00363 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps *
00364 work[i__];
00365 } else {
00366 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps *
00367 work[i__] + safe1;
00368 }
00369
00370 }
00371
00372 kase = 0;
00373 L100:
00374 dlacn2_(n, &work[(*n << 1) + 1], &work[*n + 1], &iwork[1], &ferr[j], &
00375 kase, isave);
00376 if (kase != 0) {
00377 if (kase == 1) {
00378
00379
00380
00381 dgetrs_(transt, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &
00382 work[*n + 1], n, info);
00383 i__2 = *n;
00384 for (i__ = 1; i__ <= i__2; ++i__) {
00385 work[*n + i__] = work[i__] * work[*n + i__];
00386
00387 }
00388 } else {
00389
00390
00391
00392 i__2 = *n;
00393 for (i__ = 1; i__ <= i__2; ++i__) {
00394 work[*n + i__] = work[i__] * work[*n + i__];
00395
00396 }
00397 dgetrs_(trans, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &
00398 work[*n + 1], n, info);
00399 }
00400 goto L100;
00401 }
00402
00403
00404
00405 lstres = 0.;
00406 i__2 = *n;
00407 for (i__ = 1; i__ <= i__2; ++i__) {
00408
00409 d__2 = lstres, d__3 = (d__1 = x[i__ + j * x_dim1], abs(d__1));
00410 lstres = max(d__2,d__3);
00411
00412 }
00413 if (lstres != 0.) {
00414 ferr[j] /= lstres;
00415 }
00416
00417
00418 }
00419
00420 return 0;
00421
00422
00423
00424 }