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


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