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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:27