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