zhetri.c
Go to the documentation of this file.
00001 /* zhetri.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static doublecomplex c_b2 = {0.,0.};
00019 static integer c__1 = 1;
00020 
00021 /* Subroutine */ int zhetri_(char *uplo, integer *n, doublecomplex *a, 
00022         integer *lda, integer *ipiv, doublecomplex *work, integer *info)
00023 {
00024     /* System generated locals */
00025     integer a_dim1, a_offset, i__1, i__2, i__3;
00026     doublereal d__1;
00027     doublecomplex z__1, z__2;
00028 
00029     /* Builtin functions */
00030     double z_abs(doublecomplex *);
00031     void d_cnjg(doublecomplex *, doublecomplex *);
00032 
00033     /* Local variables */
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 /* Double Complex */ VOID zdotc_(doublecomplex *, integer *, 
00042             doublecomplex *, integer *, doublecomplex *, integer *);
00043     integer kstep;
00044     extern /* Subroutine */ int zhemv_(char *, integer *, doublecomplex *, 
00045             doublecomplex *, integer *, doublecomplex *, integer *, 
00046             doublecomplex *, doublecomplex *, integer *);
00047     logical upper;
00048     extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *, 
00049             doublecomplex *, integer *), zswap_(integer *, doublecomplex *, 
00050             integer *, doublecomplex *, integer *), xerbla_(char *, integer *);
00051 
00052 
00053 /*  -- LAPACK routine (version 3.2) -- */
00054 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00055 /*     November 2006 */
00056 
00057 /*     .. Scalar Arguments .. */
00058 /*     .. */
00059 /*     .. Array Arguments .. */
00060 /*     .. */
00061 
00062 /*  Purpose */
00063 /*  ======= */
00064 
00065 /*  ZHETRI computes the inverse of a complex Hermitian indefinite matrix */
00066 /*  A using the factorization A = U*D*U**H or A = L*D*L**H computed by */
00067 /*  ZHETRF. */
00068 
00069 /*  Arguments */
00070 /*  ========= */
00071 
00072 /*  UPLO    (input) CHARACTER*1 */
00073 /*          Specifies whether the details of the factorization are stored */
00074 /*          as an upper or lower triangular matrix. */
00075 /*          = 'U':  Upper triangular, form is A = U*D*U**H; */
00076 /*          = 'L':  Lower triangular, form is A = L*D*L**H. */
00077 
00078 /*  N       (input) INTEGER */
00079 /*          The order of the matrix A.  N >= 0. */
00080 
00081 /*  A       (input/output) COMPLEX*16 array, dimension (LDA,N) */
00082 /*          On entry, the block diagonal matrix D and the multipliers */
00083 /*          used to obtain the factor U or L as computed by ZHETRF. */
00084 
00085 /*          On exit, if INFO = 0, the (Hermitian) inverse of the original */
00086 /*          matrix.  If UPLO = 'U', the upper triangular part of the */
00087 /*          inverse is formed and the part of A below the diagonal is not */
00088 /*          referenced; if UPLO = 'L' the lower triangular part of the */
00089 /*          inverse is formed and the part of A above the diagonal is */
00090 /*          not referenced. */
00091 
00092 /*  LDA     (input) INTEGER */
00093 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00094 
00095 /*  IPIV    (input) INTEGER array, dimension (N) */
00096 /*          Details of the interchanges and the block structure of D */
00097 /*          as determined by ZHETRF. */
00098 
00099 /*  WORK    (workspace) COMPLEX*16 array, dimension (N) */
00100 
00101 /*  INFO    (output) INTEGER */
00102 /*          = 0: successful exit */
00103 /*          < 0: if INFO = -i, the i-th argument had an illegal value */
00104 /*          > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its */
00105 /*               inverse could not be computed. */
00106 
00107 /*  ===================================================================== */
00108 
00109 /*     .. Parameters .. */
00110 /*     .. */
00111 /*     .. Local Scalars .. */
00112 /*     .. */
00113 /*     .. External Functions .. */
00114 /*     .. */
00115 /*     .. External Subroutines .. */
00116 /*     .. */
00117 /*     .. Intrinsic Functions .. */
00118 /*     .. */
00119 /*     .. Executable Statements .. */
00120 
00121 /*     Test the input parameters. */
00122 
00123     /* Parameter adjustments */
00124     a_dim1 = *lda;
00125     a_offset = 1 + a_dim1;
00126     a -= a_offset;
00127     --ipiv;
00128     --work;
00129 
00130     /* Function Body */
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 /*     Quick return if possible */
00147 
00148     if (*n == 0) {
00149         return 0;
00150     }
00151 
00152 /*     Check that the diagonal matrix D is nonsingular. */
00153 
00154     if (upper) {
00155 
00156 /*        Upper triangular storage: examine D from bottom to top */
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 /* L10: */
00164         }
00165     } else {
00166 
00167 /*        Lower triangular storage: examine D from top to bottom. */
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 /* L20: */
00176         }
00177     }
00178     *info = 0;
00179 
00180     if (upper) {
00181 
00182 /*        Compute inv(A) from the factorization A = U*D*U'. */
00183 
00184 /*        K is the main loop index, increasing from 1 to N in steps of */
00185 /*        1 or 2, depending on the size of the diagonal blocks. */
00186 
00187         k = 1;
00188 L30:
00189 
00190 /*        If K > N, exit from loop. */
00191 
00192         if (k > *n) {
00193             goto L50;
00194         }
00195 
00196         if (ipiv[k] > 0) {
00197 
00198 /*           1 x 1 diagonal block */
00199 
00200 /*           Invert the diagonal block. */
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 /*           Compute column K of the inverse. */
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 /*           2 x 2 diagonal block */
00229 
00230 /*           Invert the diagonal block. */
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 /*           Compute columns K and K+1 of the inverse. */
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 /*           Interchange rows and columns K and KP in the leading */
00299 /*           submatrix A(1:k+1,1:k+1) */
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 /* L40: */
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 /*        Compute inv(A) from the factorization A = L*D*L'. */
00344 
00345 /*        K is the main loop index, increasing from 1 to N in steps of */
00346 /*        1 or 2, depending on the size of the diagonal blocks. */
00347 
00348         k = *n;
00349 L60:
00350 
00351 /*        If K < 1, exit from loop. */
00352 
00353         if (k < 1) {
00354             goto L80;
00355         }
00356 
00357         if (ipiv[k] > 0) {
00358 
00359 /*           1 x 1 diagonal block */
00360 
00361 /*           Invert the diagonal block. */
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 /*           Compute column K of the inverse. */
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 /*           2 x 2 diagonal block */
00390 
00391 /*           Invert the diagonal block. */
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 /*           Compute columns K-1 and K of the inverse. */
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 /*           Interchange rows and columns K and KP in the trailing */
00461 /*           submatrix A(k-1:n,k-1:n) */
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 /* L70: */
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 /*     End of ZHETRI */
00509 
00510 } /* zhetri_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:38