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