clahef.c
Go to the documentation of this file.
00001 /* clahef.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 complex c_b1 = {1.f,0.f};
00019 static integer c__1 = 1;
00020 
00021 /* Subroutine */ int clahef_(char *uplo, integer *n, integer *nb, integer *kb, 
00022          complex *a, integer *lda, integer *ipiv, complex *w, integer *ldw, 
00023         integer *info)
00024 {
00025     /* System generated locals */
00026     integer a_dim1, a_offset, w_dim1, w_offset, i__1, i__2, i__3, i__4, i__5;
00027     real r__1, r__2, r__3, r__4;
00028     complex q__1, q__2, q__3, q__4;
00029 
00030     /* Builtin functions */
00031     double sqrt(doublereal), r_imag(complex *);
00032     void r_cnjg(complex *, complex *), c_div(complex *, complex *, complex *);
00033 
00034     /* Local variables */
00035     integer j, k;
00036     real t, r1;
00037     complex d11, d21, d22;
00038     integer jb, jj, kk, jp, kp, kw, kkw, imax, jmax;
00039     real alpha;
00040     extern /* Subroutine */ int cgemm_(char *, char *, integer *, integer *, 
00041             integer *, complex *, complex *, integer *, complex *, integer *, 
00042             complex *, complex *, integer *);
00043     extern logical lsame_(char *, char *);
00044     extern /* Subroutine */ int cgemv_(char *, integer *, integer *, complex *
00045 , complex *, integer *, complex *, integer *, complex *, complex *
00046 , integer *), ccopy_(integer *, complex *, integer *, 
00047             complex *, integer *), cswap_(integer *, complex *, integer *, 
00048             complex *, integer *);
00049     integer kstep;
00050     real absakk;
00051     extern /* Subroutine */ int clacgv_(integer *, complex *, integer *);
00052     extern integer icamax_(integer *, complex *, integer *);
00053     extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer 
00054             *);
00055     real colmax, rowmax;
00056 
00057 
00058 /*  -- LAPACK routine (version 3.2) -- */
00059 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00060 /*     November 2006 */
00061 
00062 /*     .. Scalar Arguments .. */
00063 /*     .. */
00064 /*     .. Array Arguments .. */
00065 /*     .. */
00066 
00067 /*  Purpose */
00068 /*  ======= */
00069 
00070 /*  CLAHEF computes a partial factorization of a complex Hermitian */
00071 /*  matrix A using the Bunch-Kaufman diagonal pivoting method. The */
00072 /*  partial factorization has the form: */
00073 
00074 /*  A  =  ( I  U12 ) ( A11  0  ) (  I    0   )  if UPLO = 'U', or: */
00075 /*        ( 0  U22 ) (  0   D  ) ( U12' U22' ) */
00076 
00077 /*  A  =  ( L11  0 ) (  D   0  ) ( L11' L21' )  if UPLO = 'L' */
00078 /*        ( L21  I ) (  0  A22 ) (  0    I   ) */
00079 
00080 /*  where the order of D is at most NB. The actual order is returned in */
00081 /*  the argument KB, and is either NB or NB-1, or N if N <= NB. */
00082 /*  Note that U' denotes the conjugate transpose of U. */
00083 
00084 /*  CLAHEF is an auxiliary routine called by CHETRF. It uses blocked code */
00085 /*  (calling Level 3 BLAS) to update the submatrix A11 (if UPLO = 'U') or */
00086 /*  A22 (if UPLO = 'L'). */
00087 
00088 /*  Arguments */
00089 /*  ========= */
00090 
00091 /*  UPLO    (input) CHARACTER*1 */
00092 /*          Specifies whether the upper or lower triangular part of the */
00093 /*          Hermitian matrix A is stored: */
00094 /*          = 'U':  Upper triangular */
00095 /*          = 'L':  Lower triangular */
00096 
00097 /*  N       (input) INTEGER */
00098 /*          The order of the matrix A.  N >= 0. */
00099 
00100 /*  NB      (input) INTEGER */
00101 /*          The maximum number of columns of the matrix A that should be */
00102 /*          factored.  NB should be at least 2 to allow for 2-by-2 pivot */
00103 /*          blocks. */
00104 
00105 /*  KB      (output) INTEGER */
00106 /*          The number of columns of A that were actually factored. */
00107 /*          KB is either NB-1 or NB, or N if N <= NB. */
00108 
00109 /*  A       (input/output) COMPLEX array, dimension (LDA,N) */
00110 /*          On entry, the Hermitian matrix A.  If UPLO = 'U', the leading */
00111 /*          n-by-n upper triangular part of A contains the upper */
00112 /*          triangular part of the matrix A, and the strictly lower */
00113 /*          triangular part of A is not referenced.  If UPLO = 'L', the */
00114 /*          leading n-by-n lower triangular part of A contains the lower */
00115 /*          triangular part of the matrix A, and the strictly upper */
00116 /*          triangular part of A is not referenced. */
00117 /*          On exit, A contains details of the partial factorization. */
00118 
00119 /*  LDA     (input) INTEGER */
00120 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00121 
00122 /*  IPIV    (output) INTEGER array, dimension (N) */
00123 /*          Details of the interchanges and the block structure of D. */
00124 /*          If UPLO = 'U', only the last KB elements of IPIV are set; */
00125 /*          if UPLO = 'L', only the first KB elements are set. */
00126 
00127 /*          If IPIV(k) > 0, then rows and columns k and IPIV(k) were */
00128 /*          interchanged and D(k,k) is a 1-by-1 diagonal block. */
00129 /*          If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and */
00130 /*          columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) */
00131 /*          is a 2-by-2 diagonal block.  If UPLO = 'L' and IPIV(k) = */
00132 /*          IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were */
00133 /*          interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */
00134 
00135 /*  W       (workspace) COMPLEX array, dimension (LDW,NB) */
00136 
00137 /*  LDW     (input) INTEGER */
00138 /*          The leading dimension of the array W.  LDW >= max(1,N). */
00139 
00140 /*  INFO    (output) INTEGER */
00141 /*          = 0: successful exit */
00142 /*          > 0: if INFO = k, D(k,k) is exactly zero.  The factorization */
00143 /*               has been completed, but the block diagonal matrix D is */
00144 /*               exactly singular. */
00145 
00146 /*  ===================================================================== */
00147 
00148 /*     .. Parameters .. */
00149 /*     .. */
00150 /*     .. Local Scalars .. */
00151 /*     .. */
00152 /*     .. External Functions .. */
00153 /*     .. */
00154 /*     .. External Subroutines .. */
00155 /*     .. */
00156 /*     .. Intrinsic Functions .. */
00157 /*     .. */
00158 /*     .. Statement Functions .. */
00159 /*     .. */
00160 /*     .. Statement Function definitions .. */
00161 /*     .. */
00162 /*     .. Executable Statements .. */
00163 
00164     /* Parameter adjustments */
00165     a_dim1 = *lda;
00166     a_offset = 1 + a_dim1;
00167     a -= a_offset;
00168     --ipiv;
00169     w_dim1 = *ldw;
00170     w_offset = 1 + w_dim1;
00171     w -= w_offset;
00172 
00173     /* Function Body */
00174     *info = 0;
00175 
00176 /*     Initialize ALPHA for use in choosing pivot block size. */
00177 
00178     alpha = (sqrt(17.f) + 1.f) / 8.f;
00179 
00180     if (lsame_(uplo, "U")) {
00181 
00182 /*        Factorize the trailing columns of A using the upper triangle */
00183 /*        of A and working backwards, and compute the matrix W = U12*D */
00184 /*        for use in updating A11 (note that conjg(W) is actually stored) */
00185 
00186 /*        K is the main loop index, decreasing from N in steps of 1 or 2 */
00187 
00188 /*        KW is the column of W which corresponds to column K of A */
00189 
00190         k = *n;
00191 L10:
00192         kw = *nb + k - *n;
00193 
00194 /*        Exit from loop */
00195 
00196         if (k <= *n - *nb + 1 && *nb < *n || k < 1) {
00197             goto L30;
00198         }
00199 
00200 /*        Copy column K of A to column KW of W and update it */
00201 
00202         i__1 = k - 1;
00203         ccopy_(&i__1, &a[k * a_dim1 + 1], &c__1, &w[kw * w_dim1 + 1], &c__1);
00204         i__1 = k + kw * w_dim1;
00205         i__2 = k + k * a_dim1;
00206         r__1 = a[i__2].r;
00207         w[i__1].r = r__1, w[i__1].i = 0.f;
00208         if (k < *n) {
00209             i__1 = *n - k;
00210             q__1.r = -1.f, q__1.i = -0.f;
00211             cgemv_("No transpose", &k, &i__1, &q__1, &a[(k + 1) * a_dim1 + 1], 
00212                      lda, &w[k + (kw + 1) * w_dim1], ldw, &c_b1, &w[kw * 
00213                     w_dim1 + 1], &c__1);
00214             i__1 = k + kw * w_dim1;
00215             i__2 = k + kw * w_dim1;
00216             r__1 = w[i__2].r;
00217             w[i__1].r = r__1, w[i__1].i = 0.f;
00218         }
00219 
00220         kstep = 1;
00221 
00222 /*        Determine rows and columns to be interchanged and whether */
00223 /*        a 1-by-1 or 2-by-2 pivot block will be used */
00224 
00225         i__1 = k + kw * w_dim1;
00226         absakk = (r__1 = w[i__1].r, dabs(r__1));
00227 
00228 /*        IMAX is the row-index of the largest off-diagonal element in */
00229 /*        column K, and COLMAX is its absolute value */
00230 
00231         if (k > 1) {
00232             i__1 = k - 1;
00233             imax = icamax_(&i__1, &w[kw * w_dim1 + 1], &c__1);
00234             i__1 = imax + kw * w_dim1;
00235             colmax = (r__1 = w[i__1].r, dabs(r__1)) + (r__2 = r_imag(&w[imax 
00236                     + kw * w_dim1]), dabs(r__2));
00237         } else {
00238             colmax = 0.f;
00239         }
00240 
00241         if (dmax(absakk,colmax) == 0.f) {
00242 
00243 /*           Column K is zero: set INFO and continue */
00244 
00245             if (*info == 0) {
00246                 *info = k;
00247             }
00248             kp = k;
00249             i__1 = k + k * a_dim1;
00250             i__2 = k + k * a_dim1;
00251             r__1 = a[i__2].r;
00252             a[i__1].r = r__1, a[i__1].i = 0.f;
00253         } else {
00254             if (absakk >= alpha * colmax) {
00255 
00256 /*              no interchange, use 1-by-1 pivot block */
00257 
00258                 kp = k;
00259             } else {
00260 
00261 /*              Copy column IMAX to column KW-1 of W and update it */
00262 
00263                 i__1 = imax - 1;
00264                 ccopy_(&i__1, &a[imax * a_dim1 + 1], &c__1, &w[(kw - 1) * 
00265                         w_dim1 + 1], &c__1);
00266                 i__1 = imax + (kw - 1) * w_dim1;
00267                 i__2 = imax + imax * a_dim1;
00268                 r__1 = a[i__2].r;
00269                 w[i__1].r = r__1, w[i__1].i = 0.f;
00270                 i__1 = k - imax;
00271                 ccopy_(&i__1, &a[imax + (imax + 1) * a_dim1], lda, &w[imax + 
00272                         1 + (kw - 1) * w_dim1], &c__1);
00273                 i__1 = k - imax;
00274                 clacgv_(&i__1, &w[imax + 1 + (kw - 1) * w_dim1], &c__1);
00275                 if (k < *n) {
00276                     i__1 = *n - k;
00277                     q__1.r = -1.f, q__1.i = -0.f;
00278                     cgemv_("No transpose", &k, &i__1, &q__1, &a[(k + 1) * 
00279                             a_dim1 + 1], lda, &w[imax + (kw + 1) * w_dim1], 
00280                             ldw, &c_b1, &w[(kw - 1) * w_dim1 + 1], &c__1);
00281                     i__1 = imax + (kw - 1) * w_dim1;
00282                     i__2 = imax + (kw - 1) * w_dim1;
00283                     r__1 = w[i__2].r;
00284                     w[i__1].r = r__1, w[i__1].i = 0.f;
00285                 }
00286 
00287 /*              JMAX is the column-index of the largest off-diagonal */
00288 /*              element in row IMAX, and ROWMAX is its absolute value */
00289 
00290                 i__1 = k - imax;
00291                 jmax = imax + icamax_(&i__1, &w[imax + 1 + (kw - 1) * w_dim1], 
00292                          &c__1);
00293                 i__1 = jmax + (kw - 1) * w_dim1;
00294                 rowmax = (r__1 = w[i__1].r, dabs(r__1)) + (r__2 = r_imag(&w[
00295                         jmax + (kw - 1) * w_dim1]), dabs(r__2));
00296                 if (imax > 1) {
00297                     i__1 = imax - 1;
00298                     jmax = icamax_(&i__1, &w[(kw - 1) * w_dim1 + 1], &c__1);
00299 /* Computing MAX */
00300                     i__1 = jmax + (kw - 1) * w_dim1;
00301                     r__3 = rowmax, r__4 = (r__1 = w[i__1].r, dabs(r__1)) + (
00302                             r__2 = r_imag(&w[jmax + (kw - 1) * w_dim1]), dabs(
00303                             r__2));
00304                     rowmax = dmax(r__3,r__4);
00305                 }
00306 
00307                 if (absakk >= alpha * colmax * (colmax / rowmax)) {
00308 
00309 /*                 no interchange, use 1-by-1 pivot block */
00310 
00311                     kp = k;
00312                 } else /* if(complicated condition) */ {
00313                     i__1 = imax + (kw - 1) * w_dim1;
00314                     if ((r__1 = w[i__1].r, dabs(r__1)) >= alpha * rowmax) {
00315 
00316 /*                 interchange rows and columns K and IMAX, use 1-by-1 */
00317 /*                 pivot block */
00318 
00319                         kp = imax;
00320 
00321 /*                 copy column KW-1 of W to column KW */
00322 
00323                         ccopy_(&k, &w[(kw - 1) * w_dim1 + 1], &c__1, &w[kw * 
00324                                 w_dim1 + 1], &c__1);
00325                     } else {
00326 
00327 /*                 interchange rows and columns K-1 and IMAX, use 2-by-2 */
00328 /*                 pivot block */
00329 
00330                         kp = imax;
00331                         kstep = 2;
00332                     }
00333                 }
00334             }
00335 
00336             kk = k - kstep + 1;
00337             kkw = *nb + kk - *n;
00338 
00339 /*           Updated column KP is already stored in column KKW of W */
00340 
00341             if (kp != kk) {
00342 
00343 /*              Copy non-updated column KK to column KP */
00344 
00345                 i__1 = kp + kp * a_dim1;
00346                 i__2 = kk + kk * a_dim1;
00347                 r__1 = a[i__2].r;
00348                 a[i__1].r = r__1, a[i__1].i = 0.f;
00349                 i__1 = kk - 1 - kp;
00350                 ccopy_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + (kp + 
00351                         1) * a_dim1], lda);
00352                 i__1 = kk - 1 - kp;
00353                 clacgv_(&i__1, &a[kp + (kp + 1) * a_dim1], lda);
00354                 i__1 = kp - 1;
00355                 ccopy_(&i__1, &a[kk * a_dim1 + 1], &c__1, &a[kp * a_dim1 + 1], 
00356                          &c__1);
00357 
00358 /*              Interchange rows KK and KP in last KK columns of A and W */
00359 
00360                 if (kk < *n) {
00361                     i__1 = *n - kk;
00362                     cswap_(&i__1, &a[kk + (kk + 1) * a_dim1], lda, &a[kp + (
00363                             kk + 1) * a_dim1], lda);
00364                 }
00365                 i__1 = *n - kk + 1;
00366                 cswap_(&i__1, &w[kk + kkw * w_dim1], ldw, &w[kp + kkw * 
00367                         w_dim1], ldw);
00368             }
00369 
00370             if (kstep == 1) {
00371 
00372 /*              1-by-1 pivot block D(k): column KW of W now holds */
00373 
00374 /*              W(k) = U(k)*D(k) */
00375 
00376 /*              where U(k) is the k-th column of U */
00377 
00378 /*              Store U(k) in column k of A */
00379 
00380                 ccopy_(&k, &w[kw * w_dim1 + 1], &c__1, &a[k * a_dim1 + 1], &
00381                         c__1);
00382                 i__1 = k + k * a_dim1;
00383                 r1 = 1.f / a[i__1].r;
00384                 i__1 = k - 1;
00385                 csscal_(&i__1, &r1, &a[k * a_dim1 + 1], &c__1);
00386 
00387 /*              Conjugate W(k) */
00388 
00389                 i__1 = k - 1;
00390                 clacgv_(&i__1, &w[kw * w_dim1 + 1], &c__1);
00391             } else {
00392 
00393 /*              2-by-2 pivot block D(k): columns KW and KW-1 of W now */
00394 /*              hold */
00395 
00396 /*              ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k) */
00397 
00398 /*              where U(k) and U(k-1) are the k-th and (k-1)-th columns */
00399 /*              of U */
00400 
00401                 if (k > 2) {
00402 
00403 /*                 Store U(k) and U(k-1) in columns k and k-1 of A */
00404 
00405                     i__1 = k - 1 + kw * w_dim1;
00406                     d21.r = w[i__1].r, d21.i = w[i__1].i;
00407                     r_cnjg(&q__2, &d21);
00408                     c_div(&q__1, &w[k + kw * w_dim1], &q__2);
00409                     d11.r = q__1.r, d11.i = q__1.i;
00410                     c_div(&q__1, &w[k - 1 + (kw - 1) * w_dim1], &d21);
00411                     d22.r = q__1.r, d22.i = q__1.i;
00412                     q__1.r = d11.r * d22.r - d11.i * d22.i, q__1.i = d11.r * 
00413                             d22.i + d11.i * d22.r;
00414                     t = 1.f / (q__1.r - 1.f);
00415                     q__2.r = t, q__2.i = 0.f;
00416                     c_div(&q__1, &q__2, &d21);
00417                     d21.r = q__1.r, d21.i = q__1.i;
00418                     i__1 = k - 2;
00419                     for (j = 1; j <= i__1; ++j) {
00420                         i__2 = j + (k - 1) * a_dim1;
00421                         i__3 = j + (kw - 1) * w_dim1;
00422                         q__3.r = d11.r * w[i__3].r - d11.i * w[i__3].i, 
00423                                 q__3.i = d11.r * w[i__3].i + d11.i * w[i__3]
00424                                 .r;
00425                         i__4 = j + kw * w_dim1;
00426                         q__2.r = q__3.r - w[i__4].r, q__2.i = q__3.i - w[i__4]
00427                                 .i;
00428                         q__1.r = d21.r * q__2.r - d21.i * q__2.i, q__1.i = 
00429                                 d21.r * q__2.i + d21.i * q__2.r;
00430                         a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00431                         i__2 = j + k * a_dim1;
00432                         r_cnjg(&q__2, &d21);
00433                         i__3 = j + kw * w_dim1;
00434                         q__4.r = d22.r * w[i__3].r - d22.i * w[i__3].i, 
00435                                 q__4.i = d22.r * w[i__3].i + d22.i * w[i__3]
00436                                 .r;
00437                         i__4 = j + (kw - 1) * w_dim1;
00438                         q__3.r = q__4.r - w[i__4].r, q__3.i = q__4.i - w[i__4]
00439                                 .i;
00440                         q__1.r = q__2.r * q__3.r - q__2.i * q__3.i, q__1.i = 
00441                                 q__2.r * q__3.i + q__2.i * q__3.r;
00442                         a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00443 /* L20: */
00444                     }
00445                 }
00446 
00447 /*              Copy D(k) to A */
00448 
00449                 i__1 = k - 1 + (k - 1) * a_dim1;
00450                 i__2 = k - 1 + (kw - 1) * w_dim1;
00451                 a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
00452                 i__1 = k - 1 + k * a_dim1;
00453                 i__2 = k - 1 + kw * w_dim1;
00454                 a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
00455                 i__1 = k + k * a_dim1;
00456                 i__2 = k + kw * w_dim1;
00457                 a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
00458 
00459 /*              Conjugate W(k) and W(k-1) */
00460 
00461                 i__1 = k - 1;
00462                 clacgv_(&i__1, &w[kw * w_dim1 + 1], &c__1);
00463                 i__1 = k - 2;
00464                 clacgv_(&i__1, &w[(kw - 1) * w_dim1 + 1], &c__1);
00465             }
00466         }
00467 
00468 /*        Store details of the interchanges in IPIV */
00469 
00470         if (kstep == 1) {
00471             ipiv[k] = kp;
00472         } else {
00473             ipiv[k] = -kp;
00474             ipiv[k - 1] = -kp;
00475         }
00476 
00477 /*        Decrease K and return to the start of the main loop */
00478 
00479         k -= kstep;
00480         goto L10;
00481 
00482 L30:
00483 
00484 /*        Update the upper triangle of A11 (= A(1:k,1:k)) as */
00485 
00486 /*        A11 := A11 - U12*D*U12' = A11 - U12*W' */
00487 
00488 /*        computing blocks of NB columns at a time (note that conjg(W) is */
00489 /*        actually stored) */
00490 
00491         i__1 = -(*nb);
00492         for (j = (k - 1) / *nb * *nb + 1; i__1 < 0 ? j >= 1 : j <= 1; j += 
00493                 i__1) {
00494 /* Computing MIN */
00495             i__2 = *nb, i__3 = k - j + 1;
00496             jb = min(i__2,i__3);
00497 
00498 /*           Update the upper triangle of the diagonal block */
00499 
00500             i__2 = j + jb - 1;
00501             for (jj = j; jj <= i__2; ++jj) {
00502                 i__3 = jj + jj * a_dim1;
00503                 i__4 = jj + jj * a_dim1;
00504                 r__1 = a[i__4].r;
00505                 a[i__3].r = r__1, a[i__3].i = 0.f;
00506                 i__3 = jj - j + 1;
00507                 i__4 = *n - k;
00508                 q__1.r = -1.f, q__1.i = -0.f;
00509                 cgemv_("No transpose", &i__3, &i__4, &q__1, &a[j + (k + 1) * 
00510                         a_dim1], lda, &w[jj + (kw + 1) * w_dim1], ldw, &c_b1, 
00511                         &a[j + jj * a_dim1], &c__1);
00512                 i__3 = jj + jj * a_dim1;
00513                 i__4 = jj + jj * a_dim1;
00514                 r__1 = a[i__4].r;
00515                 a[i__3].r = r__1, a[i__3].i = 0.f;
00516 /* L40: */
00517             }
00518 
00519 /*           Update the rectangular superdiagonal block */
00520 
00521             i__2 = j - 1;
00522             i__3 = *n - k;
00523             q__1.r = -1.f, q__1.i = -0.f;
00524             cgemm_("No transpose", "Transpose", &i__2, &jb, &i__3, &q__1, &a[(
00525                     k + 1) * a_dim1 + 1], lda, &w[j + (kw + 1) * w_dim1], ldw, 
00526                      &c_b1, &a[j * a_dim1 + 1], lda);
00527 /* L50: */
00528         }
00529 
00530 /*        Put U12 in standard form by partially undoing the interchanges */
00531 /*        in columns k+1:n */
00532 
00533         j = k + 1;
00534 L60:
00535         jj = j;
00536         jp = ipiv[j];
00537         if (jp < 0) {
00538             jp = -jp;
00539             ++j;
00540         }
00541         ++j;
00542         if (jp != jj && j <= *n) {
00543             i__1 = *n - j + 1;
00544             cswap_(&i__1, &a[jp + j * a_dim1], lda, &a[jj + j * a_dim1], lda);
00545         }
00546         if (j <= *n) {
00547             goto L60;
00548         }
00549 
00550 /*        Set KB to the number of columns factorized */
00551 
00552         *kb = *n - k;
00553 
00554     } else {
00555 
00556 /*        Factorize the leading columns of A using the lower triangle */
00557 /*        of A and working forwards, and compute the matrix W = L21*D */
00558 /*        for use in updating A22 (note that conjg(W) is actually stored) */
00559 
00560 /*        K is the main loop index, increasing from 1 in steps of 1 or 2 */
00561 
00562         k = 1;
00563 L70:
00564 
00565 /*        Exit from loop */
00566 
00567         if (k >= *nb && *nb < *n || k > *n) {
00568             goto L90;
00569         }
00570 
00571 /*        Copy column K of A to column K of W and update it */
00572 
00573         i__1 = k + k * w_dim1;
00574         i__2 = k + k * a_dim1;
00575         r__1 = a[i__2].r;
00576         w[i__1].r = r__1, w[i__1].i = 0.f;
00577         if (k < *n) {
00578             i__1 = *n - k;
00579             ccopy_(&i__1, &a[k + 1 + k * a_dim1], &c__1, &w[k + 1 + k * 
00580                     w_dim1], &c__1);
00581         }
00582         i__1 = *n - k + 1;
00583         i__2 = k - 1;
00584         q__1.r = -1.f, q__1.i = -0.f;
00585         cgemv_("No transpose", &i__1, &i__2, &q__1, &a[k + a_dim1], lda, &w[k 
00586                 + w_dim1], ldw, &c_b1, &w[k + k * w_dim1], &c__1);
00587         i__1 = k + k * w_dim1;
00588         i__2 = k + k * w_dim1;
00589         r__1 = w[i__2].r;
00590         w[i__1].r = r__1, w[i__1].i = 0.f;
00591 
00592         kstep = 1;
00593 
00594 /*        Determine rows and columns to be interchanged and whether */
00595 /*        a 1-by-1 or 2-by-2 pivot block will be used */
00596 
00597         i__1 = k + k * w_dim1;
00598         absakk = (r__1 = w[i__1].r, dabs(r__1));
00599 
00600 /*        IMAX is the row-index of the largest off-diagonal element in */
00601 /*        column K, and COLMAX is its absolute value */
00602 
00603         if (k < *n) {
00604             i__1 = *n - k;
00605             imax = k + icamax_(&i__1, &w[k + 1 + k * w_dim1], &c__1);
00606             i__1 = imax + k * w_dim1;
00607             colmax = (r__1 = w[i__1].r, dabs(r__1)) + (r__2 = r_imag(&w[imax 
00608                     + k * w_dim1]), dabs(r__2));
00609         } else {
00610             colmax = 0.f;
00611         }
00612 
00613         if (dmax(absakk,colmax) == 0.f) {
00614 
00615 /*           Column K is zero: set INFO and continue */
00616 
00617             if (*info == 0) {
00618                 *info = k;
00619             }
00620             kp = k;
00621             i__1 = k + k * a_dim1;
00622             i__2 = k + k * a_dim1;
00623             r__1 = a[i__2].r;
00624             a[i__1].r = r__1, a[i__1].i = 0.f;
00625         } else {
00626             if (absakk >= alpha * colmax) {
00627 
00628 /*              no interchange, use 1-by-1 pivot block */
00629 
00630                 kp = k;
00631             } else {
00632 
00633 /*              Copy column IMAX to column K+1 of W and update it */
00634 
00635                 i__1 = imax - k;
00636                 ccopy_(&i__1, &a[imax + k * a_dim1], lda, &w[k + (k + 1) * 
00637                         w_dim1], &c__1);
00638                 i__1 = imax - k;
00639                 clacgv_(&i__1, &w[k + (k + 1) * w_dim1], &c__1);
00640                 i__1 = imax + (k + 1) * w_dim1;
00641                 i__2 = imax + imax * a_dim1;
00642                 r__1 = a[i__2].r;
00643                 w[i__1].r = r__1, w[i__1].i = 0.f;
00644                 if (imax < *n) {
00645                     i__1 = *n - imax;
00646                     ccopy_(&i__1, &a[imax + 1 + imax * a_dim1], &c__1, &w[
00647                             imax + 1 + (k + 1) * w_dim1], &c__1);
00648                 }
00649                 i__1 = *n - k + 1;
00650                 i__2 = k - 1;
00651                 q__1.r = -1.f, q__1.i = -0.f;
00652                 cgemv_("No transpose", &i__1, &i__2, &q__1, &a[k + a_dim1], 
00653                         lda, &w[imax + w_dim1], ldw, &c_b1, &w[k + (k + 1) * 
00654                         w_dim1], &c__1);
00655                 i__1 = imax + (k + 1) * w_dim1;
00656                 i__2 = imax + (k + 1) * w_dim1;
00657                 r__1 = w[i__2].r;
00658                 w[i__1].r = r__1, w[i__1].i = 0.f;
00659 
00660 /*              JMAX is the column-index of the largest off-diagonal */
00661 /*              element in row IMAX, and ROWMAX is its absolute value */
00662 
00663                 i__1 = imax - k;
00664                 jmax = k - 1 + icamax_(&i__1, &w[k + (k + 1) * w_dim1], &c__1)
00665                         ;
00666                 i__1 = jmax + (k + 1) * w_dim1;
00667                 rowmax = (r__1 = w[i__1].r, dabs(r__1)) + (r__2 = r_imag(&w[
00668                         jmax + (k + 1) * w_dim1]), dabs(r__2));
00669                 if (imax < *n) {
00670                     i__1 = *n - imax;
00671                     jmax = imax + icamax_(&i__1, &w[imax + 1 + (k + 1) * 
00672                             w_dim1], &c__1);
00673 /* Computing MAX */
00674                     i__1 = jmax + (k + 1) * w_dim1;
00675                     r__3 = rowmax, r__4 = (r__1 = w[i__1].r, dabs(r__1)) + (
00676                             r__2 = r_imag(&w[jmax + (k + 1) * w_dim1]), dabs(
00677                             r__2));
00678                     rowmax = dmax(r__3,r__4);
00679                 }
00680 
00681                 if (absakk >= alpha * colmax * (colmax / rowmax)) {
00682 
00683 /*                 no interchange, use 1-by-1 pivot block */
00684 
00685                     kp = k;
00686                 } else /* if(complicated condition) */ {
00687                     i__1 = imax + (k + 1) * w_dim1;
00688                     if ((r__1 = w[i__1].r, dabs(r__1)) >= alpha * rowmax) {
00689 
00690 /*                 interchange rows and columns K and IMAX, use 1-by-1 */
00691 /*                 pivot block */
00692 
00693                         kp = imax;
00694 
00695 /*                 copy column K+1 of W to column K */
00696 
00697                         i__1 = *n - k + 1;
00698                         ccopy_(&i__1, &w[k + (k + 1) * w_dim1], &c__1, &w[k + 
00699                                 k * w_dim1], &c__1);
00700                     } else {
00701 
00702 /*                 interchange rows and columns K+1 and IMAX, use 2-by-2 */
00703 /*                 pivot block */
00704 
00705                         kp = imax;
00706                         kstep = 2;
00707                     }
00708                 }
00709             }
00710 
00711             kk = k + kstep - 1;
00712 
00713 /*           Updated column KP is already stored in column KK of W */
00714 
00715             if (kp != kk) {
00716 
00717 /*              Copy non-updated column KK to column KP */
00718 
00719                 i__1 = kp + kp * a_dim1;
00720                 i__2 = kk + kk * a_dim1;
00721                 r__1 = a[i__2].r;
00722                 a[i__1].r = r__1, a[i__1].i = 0.f;
00723                 i__1 = kp - kk - 1;
00724                 ccopy_(&i__1, &a[kk + 1 + kk * a_dim1], &c__1, &a[kp + (kk + 
00725                         1) * a_dim1], lda);
00726                 i__1 = kp - kk - 1;
00727                 clacgv_(&i__1, &a[kp + (kk + 1) * a_dim1], lda);
00728                 if (kp < *n) {
00729                     i__1 = *n - kp;
00730                     ccopy_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + 1 
00731                             + kp * a_dim1], &c__1);
00732                 }
00733 
00734 /*              Interchange rows KK and KP in first KK columns of A and W */
00735 
00736                 i__1 = kk - 1;
00737                 cswap_(&i__1, &a[kk + a_dim1], lda, &a[kp + a_dim1], lda);
00738                 cswap_(&kk, &w[kk + w_dim1], ldw, &w[kp + w_dim1], ldw);
00739             }
00740 
00741             if (kstep == 1) {
00742 
00743 /*              1-by-1 pivot block D(k): column k of W now holds */
00744 
00745 /*              W(k) = L(k)*D(k) */
00746 
00747 /*              where L(k) is the k-th column of L */
00748 
00749 /*              Store L(k) in column k of A */
00750 
00751                 i__1 = *n - k + 1;
00752                 ccopy_(&i__1, &w[k + k * w_dim1], &c__1, &a[k + k * a_dim1], &
00753                         c__1);
00754                 if (k < *n) {
00755                     i__1 = k + k * a_dim1;
00756                     r1 = 1.f / a[i__1].r;
00757                     i__1 = *n - k;
00758                     csscal_(&i__1, &r1, &a[k + 1 + k * a_dim1], &c__1);
00759 
00760 /*                 Conjugate W(k) */
00761 
00762                     i__1 = *n - k;
00763                     clacgv_(&i__1, &w[k + 1 + k * w_dim1], &c__1);
00764                 }
00765             } else {
00766 
00767 /*              2-by-2 pivot block D(k): columns k and k+1 of W now hold */
00768 
00769 /*              ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k) */
00770 
00771 /*              where L(k) and L(k+1) are the k-th and (k+1)-th columns */
00772 /*              of L */
00773 
00774                 if (k < *n - 1) {
00775 
00776 /*                 Store L(k) and L(k+1) in columns k and k+1 of A */
00777 
00778                     i__1 = k + 1 + k * w_dim1;
00779                     d21.r = w[i__1].r, d21.i = w[i__1].i;
00780                     c_div(&q__1, &w[k + 1 + (k + 1) * w_dim1], &d21);
00781                     d11.r = q__1.r, d11.i = q__1.i;
00782                     r_cnjg(&q__2, &d21);
00783                     c_div(&q__1, &w[k + k * w_dim1], &q__2);
00784                     d22.r = q__1.r, d22.i = q__1.i;
00785                     q__1.r = d11.r * d22.r - d11.i * d22.i, q__1.i = d11.r * 
00786                             d22.i + d11.i * d22.r;
00787                     t = 1.f / (q__1.r - 1.f);
00788                     q__2.r = t, q__2.i = 0.f;
00789                     c_div(&q__1, &q__2, &d21);
00790                     d21.r = q__1.r, d21.i = q__1.i;
00791                     i__1 = *n;
00792                     for (j = k + 2; j <= i__1; ++j) {
00793                         i__2 = j + k * a_dim1;
00794                         r_cnjg(&q__2, &d21);
00795                         i__3 = j + k * w_dim1;
00796                         q__4.r = d11.r * w[i__3].r - d11.i * w[i__3].i, 
00797                                 q__4.i = d11.r * w[i__3].i + d11.i * w[i__3]
00798                                 .r;
00799                         i__4 = j + (k + 1) * w_dim1;
00800                         q__3.r = q__4.r - w[i__4].r, q__3.i = q__4.i - w[i__4]
00801                                 .i;
00802                         q__1.r = q__2.r * q__3.r - q__2.i * q__3.i, q__1.i = 
00803                                 q__2.r * q__3.i + q__2.i * q__3.r;
00804                         a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00805                         i__2 = j + (k + 1) * a_dim1;
00806                         i__3 = j + (k + 1) * w_dim1;
00807                         q__3.r = d22.r * w[i__3].r - d22.i * w[i__3].i, 
00808                                 q__3.i = d22.r * w[i__3].i + d22.i * w[i__3]
00809                                 .r;
00810                         i__4 = j + k * w_dim1;
00811                         q__2.r = q__3.r - w[i__4].r, q__2.i = q__3.i - w[i__4]
00812                                 .i;
00813                         q__1.r = d21.r * q__2.r - d21.i * q__2.i, q__1.i = 
00814                                 d21.r * q__2.i + d21.i * q__2.r;
00815                         a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00816 /* L80: */
00817                     }
00818                 }
00819 
00820 /*              Copy D(k) to A */
00821 
00822                 i__1 = k + k * a_dim1;
00823                 i__2 = k + k * w_dim1;
00824                 a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
00825                 i__1 = k + 1 + k * a_dim1;
00826                 i__2 = k + 1 + k * w_dim1;
00827                 a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
00828                 i__1 = k + 1 + (k + 1) * a_dim1;
00829                 i__2 = k + 1 + (k + 1) * w_dim1;
00830                 a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
00831 
00832 /*              Conjugate W(k) and W(k+1) */
00833 
00834                 i__1 = *n - k;
00835                 clacgv_(&i__1, &w[k + 1 + k * w_dim1], &c__1);
00836                 i__1 = *n - k - 1;
00837                 clacgv_(&i__1, &w[k + 2 + (k + 1) * w_dim1], &c__1);
00838             }
00839         }
00840 
00841 /*        Store details of the interchanges in IPIV */
00842 
00843         if (kstep == 1) {
00844             ipiv[k] = kp;
00845         } else {
00846             ipiv[k] = -kp;
00847             ipiv[k + 1] = -kp;
00848         }
00849 
00850 /*        Increase K and return to the start of the main loop */
00851 
00852         k += kstep;
00853         goto L70;
00854 
00855 L90:
00856 
00857 /*        Update the lower triangle of A22 (= A(k:n,k:n)) as */
00858 
00859 /*        A22 := A22 - L21*D*L21' = A22 - L21*W' */
00860 
00861 /*        computing blocks of NB columns at a time (note that conjg(W) is */
00862 /*        actually stored) */
00863 
00864         i__1 = *n;
00865         i__2 = *nb;
00866         for (j = k; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
00867 /* Computing MIN */
00868             i__3 = *nb, i__4 = *n - j + 1;
00869             jb = min(i__3,i__4);
00870 
00871 /*           Update the lower triangle of the diagonal block */
00872 
00873             i__3 = j + jb - 1;
00874             for (jj = j; jj <= i__3; ++jj) {
00875                 i__4 = jj + jj * a_dim1;
00876                 i__5 = jj + jj * a_dim1;
00877                 r__1 = a[i__5].r;
00878                 a[i__4].r = r__1, a[i__4].i = 0.f;
00879                 i__4 = j + jb - jj;
00880                 i__5 = k - 1;
00881                 q__1.r = -1.f, q__1.i = -0.f;
00882                 cgemv_("No transpose", &i__4, &i__5, &q__1, &a[jj + a_dim1], 
00883                         lda, &w[jj + w_dim1], ldw, &c_b1, &a[jj + jj * a_dim1]
00884 , &c__1);
00885                 i__4 = jj + jj * a_dim1;
00886                 i__5 = jj + jj * a_dim1;
00887                 r__1 = a[i__5].r;
00888                 a[i__4].r = r__1, a[i__4].i = 0.f;
00889 /* L100: */
00890             }
00891 
00892 /*           Update the rectangular subdiagonal block */
00893 
00894             if (j + jb <= *n) {
00895                 i__3 = *n - j - jb + 1;
00896                 i__4 = k - 1;
00897                 q__1.r = -1.f, q__1.i = -0.f;
00898                 cgemm_("No transpose", "Transpose", &i__3, &jb, &i__4, &q__1, 
00899                         &a[j + jb + a_dim1], lda, &w[j + w_dim1], ldw, &c_b1, 
00900                         &a[j + jb + j * a_dim1], lda);
00901             }
00902 /* L110: */
00903         }
00904 
00905 /*        Put L21 in standard form by partially undoing the interchanges */
00906 /*        in columns 1:k-1 */
00907 
00908         j = k - 1;
00909 L120:
00910         jj = j;
00911         jp = ipiv[j];
00912         if (jp < 0) {
00913             jp = -jp;
00914             --j;
00915         }
00916         --j;
00917         if (jp != jj && j >= 1) {
00918             cswap_(&j, &a[jp + a_dim1], lda, &a[jj + a_dim1], lda);
00919         }
00920         if (j >= 1) {
00921             goto L120;
00922         }
00923 
00924 /*        Set KB to the number of columns factorized */
00925 
00926         *kb = k - 1;
00927 
00928     }
00929     return 0;
00930 
00931 /*     End of CLAHEF */
00932 
00933 } /* clahef_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:30