3 /* Subroutine */ int dlasyf_(char *uplo, integer *n, integer *nb, integer *kb,
4 doublereal *a, integer *lda, integer *ipiv, doublereal *w, integer *
7 /* -- LAPACK routine (version 3.1) --
8 Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
15 DLASYF computes a partial factorization of a real symmetric matrix A
16 using the Bunch-Kaufman diagonal pivoting method. The partial
17 factorization has the form:
19 A = ( I U12 ) ( A11 0 ) ( I 0 ) if UPLO = 'U', or:
20 ( 0 U22 ) ( 0 D ) ( U12' U22' )
22 A = ( L11 0 ) ( D 0 ) ( L11' L21' ) if UPLO = 'L'
23 ( L21 I ) ( 0 A22 ) ( 0 I )
25 where the order of D is at most NB. The actual order is returned in
26 the argument KB, and is either NB or NB-1, or N if N <= NB.
28 DLASYF is an auxiliary routine called by DSYTRF. It uses blocked code
29 (calling Level 3 BLAS) to update the submatrix A11 (if UPLO = 'U') or
35 UPLO (input) CHARACTER*1
36 Specifies whether the upper or lower triangular part of the
37 symmetric matrix A is stored:
38 = 'U': Upper triangular
39 = 'L': Lower triangular
42 The order of the matrix A. N >= 0.
45 The maximum number of columns of the matrix A that should be
46 factored. NB should be at least 2 to allow for 2-by-2 pivot
50 The number of columns of A that were actually factored.
51 KB is either NB-1 or NB, or N if N <= NB.
53 A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
54 On entry, the symmetric matrix A. If UPLO = 'U', the leading
55 n-by-n upper triangular part of A contains the upper
56 triangular part of the matrix A, and the strictly lower
57 triangular part of A is not referenced. If UPLO = 'L', the
58 leading n-by-n lower triangular part of A contains the lower
59 triangular part of the matrix A, and the strictly upper
60 triangular part of A is not referenced.
61 On exit, A contains details of the partial factorization.
64 The leading dimension of the array A. LDA >= max(1,N).
66 IPIV (output) INTEGER array, dimension (N)
67 Details of the interchanges and the block structure of D.
68 If UPLO = 'U', only the last KB elements of IPIV are set;
69 if UPLO = 'L', only the first KB elements are set.
71 If IPIV(k) > 0, then rows and columns k and IPIV(k) were
72 interchanged and D(k,k) is a 1-by-1 diagonal block.
73 If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and
74 columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k)
75 is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) =
76 IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were
77 interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block.
79 W (workspace) DOUBLE PRECISION array, dimension (LDW,NB)
82 The leading dimension of the array W. LDW >= max(1,N).
86 > 0: if INFO = k, D(k,k) is exactly zero. The factorization
87 has been completed, but the block diagonal matrix D is
90 =====================================================================
93 Parameter adjustments */
94 /* Table of constant values */
95 static integer c__1 = 1;
96 static doublereal c_b8 = -1.;
97 static doublereal c_b9 = 1.;
99 /* System generated locals */
100 integer a_dim1, a_offset, w_dim1, w_offset, i__1, i__2, i__3, i__4, i__5;
101 doublereal d__1, d__2, d__3;
102 /* Builtin functions */
103 double sqrt(doublereal);
104 /* Local variables */
106 static doublereal t, r1, d11, d21, d22;
107 static integer jb, jj, kk, jp, kp, kw, kkw, imax, jmax;
108 static doublereal alpha;
109 extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
110 integer *), dgemm_(char *, char *, integer *, integer *, integer *
111 , doublereal *, doublereal *, integer *, doublereal *, integer *,
112 doublereal *, doublereal *, integer *);
113 extern logical lsame_(char *, char *);
114 extern /* Subroutine */ int dgemv_(char *, integer *, integer *,
115 doublereal *, doublereal *, integer *, doublereal *, integer *,
116 doublereal *, doublereal *, integer *), dcopy_(integer *,
117 doublereal *, integer *, doublereal *, integer *), dswap_(integer
118 *, doublereal *, integer *, doublereal *, integer *);
119 static integer kstep;
120 static doublereal absakk;
121 extern integer idamax_(integer *, doublereal *, integer *);
122 static doublereal colmax, rowmax;
126 a_offset = 1 + a_dim1;
130 w_offset = 1 + w_dim1;
136 /* Initialize ALPHA for use in choosing pivot block size. */
138 alpha = (sqrt(17.) + 1.) / 8.;
140 if (lsame_(uplo, "U")) {
142 /* Factorize the trailing columns of A using the upper triangle
143 of A and working backwards, and compute the matrix W = U12*D
144 for use in updating A11
146 K is the main loop index, decreasing from N in steps of 1 or 2
148 KW is the column of W which corresponds to column K of A */
156 if (k <= *n - *nb + 1 && *nb < *n || k < 1) {
160 /* Copy column K of A to column KW of W and update it */
162 dcopy_(&k, &a[k * a_dim1 + 1], &c__1, &w[kw * w_dim1 + 1], &c__1);
165 dgemv_("No transpose", &k, &i__1, &c_b8, &a[(k + 1) * a_dim1 + 1],
166 lda, &w[k + (kw + 1) * w_dim1], ldw, &c_b9, &w[kw *
172 /* Determine rows and columns to be interchanged and whether
173 a 1-by-1 or 2-by-2 pivot block will be used */
175 absakk = (d__1 = w[k + kw * w_dim1], abs(d__1));
177 /* IMAX is the row-index of the largest off-diagonal element in
178 column K, and COLMAX is its absolute value */
182 imax = idamax_(&i__1, &w[kw * w_dim1 + 1], &c__1);
183 colmax = (d__1 = w[imax + kw * w_dim1], abs(d__1));
188 if (max(absakk,colmax) == 0.) {
190 /* Column K is zero: set INFO and continue */
197 if (absakk >= alpha * colmax) {
199 /* no interchange, use 1-by-1 pivot block */
204 /* Copy column IMAX to column KW-1 of W and update it */
206 dcopy_(&imax, &a[imax * a_dim1 + 1], &c__1, &w[(kw - 1) *
209 dcopy_(&i__1, &a[imax + (imax + 1) * a_dim1], lda, &w[imax +
210 1 + (kw - 1) * w_dim1], &c__1);
213 dgemv_("No transpose", &k, &i__1, &c_b8, &a[(k + 1) *
214 a_dim1 + 1], lda, &w[imax + (kw + 1) * w_dim1],
215 ldw, &c_b9, &w[(kw - 1) * w_dim1 + 1], &c__1);
218 /* JMAX is the column-index of the largest off-diagonal
219 element in row IMAX, and ROWMAX is its absolute value */
222 jmax = imax + idamax_(&i__1, &w[imax + 1 + (kw - 1) * w_dim1],
224 rowmax = (d__1 = w[jmax + (kw - 1) * w_dim1], abs(d__1));
227 jmax = idamax_(&i__1, &w[(kw - 1) * w_dim1 + 1], &c__1);
229 d__2 = rowmax, d__3 = (d__1 = w[jmax + (kw - 1) * w_dim1],
231 rowmax = max(d__2,d__3);
234 if (absakk >= alpha * colmax * (colmax / rowmax)) {
236 /* no interchange, use 1-by-1 pivot block */
239 } else if ((d__1 = w[imax + (kw - 1) * w_dim1], abs(d__1)) >=
242 /* interchange rows and columns K and IMAX, use 1-by-1
247 /* copy column KW-1 of W to column KW */
249 dcopy_(&k, &w[(kw - 1) * w_dim1 + 1], &c__1, &w[kw *
253 /* interchange rows and columns K-1 and IMAX, use 2-by-2
264 /* Updated column KP is already stored in column KKW of W */
268 /* Copy non-updated column KK to column KP */
270 a[kp + k * a_dim1] = a[kk + k * a_dim1];
272 dcopy_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + (kp +
274 dcopy_(&kp, &a[kk * a_dim1 + 1], &c__1, &a[kp * a_dim1 + 1], &
277 /* Interchange rows KK and KP in last KK columns of A and W */
280 dswap_(&i__1, &a[kk + kk * a_dim1], lda, &a[kp + kk * a_dim1],
283 dswap_(&i__1, &w[kk + kkw * w_dim1], ldw, &w[kp + kkw *
289 /* 1-by-1 pivot block D(k): column KW of W now holds
293 where U(k) is the k-th column of U
295 Store U(k) in column k of A */
297 dcopy_(&k, &w[kw * w_dim1 + 1], &c__1, &a[k * a_dim1 + 1], &
299 r1 = 1. / a[k + k * a_dim1];
301 dscal_(&i__1, &r1, &a[k * a_dim1 + 1], &c__1);
304 /* 2-by-2 pivot block D(k): columns KW and KW-1 of W now
307 ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
309 where U(k) and U(k-1) are the k-th and (k-1)-th columns
314 /* Store U(k) and U(k-1) in columns k and k-1 of A */
316 d21 = w[k - 1 + kw * w_dim1];
317 d11 = w[k + kw * w_dim1] / d21;
318 d22 = w[k - 1 + (kw - 1) * w_dim1] / d21;
319 t = 1. / (d11 * d22 - 1.);
322 for (j = 1; j <= i__1; ++j) {
323 a[j + (k - 1) * a_dim1] = d21 * (d11 * w[j + (kw - 1)
324 * w_dim1] - w[j + kw * w_dim1]);
325 a[j + k * a_dim1] = d21 * (d22 * w[j + kw * w_dim1] -
326 w[j + (kw - 1) * w_dim1]);
333 a[k - 1 + (k - 1) * a_dim1] = w[k - 1 + (kw - 1) * w_dim1];
334 a[k - 1 + k * a_dim1] = w[k - 1 + kw * w_dim1];
335 a[k + k * a_dim1] = w[k + kw * w_dim1];
339 /* Store details of the interchanges in IPIV */
348 /* Decrease K and return to the start of the main loop */
355 /* Update the upper triangle of A11 (= A(1:k,1:k)) as
357 A11 := A11 - U12*D*U12' = A11 - U12*W'
359 computing blocks of NB columns at a time */
362 for (j = (k - 1) / *nb * *nb + 1; i__1 < 0 ? j >= 1 : j <= 1; j +=
365 i__2 = *nb, i__3 = k - j + 1;
368 /* Update the upper triangle of the diagonal block */
371 for (jj = j; jj <= i__2; ++jj) {
374 dgemv_("No transpose", &i__3, &i__4, &c_b8, &a[j + (k + 1) *
375 a_dim1], lda, &w[jj + (kw + 1) * w_dim1], ldw, &c_b9,
376 &a[j + jj * a_dim1], &c__1);
380 /* Update the rectangular superdiagonal block */
384 dgemm_("No transpose", "Transpose", &i__2, &jb, &i__3, &c_b8, &a[(
385 k + 1) * a_dim1 + 1], lda, &w[j + (kw + 1) * w_dim1], ldw,
386 &c_b9, &a[j * a_dim1 + 1], lda);
390 /* Put U12 in standard form by partially undoing the interchanges
402 if (jp != jj && j <= *n) {
404 dswap_(&i__1, &a[jp + j * a_dim1], lda, &a[jj + j * a_dim1], lda);
410 /* Set KB to the number of columns factorized */
416 /* Factorize the leading columns of A using the lower triangle
417 of A and working forwards, and compute the matrix W = L21*D
418 for use in updating A22
420 K is the main loop index, increasing from 1 in steps of 1 or 2 */
427 if (k >= *nb && *nb < *n || k > *n) {
431 /* Copy column K of A to column K of W and update it */
434 dcopy_(&i__1, &a[k + k * a_dim1], &c__1, &w[k + k * w_dim1], &c__1);
437 dgemv_("No transpose", &i__1, &i__2, &c_b8, &a[k + a_dim1], lda, &w[k
438 + w_dim1], ldw, &c_b9, &w[k + k * w_dim1], &c__1);
442 /* Determine rows and columns to be interchanged and whether
443 a 1-by-1 or 2-by-2 pivot block will be used */
445 absakk = (d__1 = w[k + k * w_dim1], abs(d__1));
447 /* IMAX is the row-index of the largest off-diagonal element in
448 column K, and COLMAX is its absolute value */
452 imax = k + idamax_(&i__1, &w[k + 1 + k * w_dim1], &c__1);
453 colmax = (d__1 = w[imax + k * w_dim1], abs(d__1));
458 if (max(absakk,colmax) == 0.) {
460 /* Column K is zero: set INFO and continue */
467 if (absakk >= alpha * colmax) {
469 /* no interchange, use 1-by-1 pivot block */
474 /* Copy column IMAX to column K+1 of W and update it */
477 dcopy_(&i__1, &a[imax + k * a_dim1], lda, &w[k + (k + 1) *
479 i__1 = *n - imax + 1;
480 dcopy_(&i__1, &a[imax + imax * a_dim1], &c__1, &w[imax + (k +
481 1) * w_dim1], &c__1);
484 dgemv_("No transpose", &i__1, &i__2, &c_b8, &a[k + a_dim1],
485 lda, &w[imax + w_dim1], ldw, &c_b9, &w[k + (k + 1) *
488 /* JMAX is the column-index of the largest off-diagonal
489 element in row IMAX, and ROWMAX is its absolute value */
492 jmax = k - 1 + idamax_(&i__1, &w[k + (k + 1) * w_dim1], &c__1)
494 rowmax = (d__1 = w[jmax + (k + 1) * w_dim1], abs(d__1));
497 jmax = imax + idamax_(&i__1, &w[imax + 1 + (k + 1) *
500 d__2 = rowmax, d__3 = (d__1 = w[jmax + (k + 1) * w_dim1],
502 rowmax = max(d__2,d__3);
505 if (absakk >= alpha * colmax * (colmax / rowmax)) {
507 /* no interchange, use 1-by-1 pivot block */
510 } else if ((d__1 = w[imax + (k + 1) * w_dim1], abs(d__1)) >=
513 /* interchange rows and columns K and IMAX, use 1-by-1
518 /* copy column K+1 of W to column K */
521 dcopy_(&i__1, &w[k + (k + 1) * w_dim1], &c__1, &w[k + k *
525 /* interchange rows and columns K+1 and IMAX, use 2-by-2
535 /* Updated column KP is already stored in column KK of W */
539 /* Copy non-updated column KK to column KP */
541 a[kp + k * a_dim1] = a[kk + k * a_dim1];
543 dcopy_(&i__1, &a[k + 1 + kk * a_dim1], &c__1, &a[kp + (k + 1)
546 dcopy_(&i__1, &a[kp + kk * a_dim1], &c__1, &a[kp + kp *
549 /* Interchange rows KK and KP in first KK columns of A and W */
551 dswap_(&kk, &a[kk + a_dim1], lda, &a[kp + a_dim1], lda);
552 dswap_(&kk, &w[kk + w_dim1], ldw, &w[kp + w_dim1], ldw);
557 /* 1-by-1 pivot block D(k): column k of W now holds
561 where L(k) is the k-th column of L
563 Store L(k) in column k of A */
566 dcopy_(&i__1, &w[k + k * w_dim1], &c__1, &a[k + k * a_dim1], &
569 r1 = 1. / a[k + k * a_dim1];
571 dscal_(&i__1, &r1, &a[k + 1 + k * a_dim1], &c__1);
575 /* 2-by-2 pivot block D(k): columns k and k+1 of W now hold
577 ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k)
579 where L(k) and L(k+1) are the k-th and (k+1)-th columns
584 /* Store L(k) and L(k+1) in columns k and k+1 of A */
586 d21 = w[k + 1 + k * w_dim1];
587 d11 = w[k + 1 + (k + 1) * w_dim1] / d21;
588 d22 = w[k + k * w_dim1] / d21;
589 t = 1. / (d11 * d22 - 1.);
592 for (j = k + 2; j <= i__1; ++j) {
593 a[j + k * a_dim1] = d21 * (d11 * w[j + k * w_dim1] -
594 w[j + (k + 1) * w_dim1]);
595 a[j + (k + 1) * a_dim1] = d21 * (d22 * w[j + (k + 1) *
596 w_dim1] - w[j + k * w_dim1]);
603 a[k + k * a_dim1] = w[k + k * w_dim1];
604 a[k + 1 + k * a_dim1] = w[k + 1 + k * w_dim1];
605 a[k + 1 + (k + 1) * a_dim1] = w[k + 1 + (k + 1) * w_dim1];
609 /* Store details of the interchanges in IPIV */
618 /* Increase K and return to the start of the main loop */
625 /* Update the lower triangle of A22 (= A(k:n,k:n)) as
627 A22 := A22 - L21*D*L21' = A22 - L21*W'
629 computing blocks of NB columns at a time */
633 for (j = k; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
635 i__3 = *nb, i__4 = *n - j + 1;
638 /* Update the lower triangle of the diagonal block */
641 for (jj = j; jj <= i__3; ++jj) {
644 dgemv_("No transpose", &i__4, &i__5, &c_b8, &a[jj + a_dim1],
645 lda, &w[jj + w_dim1], ldw, &c_b9, &a[jj + jj * a_dim1]
650 /* Update the rectangular subdiagonal block */
653 i__3 = *n - j - jb + 1;
655 dgemm_("No transpose", "Transpose", &i__3, &jb, &i__4, &c_b8,
656 &a[j + jb + a_dim1], lda, &w[j + w_dim1], ldw, &c_b9,
657 &a[j + jb + j * a_dim1], lda);
662 /* Put L21 in standard form by partially undoing the interchanges
674 if (jp != jj && j >= 1) {
675 dswap_(&j, &a[jp + a_dim1], lda, &a[jj + a_dim1], lda);
681 /* Set KB to the number of columns factorized */