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 zhetrs_(char *uplo, integer *n, integer *nrhs,
00022 doublecomplex *a, integer *lda, integer *ipiv, doublecomplex *b,
00023 integer *ldb, integer *info)
00024 {
00025
00026 integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2;
00027 doublecomplex z__1, z__2, z__3;
00028
00029
00030 void z_div(doublecomplex *, doublecomplex *, doublecomplex *), d_cnjg(
00031 doublecomplex *, doublecomplex *);
00032
00033
00034 integer j, k;
00035 doublereal s;
00036 doublecomplex ak, bk;
00037 integer kp;
00038 doublecomplex akm1, bkm1, akm1k;
00039 extern logical lsame_(char *, char *);
00040 doublecomplex denom;
00041 extern int zgemv_(char *, integer *, integer *,
00042 doublecomplex *, doublecomplex *, integer *, doublecomplex *,
00043 integer *, doublecomplex *, doublecomplex *, integer *);
00044 logical upper;
00045 extern int zgeru_(integer *, integer *, doublecomplex *,
00046 doublecomplex *, integer *, doublecomplex *, integer *,
00047 doublecomplex *, integer *), zswap_(integer *, doublecomplex *,
00048 integer *, doublecomplex *, integer *), xerbla_(char *, integer *), zdscal_(integer *, doublereal *, doublecomplex *,
00049 integer *), zlacgv_(integer *, doublecomplex *, integer *);
00050
00051
00052
00053
00054
00055
00056
00057
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 a_dim1 = *lda;
00122 a_offset = 1 + a_dim1;
00123 a -= a_offset;
00124 --ipiv;
00125 b_dim1 = *ldb;
00126 b_offset = 1 + b_dim1;
00127 b -= b_offset;
00128
00129
00130 *info = 0;
00131 upper = lsame_(uplo, "U");
00132 if (! upper && ! lsame_(uplo, "L")) {
00133 *info = -1;
00134 } else if (*n < 0) {
00135 *info = -2;
00136 } else if (*nrhs < 0) {
00137 *info = -3;
00138 } else if (*lda < max(1,*n)) {
00139 *info = -5;
00140 } else if (*ldb < max(1,*n)) {
00141 *info = -8;
00142 }
00143 if (*info != 0) {
00144 i__1 = -(*info);
00145 xerbla_("ZHETRS", &i__1);
00146 return 0;
00147 }
00148
00149
00150
00151 if (*n == 0 || *nrhs == 0) {
00152 return 0;
00153 }
00154
00155 if (upper) {
00156
00157
00158
00159
00160
00161
00162
00163
00164 k = *n;
00165 L10:
00166
00167
00168
00169 if (k < 1) {
00170 goto L30;
00171 }
00172
00173 if (ipiv[k] > 0) {
00174
00175
00176
00177
00178
00179 kp = ipiv[k];
00180 if (kp != k) {
00181 zswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb);
00182 }
00183
00184
00185
00186
00187 i__1 = k - 1;
00188 z__1.r = -1., z__1.i = -0.;
00189 zgeru_(&i__1, nrhs, &z__1, &a[k * a_dim1 + 1], &c__1, &b[k +
00190 b_dim1], ldb, &b[b_dim1 + 1], ldb);
00191
00192
00193
00194 i__1 = k + k * a_dim1;
00195 s = 1. / a[i__1].r;
00196 zdscal_(nrhs, &s, &b[k + b_dim1], ldb);
00197 --k;
00198 } else {
00199
00200
00201
00202
00203
00204 kp = -ipiv[k];
00205 if (kp != k - 1) {
00206 zswap_(nrhs, &b[k - 1 + b_dim1], ldb, &b[kp + b_dim1], ldb);
00207 }
00208
00209
00210
00211
00212 i__1 = k - 2;
00213 z__1.r = -1., z__1.i = -0.;
00214 zgeru_(&i__1, nrhs, &z__1, &a[k * a_dim1 + 1], &c__1, &b[k +
00215 b_dim1], ldb, &b[b_dim1 + 1], ldb);
00216 i__1 = k - 2;
00217 z__1.r = -1., z__1.i = -0.;
00218 zgeru_(&i__1, nrhs, &z__1, &a[(k - 1) * a_dim1 + 1], &c__1, &b[k
00219 - 1 + b_dim1], ldb, &b[b_dim1 + 1], ldb);
00220
00221
00222
00223 i__1 = k - 1 + k * a_dim1;
00224 akm1k.r = a[i__1].r, akm1k.i = a[i__1].i;
00225 z_div(&z__1, &a[k - 1 + (k - 1) * a_dim1], &akm1k);
00226 akm1.r = z__1.r, akm1.i = z__1.i;
00227 d_cnjg(&z__2, &akm1k);
00228 z_div(&z__1, &a[k + k * a_dim1], &z__2);
00229 ak.r = z__1.r, ak.i = z__1.i;
00230 z__2.r = akm1.r * ak.r - akm1.i * ak.i, z__2.i = akm1.r * ak.i +
00231 akm1.i * ak.r;
00232 z__1.r = z__2.r - 1., z__1.i = z__2.i - 0.;
00233 denom.r = z__1.r, denom.i = z__1.i;
00234 i__1 = *nrhs;
00235 for (j = 1; j <= i__1; ++j) {
00236 z_div(&z__1, &b[k - 1 + j * b_dim1], &akm1k);
00237 bkm1.r = z__1.r, bkm1.i = z__1.i;
00238 d_cnjg(&z__2, &akm1k);
00239 z_div(&z__1, &b[k + j * b_dim1], &z__2);
00240 bk.r = z__1.r, bk.i = z__1.i;
00241 i__2 = k - 1 + j * b_dim1;
00242 z__3.r = ak.r * bkm1.r - ak.i * bkm1.i, z__3.i = ak.r *
00243 bkm1.i + ak.i * bkm1.r;
00244 z__2.r = z__3.r - bk.r, z__2.i = z__3.i - bk.i;
00245 z_div(&z__1, &z__2, &denom);
00246 b[i__2].r = z__1.r, b[i__2].i = z__1.i;
00247 i__2 = k + j * b_dim1;
00248 z__3.r = akm1.r * bk.r - akm1.i * bk.i, z__3.i = akm1.r *
00249 bk.i + akm1.i * bk.r;
00250 z__2.r = z__3.r - bkm1.r, z__2.i = z__3.i - bkm1.i;
00251 z_div(&z__1, &z__2, &denom);
00252 b[i__2].r = z__1.r, b[i__2].i = z__1.i;
00253
00254 }
00255 k += -2;
00256 }
00257
00258 goto L10;
00259 L30:
00260
00261
00262
00263
00264
00265
00266 k = 1;
00267 L40:
00268
00269
00270
00271 if (k > *n) {
00272 goto L50;
00273 }
00274
00275 if (ipiv[k] > 0) {
00276
00277
00278
00279
00280
00281
00282 if (k > 1) {
00283 zlacgv_(nrhs, &b[k + b_dim1], ldb);
00284 i__1 = k - 1;
00285 z__1.r = -1., z__1.i = -0.;
00286 zgemv_("Conjugate transpose", &i__1, nrhs, &z__1, &b[b_offset]
00287 , ldb, &a[k * a_dim1 + 1], &c__1, &c_b1, &b[k +
00288 b_dim1], ldb);
00289 zlacgv_(nrhs, &b[k + b_dim1], ldb);
00290 }
00291
00292
00293
00294 kp = ipiv[k];
00295 if (kp != k) {
00296 zswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb);
00297 }
00298 ++k;
00299 } else {
00300
00301
00302
00303
00304
00305
00306 if (k > 1) {
00307 zlacgv_(nrhs, &b[k + b_dim1], ldb);
00308 i__1 = k - 1;
00309 z__1.r = -1., z__1.i = -0.;
00310 zgemv_("Conjugate transpose", &i__1, nrhs, &z__1, &b[b_offset]
00311 , ldb, &a[k * a_dim1 + 1], &c__1, &c_b1, &b[k +
00312 b_dim1], ldb);
00313 zlacgv_(nrhs, &b[k + b_dim1], ldb);
00314
00315 zlacgv_(nrhs, &b[k + 1 + b_dim1], ldb);
00316 i__1 = k - 1;
00317 z__1.r = -1., z__1.i = -0.;
00318 zgemv_("Conjugate transpose", &i__1, nrhs, &z__1, &b[b_offset]
00319 , ldb, &a[(k + 1) * a_dim1 + 1], &c__1, &c_b1, &b[k +
00320 1 + b_dim1], ldb);
00321 zlacgv_(nrhs, &b[k + 1 + b_dim1], ldb);
00322 }
00323
00324
00325
00326 kp = -ipiv[k];
00327 if (kp != k) {
00328 zswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb);
00329 }
00330 k += 2;
00331 }
00332
00333 goto L40;
00334 L50:
00335
00336 ;
00337 } else {
00338
00339
00340
00341
00342
00343
00344
00345
00346 k = 1;
00347 L60:
00348
00349
00350
00351 if (k > *n) {
00352 goto L80;
00353 }
00354
00355 if (ipiv[k] > 0) {
00356
00357
00358
00359
00360
00361 kp = ipiv[k];
00362 if (kp != k) {
00363 zswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb);
00364 }
00365
00366
00367
00368
00369 if (k < *n) {
00370 i__1 = *n - k;
00371 z__1.r = -1., z__1.i = -0.;
00372 zgeru_(&i__1, nrhs, &z__1, &a[k + 1 + k * a_dim1], &c__1, &b[
00373 k + b_dim1], ldb, &b[k + 1 + b_dim1], ldb);
00374 }
00375
00376
00377
00378 i__1 = k + k * a_dim1;
00379 s = 1. / a[i__1].r;
00380 zdscal_(nrhs, &s, &b[k + b_dim1], ldb);
00381 ++k;
00382 } else {
00383
00384
00385
00386
00387
00388 kp = -ipiv[k];
00389 if (kp != k + 1) {
00390 zswap_(nrhs, &b[k + 1 + b_dim1], ldb, &b[kp + b_dim1], ldb);
00391 }
00392
00393
00394
00395
00396 if (k < *n - 1) {
00397 i__1 = *n - k - 1;
00398 z__1.r = -1., z__1.i = -0.;
00399 zgeru_(&i__1, nrhs, &z__1, &a[k + 2 + k * a_dim1], &c__1, &b[
00400 k + b_dim1], ldb, &b[k + 2 + b_dim1], ldb);
00401 i__1 = *n - k - 1;
00402 z__1.r = -1., z__1.i = -0.;
00403 zgeru_(&i__1, nrhs, &z__1, &a[k + 2 + (k + 1) * a_dim1], &
00404 c__1, &b[k + 1 + b_dim1], ldb, &b[k + 2 + b_dim1],
00405 ldb);
00406 }
00407
00408
00409
00410 i__1 = k + 1 + k * a_dim1;
00411 akm1k.r = a[i__1].r, akm1k.i = a[i__1].i;
00412 d_cnjg(&z__2, &akm1k);
00413 z_div(&z__1, &a[k + k * a_dim1], &z__2);
00414 akm1.r = z__1.r, akm1.i = z__1.i;
00415 z_div(&z__1, &a[k + 1 + (k + 1) * a_dim1], &akm1k);
00416 ak.r = z__1.r, ak.i = z__1.i;
00417 z__2.r = akm1.r * ak.r - akm1.i * ak.i, z__2.i = akm1.r * ak.i +
00418 akm1.i * ak.r;
00419 z__1.r = z__2.r - 1., z__1.i = z__2.i - 0.;
00420 denom.r = z__1.r, denom.i = z__1.i;
00421 i__1 = *nrhs;
00422 for (j = 1; j <= i__1; ++j) {
00423 d_cnjg(&z__2, &akm1k);
00424 z_div(&z__1, &b[k + j * b_dim1], &z__2);
00425 bkm1.r = z__1.r, bkm1.i = z__1.i;
00426 z_div(&z__1, &b[k + 1 + j * b_dim1], &akm1k);
00427 bk.r = z__1.r, bk.i = z__1.i;
00428 i__2 = k + j * b_dim1;
00429 z__3.r = ak.r * bkm1.r - ak.i * bkm1.i, z__3.i = ak.r *
00430 bkm1.i + ak.i * bkm1.r;
00431 z__2.r = z__3.r - bk.r, z__2.i = z__3.i - bk.i;
00432 z_div(&z__1, &z__2, &denom);
00433 b[i__2].r = z__1.r, b[i__2].i = z__1.i;
00434 i__2 = k + 1 + j * b_dim1;
00435 z__3.r = akm1.r * bk.r - akm1.i * bk.i, z__3.i = akm1.r *
00436 bk.i + akm1.i * bk.r;
00437 z__2.r = z__3.r - bkm1.r, z__2.i = z__3.i - bkm1.i;
00438 z_div(&z__1, &z__2, &denom);
00439 b[i__2].r = z__1.r, b[i__2].i = z__1.i;
00440
00441 }
00442 k += 2;
00443 }
00444
00445 goto L60;
00446 L80:
00447
00448
00449
00450
00451
00452
00453 k = *n;
00454 L90:
00455
00456
00457
00458 if (k < 1) {
00459 goto L100;
00460 }
00461
00462 if (ipiv[k] > 0) {
00463
00464
00465
00466
00467
00468
00469 if (k < *n) {
00470 zlacgv_(nrhs, &b[k + b_dim1], ldb);
00471 i__1 = *n - k;
00472 z__1.r = -1., z__1.i = -0.;
00473 zgemv_("Conjugate transpose", &i__1, nrhs, &z__1, &b[k + 1 +
00474 b_dim1], ldb, &a[k + 1 + k * a_dim1], &c__1, &c_b1, &
00475 b[k + b_dim1], ldb);
00476 zlacgv_(nrhs, &b[k + b_dim1], ldb);
00477 }
00478
00479
00480
00481 kp = ipiv[k];
00482 if (kp != k) {
00483 zswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb);
00484 }
00485 --k;
00486 } else {
00487
00488
00489
00490
00491
00492
00493 if (k < *n) {
00494 zlacgv_(nrhs, &b[k + b_dim1], ldb);
00495 i__1 = *n - k;
00496 z__1.r = -1., z__1.i = -0.;
00497 zgemv_("Conjugate transpose", &i__1, nrhs, &z__1, &b[k + 1 +
00498 b_dim1], ldb, &a[k + 1 + k * a_dim1], &c__1, &c_b1, &
00499 b[k + b_dim1], ldb);
00500 zlacgv_(nrhs, &b[k + b_dim1], ldb);
00501
00502 zlacgv_(nrhs, &b[k - 1 + b_dim1], ldb);
00503 i__1 = *n - k;
00504 z__1.r = -1., z__1.i = -0.;
00505 zgemv_("Conjugate transpose", &i__1, nrhs, &z__1, &b[k + 1 +
00506 b_dim1], ldb, &a[k + 1 + (k - 1) * a_dim1], &c__1, &
00507 c_b1, &b[k - 1 + b_dim1], ldb);
00508 zlacgv_(nrhs, &b[k - 1 + b_dim1], ldb);
00509 }
00510
00511
00512
00513 kp = -ipiv[k];
00514 if (kp != k) {
00515 zswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb);
00516 }
00517 k += -2;
00518 }
00519
00520 goto L90;
00521 L100:
00522 ;
00523 }
00524
00525 return 0;
00526
00527
00528
00529 }