3 /* Subroutine */ int dsytri_(char *uplo, integer *n, doublereal *a, integer *
4 lda, integer *ipiv, doublereal *work, integer *info)
6 /* -- LAPACK routine (version 3.0) --
7 Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
8 Courant Institute, Argonne National Lab, and Rice University
15 DSYTRI computes the inverse of a real symmetric indefinite matrix
16 A using the factorization A = U*D*U**T or A = L*D*L**T computed by
22 UPLO (input) CHARACTER*1
23 Specifies whether the details of the factorization are stored
24 as an upper or lower triangular matrix.
25 = 'U': Upper triangular, form is A = U*D*U**T;
26 = 'L': Lower triangular, form is A = L*D*L**T.
29 The order of the matrix A. N >= 0.
31 A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
32 On entry, the block diagonal matrix D and the multipliers
33 used to obtain the factor U or L as computed by DSYTRF.
35 On exit, if INFO = 0, the (symmetric) inverse of the original
36 matrix. If UPLO = 'U', the upper triangular part of the
37 inverse is formed and the part of A below the diagonal is not
38 referenced; if UPLO = 'L' the lower triangular part of the
39 inverse is formed and the part of A above the diagonal is
43 The leading dimension of the array A. LDA >= max(1,N).
45 IPIV (input) INTEGER array, dimension (N)
46 Details of the interchanges and the block structure of D
47 as determined by DSYTRF.
49 WORK (workspace) DOUBLE PRECISION array, dimension (N)
53 < 0: if INFO = -i, the i-th argument had an illegal value
54 > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its
55 inverse could not be computed.
57 =====================================================================
60 Test the input parameters.
62 Parameter adjustments */
63 /* Table of constant values */
64 static integer c__1 = 1;
65 static doublereal c_b11 = -1.;
66 static doublereal c_b13 = 0.;
68 /* System generated locals */
69 integer a_dim1, a_offset, i__1;
72 extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
74 static doublereal temp, akkp1, d__;
77 extern logical lsame_(char *, char *);
78 extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
79 doublereal *, integer *), dswap_(integer *, doublereal *, integer
80 *, doublereal *, integer *);
83 extern /* Subroutine */ int dsymv_(char *, integer *, doublereal *,
84 doublereal *, integer *, doublereal *, integer *, doublereal *,
85 doublereal *, integer *);
88 extern /* Subroutine */ int xerbla_(char *, integer *);
89 static doublereal akp1;
90 #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1]
94 a_offset = 1 + a_dim1 * 1;
101 upper = lsame_(uplo, "U");
102 if (! upper && ! lsame_(uplo, "L")) {
106 } else if (*lda < max(1,*n)) {
111 xerbla_("DSYTRI", &i__1);
115 /* Quick return if possible */
121 /* Check that the diagonal matrix D is nonsingular. */
125 /* Upper triangular storage: examine D from bottom to top */
127 for (*info = *n; *info >= 1; --(*info)) {
128 if (ipiv[*info] > 0 && a_ref(*info, *info) == 0.) {
135 /* Lower triangular storage: examine D from top to bottom. */
138 for (*info = 1; *info <= i__1; ++(*info)) {
139 if (ipiv[*info] > 0 && a_ref(*info, *info) == 0.) {
149 /* Compute inv(A) from the factorization A = U*D*U'.
151 K is the main loop index, increasing from 1 to N in steps of
152 1 or 2, depending on the size of the diagonal blocks. */
157 /* If K > N, exit from loop. */
165 /* 1 x 1 diagonal block
167 Invert the diagonal block. */
169 a_ref(k, k) = 1. / a_ref(k, k);
171 /* Compute column K of the inverse. */
175 dcopy_(&i__1, &a_ref(1, k), &c__1, &work[1], &c__1);
177 dsymv_(uplo, &i__1, &c_b11, &a[a_offset], lda, &work[1], &
178 c__1, &c_b13, &a_ref(1, k), &c__1);
180 a_ref(k, k) = a_ref(k, k) - ddot_(&i__1, &work[1], &c__1, &
186 /* 2 x 2 diagonal block
188 Invert the diagonal block. */
190 t = (d__1 = a_ref(k, k + 1), abs(d__1));
191 ak = a_ref(k, k) / t;
192 akp1 = a_ref(k + 1, k + 1) / t;
193 akkp1 = a_ref(k, k + 1) / t;
194 d__ = t * (ak * akp1 - 1.);
195 a_ref(k, k) = akp1 / d__;
196 a_ref(k + 1, k + 1) = ak / d__;
197 a_ref(k, k + 1) = -akkp1 / d__;
199 /* Compute columns K and K+1 of the inverse. */
203 dcopy_(&i__1, &a_ref(1, k), &c__1, &work[1], &c__1);
205 dsymv_(uplo, &i__1, &c_b11, &a[a_offset], lda, &work[1], &
206 c__1, &c_b13, &a_ref(1, k), &c__1);
208 a_ref(k, k) = a_ref(k, k) - ddot_(&i__1, &work[1], &c__1, &
211 a_ref(k, k + 1) = a_ref(k, k + 1) - ddot_(&i__1, &a_ref(1, k),
212 &c__1, &a_ref(1, k + 1), &c__1);
214 dcopy_(&i__1, &a_ref(1, k + 1), &c__1, &work[1], &c__1);
216 dsymv_(uplo, &i__1, &c_b11, &a[a_offset], lda, &work[1], &
217 c__1, &c_b13, &a_ref(1, k + 1), &c__1);
219 a_ref(k + 1, k + 1) = a_ref(k + 1, k + 1) - ddot_(&i__1, &
220 work[1], &c__1, &a_ref(1, k + 1), &c__1);
225 kp = (i__1 = ipiv[k], abs(i__1));
228 /* Interchange rows and columns K and KP in the leading
229 submatrix A(1:k+1,1:k+1) */
232 dswap_(&i__1, &a_ref(1, k), &c__1, &a_ref(1, kp), &c__1);
234 dswap_(&i__1, &a_ref(kp + 1, k), &c__1, &a_ref(kp, kp + 1), lda);
236 a_ref(k, k) = a_ref(kp, kp);
237 a_ref(kp, kp) = temp;
239 temp = a_ref(k, k + 1);
240 a_ref(k, k + 1) = a_ref(kp, k + 1);
241 a_ref(kp, k + 1) = temp;
252 /* Compute inv(A) from the factorization A = L*D*L'.
254 K is the main loop index, increasing from 1 to N in steps of
255 1 or 2, depending on the size of the diagonal blocks. */
260 /* If K < 1, exit from loop. */
268 /* 1 x 1 diagonal block
270 Invert the diagonal block. */
272 a_ref(k, k) = 1. / a_ref(k, k);
274 /* Compute column K of the inverse. */
278 dcopy_(&i__1, &a_ref(k + 1, k), &c__1, &work[1], &c__1);
280 dsymv_(uplo, &i__1, &c_b11, &a_ref(k + 1, k + 1), lda, &work[
281 1], &c__1, &c_b13, &a_ref(k + 1, k), &c__1)
284 a_ref(k, k) = a_ref(k, k) - ddot_(&i__1, &work[1], &c__1, &
285 a_ref(k + 1, k), &c__1);
290 /* 2 x 2 diagonal block
292 Invert the diagonal block. */
294 t = (d__1 = a_ref(k, k - 1), abs(d__1));
295 ak = a_ref(k - 1, k - 1) / t;
296 akp1 = a_ref(k, k) / t;
297 akkp1 = a_ref(k, k - 1) / t;
298 d__ = t * (ak * akp1 - 1.);
299 a_ref(k - 1, k - 1) = akp1 / d__;
300 a_ref(k, k) = ak / d__;
301 a_ref(k, k - 1) = -akkp1 / d__;
303 /* Compute columns K-1 and K of the inverse. */
307 dcopy_(&i__1, &a_ref(k + 1, k), &c__1, &work[1], &c__1);
309 dsymv_(uplo, &i__1, &c_b11, &a_ref(k + 1, k + 1), lda, &work[
310 1], &c__1, &c_b13, &a_ref(k + 1, k), &c__1)
313 a_ref(k, k) = a_ref(k, k) - ddot_(&i__1, &work[1], &c__1, &
314 a_ref(k + 1, k), &c__1);
316 a_ref(k, k - 1) = a_ref(k, k - 1) - ddot_(&i__1, &a_ref(k + 1,
317 k), &c__1, &a_ref(k + 1, k - 1), &c__1);
319 dcopy_(&i__1, &a_ref(k + 1, k - 1), &c__1, &work[1], &c__1);
321 dsymv_(uplo, &i__1, &c_b11, &a_ref(k + 1, k + 1), lda, &work[
322 1], &c__1, &c_b13, &a_ref(k + 1, k - 1), &c__1);
324 a_ref(k - 1, k - 1) = a_ref(k - 1, k - 1) - ddot_(&i__1, &
325 work[1], &c__1, &a_ref(k + 1, k - 1), &c__1);
330 kp = (i__1 = ipiv[k], abs(i__1));
333 /* Interchange rows and columns K and KP in the trailing
334 submatrix A(k-1:n,k-1:n) */
338 dswap_(&i__1, &a_ref(kp + 1, k), &c__1, &a_ref(kp + 1, kp), &
342 dswap_(&i__1, &a_ref(k + 1, k), &c__1, &a_ref(kp, k + 1), lda);
344 a_ref(k, k) = a_ref(kp, kp);
345 a_ref(kp, kp) = temp;
347 temp = a_ref(k, k - 1);
348 a_ref(k, k - 1) = a_ref(kp, k - 1);
349 a_ref(kp, k - 1) = temp;