zgetri.c
Go to the documentation of this file.
00001 /* zgetri.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 = {1.,0.};
00019 static integer c__1 = 1;
00020 static integer c_n1 = -1;
00021 static integer c__2 = 2;
00022 
00023 /* Subroutine */ int zgetri_(integer *n, doublecomplex *a, integer *lda, 
00024         integer *ipiv, doublecomplex *work, integer *lwork, integer *info)
00025 {
00026     /* System generated locals */
00027     integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
00028     doublecomplex z__1;
00029 
00030     /* Local variables */
00031     integer i__, j, jb, nb, jj, jp, nn, iws, nbmin;
00032     extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *, 
00033             integer *, doublecomplex *, doublecomplex *, integer *, 
00034             doublecomplex *, integer *, doublecomplex *, doublecomplex *, 
00035             integer *), zgemv_(char *, integer *, integer *, 
00036             doublecomplex *, doublecomplex *, integer *, doublecomplex *, 
00037             integer *, doublecomplex *, doublecomplex *, integer *), 
00038             zswap_(integer *, doublecomplex *, integer *, doublecomplex *, 
00039             integer *), ztrsm_(char *, char *, char *, char *, integer *, 
00040             integer *, doublecomplex *, doublecomplex *, integer *, 
00041             doublecomplex *, integer *), 
00042             xerbla_(char *, integer *);
00043     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00044             integer *, integer *);
00045     integer ldwork, lwkopt;
00046     logical lquery;
00047     extern /* Subroutine */ int ztrtri_(char *, char *, integer *, 
00048             doublecomplex *, integer *, integer *);
00049 
00050 
00051 /*  -- LAPACK routine (version 3.2) -- */
00052 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00053 /*     November 2006 */
00054 
00055 /*     .. Scalar Arguments .. */
00056 /*     .. */
00057 /*     .. Array Arguments .. */
00058 /*     .. */
00059 
00060 /*  Purpose */
00061 /*  ======= */
00062 
00063 /*  ZGETRI computes the inverse of a matrix using the LU factorization */
00064 /*  computed by ZGETRF. */
00065 
00066 /*  This method inverts U and then computes inv(A) by solving the system */
00067 /*  inv(A)*L = inv(U) for inv(A). */
00068 
00069 /*  Arguments */
00070 /*  ========= */
00071 
00072 /*  N       (input) INTEGER */
00073 /*          The order of the matrix A.  N >= 0. */
00074 
00075 /*  A       (input/output) COMPLEX*16 array, dimension (LDA,N) */
00076 /*          On entry, the factors L and U from the factorization */
00077 /*          A = P*L*U as computed by ZGETRF. */
00078 /*          On exit, if INFO = 0, the inverse of the original matrix A. */
00079 
00080 /*  LDA     (input) INTEGER */
00081 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00082 
00083 /*  IPIV    (input) INTEGER array, dimension (N) */
00084 /*          The pivot indices from ZGETRF; for 1<=i<=N, row i of the */
00085 /*          matrix was interchanged with row IPIV(i). */
00086 
00087 /*  WORK    (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */
00088 /*          On exit, if INFO=0, then WORK(1) returns the optimal LWORK. */
00089 
00090 /*  LWORK   (input) INTEGER */
00091 /*          The dimension of the array WORK.  LWORK >= max(1,N). */
00092 /*          For optimal performance LWORK >= N*NB, where NB is */
00093 /*          the optimal blocksize returned by ILAENV. */
00094 
00095 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00096 /*          only calculates the optimal size of the WORK array, returns */
00097 /*          this value as the first entry of the WORK array, and no error */
00098 /*          message related to LWORK is issued by XERBLA. */
00099 
00100 /*  INFO    (output) INTEGER */
00101 /*          = 0:  successful exit */
00102 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00103 /*          > 0:  if INFO = i, U(i,i) is exactly zero; the matrix is */
00104 /*                singular and its inverse could not be computed. */
00105 
00106 /*  ===================================================================== */
00107 
00108 /*     .. Parameters .. */
00109 /*     .. */
00110 /*     .. Local Scalars .. */
00111 /*     .. */
00112 /*     .. External Functions .. */
00113 /*     .. */
00114 /*     .. External Subroutines .. */
00115 /*     .. */
00116 /*     .. Intrinsic Functions .. */
00117 /*     .. */
00118 /*     .. Executable Statements .. */
00119 
00120 /*     Test the input parameters. */
00121 
00122     /* Parameter adjustments */
00123     a_dim1 = *lda;
00124     a_offset = 1 + a_dim1;
00125     a -= a_offset;
00126     --ipiv;
00127     --work;
00128 
00129     /* Function Body */
00130     *info = 0;
00131     nb = ilaenv_(&c__1, "ZGETRI", " ", n, &c_n1, &c_n1, &c_n1);
00132     lwkopt = *n * nb;
00133     work[1].r = (doublereal) lwkopt, work[1].i = 0.;
00134     lquery = *lwork == -1;
00135     if (*n < 0) {
00136         *info = -1;
00137     } else if (*lda < max(1,*n)) {
00138         *info = -3;
00139     } else if (*lwork < max(1,*n) && ! lquery) {
00140         *info = -6;
00141     }
00142     if (*info != 0) {
00143         i__1 = -(*info);
00144         xerbla_("ZGETRI", &i__1);
00145         return 0;
00146     } else if (lquery) {
00147         return 0;
00148     }
00149 
00150 /*     Quick return if possible */
00151 
00152     if (*n == 0) {
00153         return 0;
00154     }
00155 
00156 /*     Form inv(U).  If INFO > 0 from ZTRTRI, then U is singular, */
00157 /*     and the inverse is not computed. */
00158 
00159     ztrtri_("Upper", "Non-unit", n, &a[a_offset], lda, info);
00160     if (*info > 0) {
00161         return 0;
00162     }
00163 
00164     nbmin = 2;
00165     ldwork = *n;
00166     if (nb > 1 && nb < *n) {
00167 /* Computing MAX */
00168         i__1 = ldwork * nb;
00169         iws = max(i__1,1);
00170         if (*lwork < iws) {
00171             nb = *lwork / ldwork;
00172 /* Computing MAX */
00173             i__1 = 2, i__2 = ilaenv_(&c__2, "ZGETRI", " ", n, &c_n1, &c_n1, &
00174                     c_n1);
00175             nbmin = max(i__1,i__2);
00176         }
00177     } else {
00178         iws = *n;
00179     }
00180 
00181 /*     Solve the equation inv(A)*L = inv(U) for inv(A). */
00182 
00183     if (nb < nbmin || nb >= *n) {
00184 
00185 /*        Use unblocked code. */
00186 
00187         for (j = *n; j >= 1; --j) {
00188 
00189 /*           Copy current column of L to WORK and replace with zeros. */
00190 
00191             i__1 = *n;
00192             for (i__ = j + 1; i__ <= i__1; ++i__) {
00193                 i__2 = i__;
00194                 i__3 = i__ + j * a_dim1;
00195                 work[i__2].r = a[i__3].r, work[i__2].i = a[i__3].i;
00196                 i__2 = i__ + j * a_dim1;
00197                 a[i__2].r = 0., a[i__2].i = 0.;
00198 /* L10: */
00199             }
00200 
00201 /*           Compute current column of inv(A). */
00202 
00203             if (j < *n) {
00204                 i__1 = *n - j;
00205                 z__1.r = -1., z__1.i = -0.;
00206                 zgemv_("No transpose", n, &i__1, &z__1, &a[(j + 1) * a_dim1 + 
00207                         1], lda, &work[j + 1], &c__1, &c_b2, &a[j * a_dim1 + 
00208                         1], &c__1);
00209             }
00210 /* L20: */
00211         }
00212     } else {
00213 
00214 /*        Use blocked code. */
00215 
00216         nn = (*n - 1) / nb * nb + 1;
00217         i__1 = -nb;
00218         for (j = nn; i__1 < 0 ? j >= 1 : j <= 1; j += i__1) {
00219 /* Computing MIN */
00220             i__2 = nb, i__3 = *n - j + 1;
00221             jb = min(i__2,i__3);
00222 
00223 /*           Copy current block column of L to WORK and replace with */
00224 /*           zeros. */
00225 
00226             i__2 = j + jb - 1;
00227             for (jj = j; jj <= i__2; ++jj) {
00228                 i__3 = *n;
00229                 for (i__ = jj + 1; i__ <= i__3; ++i__) {
00230                     i__4 = i__ + (jj - j) * ldwork;
00231                     i__5 = i__ + jj * a_dim1;
00232                     work[i__4].r = a[i__5].r, work[i__4].i = a[i__5].i;
00233                     i__4 = i__ + jj * a_dim1;
00234                     a[i__4].r = 0., a[i__4].i = 0.;
00235 /* L30: */
00236                 }
00237 /* L40: */
00238             }
00239 
00240 /*           Compute current block column of inv(A). */
00241 
00242             if (j + jb <= *n) {
00243                 i__2 = *n - j - jb + 1;
00244                 z__1.r = -1., z__1.i = -0.;
00245                 zgemm_("No transpose", "No transpose", n, &jb, &i__2, &z__1, &
00246                         a[(j + jb) * a_dim1 + 1], lda, &work[j + jb], &ldwork, 
00247                          &c_b2, &a[j * a_dim1 + 1], lda);
00248             }
00249             ztrsm_("Right", "Lower", "No transpose", "Unit", n, &jb, &c_b2, &
00250                     work[j], &ldwork, &a[j * a_dim1 + 1], lda);
00251 /* L50: */
00252         }
00253     }
00254 
00255 /*     Apply column interchanges. */
00256 
00257     for (j = *n - 1; j >= 1; --j) {
00258         jp = ipiv[j];
00259         if (jp != j) {
00260             zswap_(n, &a[j * a_dim1 + 1], &c__1, &a[jp * a_dim1 + 1], &c__1);
00261         }
00262 /* L60: */
00263     }
00264 
00265     work[1].r = (doublereal) iws, work[1].i = 0.;
00266     return 0;
00267 
00268 /*     End of ZGETRI */
00269 
00270 } /* zgetri_ */


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