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