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


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