c@427: /* dgetri.f -- translated by f2c (version 20061008). c@427: You must link the resulting object file with libf2c: c@427: on Microsoft Windows system, link with libf2c.lib; c@427: on Linux or Unix systems, link with .../path/to/libf2c.a -lm c@427: or, if you install libf2c.a in a standard place, with -lf2c -lm c@427: -- in that order, at the end of the command line, as in c@427: cc *.o -lf2c -lm c@427: Source for libf2c is in /netlib/f2c/libf2c.zip, e.g., c@427: c@427: http://www.netlib.org/f2c/libf2c.zip c@427: */ c@427: c@427: #include "f2c.h" c@427: #include "blaswrap.h" c@427: c@427: /* Table of constant values */ c@427: c@427: static integer c__1 = 1; c@427: static integer c_n1 = -1; c@427: static integer c__2 = 2; c@427: static doublereal c_b20 = -1.; c@427: static doublereal c_b22 = 1.; c@427: c@427: /* Subroutine */ int dgetri_(integer *n, doublereal *a, integer *lda, integer c@427: *ipiv, doublereal *work, integer *lwork, integer *info) c@427: { c@427: /* System generated locals */ c@427: integer a_dim1, a_offset, i__1, i__2, i__3; c@427: c@427: /* Local variables */ c@427: integer i__, j, jb, nb, jj, jp, nn, iws; c@427: extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *, c@427: integer *, doublereal *, doublereal *, integer *, doublereal *, c@427: integer *, doublereal *, doublereal *, integer *), c@427: dgemv_(char *, integer *, integer *, doublereal *, doublereal *, c@427: integer *, doublereal *, integer *, doublereal *, doublereal *, c@427: integer *); c@427: integer nbmin; c@427: extern /* Subroutine */ int dswap_(integer *, doublereal *, integer *, c@427: doublereal *, integer *), dtrsm_(char *, char *, char *, char *, c@427: integer *, integer *, doublereal *, doublereal *, integer *, c@427: doublereal *, integer *), xerbla_( c@427: char *, integer *); c@427: extern integer ilaenv_(integer *, char *, char *, integer *, integer *, c@427: integer *, integer *); c@427: integer ldwork; c@427: extern /* Subroutine */ int dtrtri_(char *, char *, integer *, doublereal c@427: *, integer *, integer *); c@427: integer lwkopt; c@427: logical lquery; c@427: c@427: c@427: /* -- LAPACK routine (version 3.2) -- */ c@427: /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ c@427: /* November 2006 */ c@427: c@427: /* .. Scalar Arguments .. */ c@427: /* .. */ c@427: /* .. Array Arguments .. */ c@427: /* .. */ c@427: c@427: /* Purpose */ c@427: /* ======= */ c@427: c@427: /* DGETRI computes the inverse of a matrix using the LU factorization */ c@427: /* computed by DGETRF. */ c@427: c@427: /* This method inverts U and then computes inv(A) by solving the system */ c@427: /* inv(A)*L = inv(U) for inv(A). */ c@427: c@427: /* Arguments */ c@427: /* ========= */ c@427: c@427: /* N (input) INTEGER */ c@427: /* The order of the matrix A. N >= 0. */ c@427: c@427: /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */ c@427: /* On entry, the factors L and U from the factorization */ c@427: /* A = P*L*U as computed by DGETRF. */ c@427: /* On exit, if INFO = 0, the inverse of the original matrix A. */ c@427: c@427: /* LDA (input) INTEGER */ c@427: /* The leading dimension of the array A. LDA >= max(1,N). */ c@427: c@427: /* IPIV (input) INTEGER array, dimension (N) */ c@427: /* The pivot indices from DGETRF; for 1<=i<=N, row i of the */ c@427: /* matrix was interchanged with row IPIV(i). */ c@427: c@427: /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */ c@427: /* On exit, if INFO=0, then WORK(1) returns the optimal LWORK. */ c@427: c@427: /* LWORK (input) INTEGER */ c@427: /* The dimension of the array WORK. LWORK >= max(1,N). */ c@427: /* For optimal performance LWORK >= N*NB, where NB is */ c@427: /* the optimal blocksize returned by ILAENV. */ c@427: c@427: /* If LWORK = -1, then a workspace query is assumed; the routine */ c@427: /* only calculates the optimal size of the WORK array, returns */ c@427: /* this value as the first entry of the WORK array, and no error */ c@427: /* message related to LWORK is issued by XERBLA. */ c@427: c@427: /* INFO (output) INTEGER */ c@427: /* = 0: successful exit */ c@427: /* < 0: if INFO = -i, the i-th argument had an illegal value */ c@427: /* > 0: if INFO = i, U(i,i) is exactly zero; the matrix is */ c@427: /* singular and its inverse could not be computed. */ c@427: c@427: /* ===================================================================== */ c@427: c@427: /* .. Parameters .. */ c@427: /* .. */ c@427: /* .. Local Scalars .. */ c@427: /* .. */ c@427: /* .. External Functions .. */ c@427: /* .. */ c@427: /* .. External Subroutines .. */ c@427: /* .. */ c@427: /* .. Intrinsic Functions .. */ c@427: /* .. */ c@427: /* .. Executable Statements .. */ c@427: c@427: /* Test the input parameters. */ c@427: c@427: /* Parameter adjustments */ c@427: a_dim1 = *lda; c@427: a_offset = 1 + a_dim1; c@427: a -= a_offset; c@427: --ipiv; c@427: --work; c@427: c@427: /* Function Body */ c@427: *info = 0; c@427: nb = ilaenv_(&c__1, "DGETRI", " ", n, &c_n1, &c_n1, &c_n1); c@427: lwkopt = *n * nb; c@427: work[1] = (doublereal) lwkopt; c@427: lquery = *lwork == -1; c@427: if (*n < 0) { c@427: *info = -1; c@427: } else if (*lda < max(1,*n)) { c@427: *info = -3; c@427: } else if (*lwork < max(1,*n) && ! lquery) { c@427: *info = -6; c@427: } c@427: if (*info != 0) { c@427: i__1 = -(*info); c@427: xerbla_("DGETRI", &i__1); c@427: return 0; c@427: } else if (lquery) { c@427: return 0; c@427: } c@427: c@427: /* Quick return if possible */ c@427: c@427: if (*n == 0) { c@427: return 0; c@427: } c@427: c@427: /* Form inv(U). If INFO > 0 from DTRTRI, then U is singular, */ c@427: /* and the inverse is not computed. */ c@427: c@427: dtrtri_("Upper", "Non-unit", n, &a[a_offset], lda, info); c@427: if (*info > 0) { c@427: return 0; c@427: } c@427: c@427: nbmin = 2; c@427: ldwork = *n; c@427: if (nb > 1 && nb < *n) { c@427: /* Computing MAX */ c@427: i__1 = ldwork * nb; c@427: iws = max(i__1,1); c@427: if (*lwork < iws) { c@427: nb = *lwork / ldwork; c@427: /* Computing MAX */ c@427: i__1 = 2, i__2 = ilaenv_(&c__2, "DGETRI", " ", n, &c_n1, &c_n1, & c@427: c_n1); c@427: nbmin = max(i__1,i__2); c@427: } c@427: } else { c@427: iws = *n; c@427: } c@427: c@427: /* Solve the equation inv(A)*L = inv(U) for inv(A). */ c@427: c@427: if (nb < nbmin || nb >= *n) { c@427: c@427: /* Use unblocked code. */ c@427: c@427: for (j = *n; j >= 1; --j) { c@427: c@427: /* Copy current column of L to WORK and replace with zeros. */ c@427: c@427: i__1 = *n; c@427: for (i__ = j + 1; i__ <= i__1; ++i__) { c@427: work[i__] = a[i__ + j * a_dim1]; c@427: a[i__ + j * a_dim1] = 0.; c@427: /* L10: */ c@427: } c@427: c@427: /* Compute current column of inv(A). */ c@427: c@427: if (j < *n) { c@427: i__1 = *n - j; c@427: dgemv_("No transpose", n, &i__1, &c_b20, &a[(j + 1) * a_dim1 c@427: + 1], lda, &work[j + 1], &c__1, &c_b22, &a[j * a_dim1 c@427: + 1], &c__1); c@427: } c@427: /* L20: */ c@427: } c@427: } else { c@427: c@427: /* Use blocked code. */ c@427: c@427: nn = (*n - 1) / nb * nb + 1; c@427: i__1 = -nb; c@427: for (j = nn; i__1 < 0 ? j >= 1 : j <= 1; j += i__1) { c@427: /* Computing MIN */ c@427: i__2 = nb, i__3 = *n - j + 1; c@427: jb = min(i__2,i__3); c@427: c@427: /* Copy current block column of L to WORK and replace with */ c@427: /* zeros. */ c@427: c@427: i__2 = j + jb - 1; c@427: for (jj = j; jj <= i__2; ++jj) { c@427: i__3 = *n; c@427: for (i__ = jj + 1; i__ <= i__3; ++i__) { c@427: work[i__ + (jj - j) * ldwork] = a[i__ + jj * a_dim1]; c@427: a[i__ + jj * a_dim1] = 0.; c@427: /* L30: */ c@427: } c@427: /* L40: */ c@427: } c@427: c@427: /* Compute current block column of inv(A). */ c@427: c@427: if (j + jb <= *n) { c@427: i__2 = *n - j - jb + 1; c@427: dgemm_("No transpose", "No transpose", n, &jb, &i__2, &c_b20, c@427: &a[(j + jb) * a_dim1 + 1], lda, &work[j + jb], & c@427: ldwork, &c_b22, &a[j * a_dim1 + 1], lda); c@427: } c@427: dtrsm_("Right", "Lower", "No transpose", "Unit", n, &jb, &c_b22, & c@427: work[j], &ldwork, &a[j * a_dim1 + 1], lda); c@427: /* L50: */ c@427: } c@427: } c@427: c@427: /* Apply column interchanges. */ c@427: c@427: for (j = *n - 1; j >= 1; --j) { c@427: jp = ipiv[j]; c@427: if (jp != j) { c@427: dswap_(n, &a[j * a_dim1 + 1], &c__1, &a[jp * a_dim1 + 1], &c__1); c@427: } c@427: /* L60: */ c@427: } c@427: c@427: work[1] = (doublereal) iws; c@427: return 0; c@427: c@427: /* End of DGETRI */ c@427: c@427: } /* dgetri_ */