chptrf.c
Go to the documentation of this file.
00001 /* chptrf.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 integer c__1 = 1;
00019 
00020 /* Subroutine */ int chptrf_(char *uplo, integer *n, complex *ap, integer *
00021         ipiv, integer *info)
00022 {
00023     /* System generated locals */
00024     integer i__1, i__2, i__3, i__4, i__5, i__6;
00025     real r__1, r__2, r__3, r__4;
00026     complex q__1, q__2, q__3, q__4, q__5, q__6;
00027 
00028     /* Builtin functions */
00029     double sqrt(doublereal), r_imag(complex *);
00030     void r_cnjg(complex *, complex *);
00031 
00032     /* Local variables */
00033     real d__;
00034     integer i__, j, k;
00035     complex t;
00036     real r1, d11;
00037     complex d12;
00038     real d22;
00039     complex d21;
00040     integer kc, kk, kp;
00041     complex wk;
00042     integer kx;
00043     real tt;
00044     integer knc, kpc, npp;
00045     complex wkm1, wkp1;
00046     extern /* Subroutine */ int chpr_(char *, integer *, real *, complex *, 
00047             integer *, complex *);
00048     integer imax, jmax;
00049     real alpha;
00050     extern logical lsame_(char *, char *);
00051     extern /* Subroutine */ int cswap_(integer *, complex *, integer *, 
00052             complex *, integer *);
00053     integer kstep;
00054     logical upper;
00055     extern doublereal slapy2_(real *, real *);
00056     real absakk;
00057     extern integer icamax_(integer *, complex *, integer *);
00058     extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer 
00059             *), xerbla_(char *, integer *);
00060     real colmax, rowmax;
00061 
00062 
00063 /*  -- LAPACK routine (version 3.2) -- */
00064 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00065 /*     November 2006 */
00066 
00067 /*     .. Scalar Arguments .. */
00068 /*     .. */
00069 /*     .. Array Arguments .. */
00070 /*     .. */
00071 
00072 /*  Purpose */
00073 /*  ======= */
00074 
00075 /*  CHPTRF computes the factorization of a complex Hermitian packed */
00076 /*  matrix A using the Bunch-Kaufman diagonal pivoting method: */
00077 
00078 /*     A = U*D*U**H  or  A = L*D*L**H */
00079 
00080 /*  where U (or L) is a product of permutation and unit upper (lower) */
00081 /*  triangular matrices, and D is Hermitian and block diagonal with */
00082 /*  1-by-1 and 2-by-2 diagonal blocks. */
00083 
00084 /*  Arguments */
00085 /*  ========= */
00086 
00087 /*  UPLO    (input) CHARACTER*1 */
00088 /*          = 'U':  Upper triangle of A is stored; */
00089 /*          = 'L':  Lower triangle of A is stored. */
00090 
00091 /*  N       (input) INTEGER */
00092 /*          The order of the matrix A.  N >= 0. */
00093 
00094 /*  AP      (input/output) COMPLEX array, dimension (N*(N+1)/2) */
00095 /*          On entry, the upper or lower triangle of the Hermitian matrix */
00096 /*          A, packed columnwise in a linear array.  The j-th column of A */
00097 /*          is stored in the array AP as follows: */
00098 /*          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
00099 /*          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
00100 
00101 /*          On exit, the block diagonal matrix D and the multipliers used */
00102 /*          to obtain the factor U or L, stored as a packed triangular */
00103 /*          matrix overwriting A (see below for further details). */
00104 
00105 /*  IPIV    (output) INTEGER array, dimension (N) */
00106 /*          Details of the interchanges and the block structure of D. */
00107 /*          If IPIV(k) > 0, then rows and columns k and IPIV(k) were */
00108 /*          interchanged and D(k,k) is a 1-by-1 diagonal block. */
00109 /*          If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and */
00110 /*          columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) */
00111 /*          is a 2-by-2 diagonal block.  If UPLO = 'L' and IPIV(k) = */
00112 /*          IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were */
00113 /*          interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */
00114 
00115 /*  INFO    (output) INTEGER */
00116 /*          = 0: successful exit */
00117 /*          < 0: if INFO = -i, the i-th argument had an illegal value */
00118 /*          > 0: if INFO = i, D(i,i) is exactly zero.  The factorization */
00119 /*               has been completed, but the block diagonal matrix D is */
00120 /*               exactly singular, and division by zero will occur if it */
00121 /*               is used to solve a system of equations. */
00122 
00123 /*  Further Details */
00124 /*  =============== */
00125 
00126 /*  5-96 - Based on modifications by J. Lewis, Boeing Computer Services */
00127 /*         Company */
00128 
00129 /*  If UPLO = 'U', then A = U*D*U', where */
00130 /*     U = P(n)*U(n)* ... *P(k)U(k)* ..., */
00131 /*  i.e., U is a product of terms P(k)*U(k), where k decreases from n to */
00132 /*  1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */
00133 /*  and 2-by-2 diagonal blocks D(k).  P(k) is a permutation matrix as */
00134 /*  defined by IPIV(k), and U(k) is a unit upper triangular matrix, such */
00135 /*  that if the diagonal block D(k) is of order s (s = 1 or 2), then */
00136 
00137 /*             (   I    v    0   )   k-s */
00138 /*     U(k) =  (   0    I    0   )   s */
00139 /*             (   0    0    I   )   n-k */
00140 /*                k-s   s   n-k */
00141 
00142 /*  If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k). */
00143 /*  If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k), */
00144 /*  and A(k,k), and v overwrites A(1:k-2,k-1:k). */
00145 
00146 /*  If UPLO = 'L', then A = L*D*L', where */
00147 /*     L = P(1)*L(1)* ... *P(k)*L(k)* ..., */
00148 /*  i.e., L is a product of terms P(k)*L(k), where k increases from 1 to */
00149 /*  n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */
00150 /*  and 2-by-2 diagonal blocks D(k).  P(k) is a permutation matrix as */
00151 /*  defined by IPIV(k), and L(k) is a unit lower triangular matrix, such */
00152 /*  that if the diagonal block D(k) is of order s (s = 1 or 2), then */
00153 
00154 /*             (   I    0     0   )  k-1 */
00155 /*     L(k) =  (   0    I     0   )  s */
00156 /*             (   0    v     I   )  n-k-s+1 */
00157 /*                k-1   s  n-k-s+1 */
00158 
00159 /*  If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k). */
00160 /*  If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k), */
00161 /*  and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1). */
00162 
00163 /*  ===================================================================== */
00164 
00165 /*     .. Parameters .. */
00166 /*     .. */
00167 /*     .. Local Scalars .. */
00168 /*     .. */
00169 /*     .. External Functions .. */
00170 /*     .. */
00171 /*     .. External Subroutines .. */
00172 /*     .. */
00173 /*     .. Intrinsic Functions .. */
00174 /*     .. */
00175 /*     .. Statement Functions .. */
00176 /*     .. */
00177 /*     .. Statement Function definitions .. */
00178 /*     .. */
00179 /*     .. Executable Statements .. */
00180 
00181 /*     Test the input parameters. */
00182 
00183     /* Parameter adjustments */
00184     --ipiv;
00185     --ap;
00186 
00187     /* Function Body */
00188     *info = 0;
00189     upper = lsame_(uplo, "U");
00190     if (! upper && ! lsame_(uplo, "L")) {
00191         *info = -1;
00192     } else if (*n < 0) {
00193         *info = -2;
00194     }
00195     if (*info != 0) {
00196         i__1 = -(*info);
00197         xerbla_("CHPTRF", &i__1);
00198         return 0;
00199     }
00200 
00201 /*     Initialize ALPHA for use in choosing pivot block size. */
00202 
00203     alpha = (sqrt(17.f) + 1.f) / 8.f;
00204 
00205     if (upper) {
00206 
00207 /*        Factorize A as U*D*U' using the upper triangle of A */
00208 
00209 /*        K is the main loop index, decreasing from N to 1 in steps of */
00210 /*        1 or 2 */
00211 
00212         k = *n;
00213         kc = (*n - 1) * *n / 2 + 1;
00214 L10:
00215         knc = kc;
00216 
00217 /*        If K < 1, exit from loop */
00218 
00219         if (k < 1) {
00220             goto L110;
00221         }
00222         kstep = 1;
00223 
00224 /*        Determine rows and columns to be interchanged and whether */
00225 /*        a 1-by-1 or 2-by-2 pivot block will be used */
00226 
00227         i__1 = kc + k - 1;
00228         absakk = (r__1 = ap[i__1].r, dabs(r__1));
00229 
00230 /*        IMAX is the row-index of the largest off-diagonal element in */
00231 /*        column K, and COLMAX is its absolute value */
00232 
00233         if (k > 1) {
00234             i__1 = k - 1;
00235             imax = icamax_(&i__1, &ap[kc], &c__1);
00236             i__1 = kc + imax - 1;
00237             colmax = (r__1 = ap[i__1].r, dabs(r__1)) + (r__2 = r_imag(&ap[kc 
00238                     + imax - 1]), dabs(r__2));
00239         } else {
00240             colmax = 0.f;
00241         }
00242 
00243         if (dmax(absakk,colmax) == 0.f) {
00244 
00245 /*           Column K is zero: set INFO and continue */
00246 
00247             if (*info == 0) {
00248                 *info = k;
00249             }
00250             kp = k;
00251             i__1 = kc + k - 1;
00252             i__2 = kc + k - 1;
00253             r__1 = ap[i__2].r;
00254             ap[i__1].r = r__1, ap[i__1].i = 0.f;
00255         } else {
00256             if (absakk >= alpha * colmax) {
00257 
00258 /*              no interchange, use 1-by-1 pivot block */
00259 
00260                 kp = k;
00261             } else {
00262 
00263 /*              JMAX is the column-index of the largest off-diagonal */
00264 /*              element in row IMAX, and ROWMAX is its absolute value */
00265 
00266                 rowmax = 0.f;
00267                 jmax = imax;
00268                 kx = imax * (imax + 1) / 2 + imax;
00269                 i__1 = k;
00270                 for (j = imax + 1; j <= i__1; ++j) {
00271                     i__2 = kx;
00272                     if ((r__1 = ap[i__2].r, dabs(r__1)) + (r__2 = r_imag(&ap[
00273                             kx]), dabs(r__2)) > rowmax) {
00274                         i__2 = kx;
00275                         rowmax = (r__1 = ap[i__2].r, dabs(r__1)) + (r__2 = 
00276                                 r_imag(&ap[kx]), dabs(r__2));
00277                         jmax = j;
00278                     }
00279                     kx += j;
00280 /* L20: */
00281                 }
00282                 kpc = (imax - 1) * imax / 2 + 1;
00283                 if (imax > 1) {
00284                     i__1 = imax - 1;
00285                     jmax = icamax_(&i__1, &ap[kpc], &c__1);
00286 /* Computing MAX */
00287                     i__1 = kpc + jmax - 1;
00288                     r__3 = rowmax, r__4 = (r__1 = ap[i__1].r, dabs(r__1)) + (
00289                             r__2 = r_imag(&ap[kpc + jmax - 1]), dabs(r__2));
00290                     rowmax = dmax(r__3,r__4);
00291                 }
00292 
00293                 if (absakk >= alpha * colmax * (colmax / rowmax)) {
00294 
00295 /*                 no interchange, use 1-by-1 pivot block */
00296 
00297                     kp = k;
00298                 } else /* if(complicated condition) */ {
00299                     i__1 = kpc + imax - 1;
00300                     if ((r__1 = ap[i__1].r, dabs(r__1)) >= alpha * rowmax) {
00301 
00302 /*                 interchange rows and columns K and IMAX, use 1-by-1 */
00303 /*                 pivot block */
00304 
00305                         kp = imax;
00306                     } else {
00307 
00308 /*                 interchange rows and columns K-1 and IMAX, use 2-by-2 */
00309 /*                 pivot block */
00310 
00311                         kp = imax;
00312                         kstep = 2;
00313                     }
00314                 }
00315             }
00316 
00317             kk = k - kstep + 1;
00318             if (kstep == 2) {
00319                 knc = knc - k + 1;
00320             }
00321             if (kp != kk) {
00322 
00323 /*              Interchange rows and columns KK and KP in the leading */
00324 /*              submatrix A(1:k,1:k) */
00325 
00326                 i__1 = kp - 1;
00327                 cswap_(&i__1, &ap[knc], &c__1, &ap[kpc], &c__1);
00328                 kx = kpc + kp - 1;
00329                 i__1 = kk - 1;
00330                 for (j = kp + 1; j <= i__1; ++j) {
00331                     kx = kx + j - 1;
00332                     r_cnjg(&q__1, &ap[knc + j - 1]);
00333                     t.r = q__1.r, t.i = q__1.i;
00334                     i__2 = knc + j - 1;
00335                     r_cnjg(&q__1, &ap[kx]);
00336                     ap[i__2].r = q__1.r, ap[i__2].i = q__1.i;
00337                     i__2 = kx;
00338                     ap[i__2].r = t.r, ap[i__2].i = t.i;
00339 /* L30: */
00340                 }
00341                 i__1 = kx + kk - 1;
00342                 r_cnjg(&q__1, &ap[kx + kk - 1]);
00343                 ap[i__1].r = q__1.r, ap[i__1].i = q__1.i;
00344                 i__1 = knc + kk - 1;
00345                 r1 = ap[i__1].r;
00346                 i__1 = knc + kk - 1;
00347                 i__2 = kpc + kp - 1;
00348                 r__1 = ap[i__2].r;
00349                 ap[i__1].r = r__1, ap[i__1].i = 0.f;
00350                 i__1 = kpc + kp - 1;
00351                 ap[i__1].r = r1, ap[i__1].i = 0.f;
00352                 if (kstep == 2) {
00353                     i__1 = kc + k - 1;
00354                     i__2 = kc + k - 1;
00355                     r__1 = ap[i__2].r;
00356                     ap[i__1].r = r__1, ap[i__1].i = 0.f;
00357                     i__1 = kc + k - 2;
00358                     t.r = ap[i__1].r, t.i = ap[i__1].i;
00359                     i__1 = kc + k - 2;
00360                     i__2 = kc + kp - 1;
00361                     ap[i__1].r = ap[i__2].r, ap[i__1].i = ap[i__2].i;
00362                     i__1 = kc + kp - 1;
00363                     ap[i__1].r = t.r, ap[i__1].i = t.i;
00364                 }
00365             } else {
00366                 i__1 = kc + k - 1;
00367                 i__2 = kc + k - 1;
00368                 r__1 = ap[i__2].r;
00369                 ap[i__1].r = r__1, ap[i__1].i = 0.f;
00370                 if (kstep == 2) {
00371                     i__1 = kc - 1;
00372                     i__2 = kc - 1;
00373                     r__1 = ap[i__2].r;
00374                     ap[i__1].r = r__1, ap[i__1].i = 0.f;
00375                 }
00376             }
00377 
00378 /*           Update the leading submatrix */
00379 
00380             if (kstep == 1) {
00381 
00382 /*              1-by-1 pivot block D(k): column k now holds */
00383 
00384 /*              W(k) = U(k)*D(k) */
00385 
00386 /*              where U(k) is the k-th column of U */
00387 
00388 /*              Perform a rank-1 update of A(1:k-1,1:k-1) as */
00389 
00390 /*              A := A - U(k)*D(k)*U(k)' = A - W(k)*1/D(k)*W(k)' */
00391 
00392                 i__1 = kc + k - 1;
00393                 r1 = 1.f / ap[i__1].r;
00394                 i__1 = k - 1;
00395                 r__1 = -r1;
00396                 chpr_(uplo, &i__1, &r__1, &ap[kc], &c__1, &ap[1]);
00397 
00398 /*              Store U(k) in column k */
00399 
00400                 i__1 = k - 1;
00401                 csscal_(&i__1, &r1, &ap[kc], &c__1);
00402             } else {
00403 
00404 /*              2-by-2 pivot block D(k): columns k and k-1 now hold */
00405 
00406 /*              ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k) */
00407 
00408 /*              where U(k) and U(k-1) are the k-th and (k-1)-th columns */
00409 /*              of U */
00410 
00411 /*              Perform a rank-2 update of A(1:k-2,1:k-2) as */
00412 
00413 /*              A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )' */
00414 /*                 = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )' */
00415 
00416                 if (k > 2) {
00417 
00418                     i__1 = k - 1 + (k - 1) * k / 2;
00419                     r__1 = ap[i__1].r;
00420                     r__2 = r_imag(&ap[k - 1 + (k - 1) * k / 2]);
00421                     d__ = slapy2_(&r__1, &r__2);
00422                     i__1 = k - 1 + (k - 2) * (k - 1) / 2;
00423                     d22 = ap[i__1].r / d__;
00424                     i__1 = k + (k - 1) * k / 2;
00425                     d11 = ap[i__1].r / d__;
00426                     tt = 1.f / (d11 * d22 - 1.f);
00427                     i__1 = k - 1 + (k - 1) * k / 2;
00428                     q__1.r = ap[i__1].r / d__, q__1.i = ap[i__1].i / d__;
00429                     d12.r = q__1.r, d12.i = q__1.i;
00430                     d__ = tt / d__;
00431 
00432                     for (j = k - 2; j >= 1; --j) {
00433                         i__1 = j + (k - 2) * (k - 1) / 2;
00434                         q__3.r = d11 * ap[i__1].r, q__3.i = d11 * ap[i__1].i;
00435                         r_cnjg(&q__5, &d12);
00436                         i__2 = j + (k - 1) * k / 2;
00437                         q__4.r = q__5.r * ap[i__2].r - q__5.i * ap[i__2].i, 
00438                                 q__4.i = q__5.r * ap[i__2].i + q__5.i * ap[
00439                                 i__2].r;
00440                         q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
00441                         q__1.r = d__ * q__2.r, q__1.i = d__ * q__2.i;
00442                         wkm1.r = q__1.r, wkm1.i = q__1.i;
00443                         i__1 = j + (k - 1) * k / 2;
00444                         q__3.r = d22 * ap[i__1].r, q__3.i = d22 * ap[i__1].i;
00445                         i__2 = j + (k - 2) * (k - 1) / 2;
00446                         q__4.r = d12.r * ap[i__2].r - d12.i * ap[i__2].i, 
00447                                 q__4.i = d12.r * ap[i__2].i + d12.i * ap[i__2]
00448                                 .r;
00449                         q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
00450                         q__1.r = d__ * q__2.r, q__1.i = d__ * q__2.i;
00451                         wk.r = q__1.r, wk.i = q__1.i;
00452                         for (i__ = j; i__ >= 1; --i__) {
00453                             i__1 = i__ + (j - 1) * j / 2;
00454                             i__2 = i__ + (j - 1) * j / 2;
00455                             i__3 = i__ + (k - 1) * k / 2;
00456                             r_cnjg(&q__4, &wk);
00457                             q__3.r = ap[i__3].r * q__4.r - ap[i__3].i * 
00458                                     q__4.i, q__3.i = ap[i__3].r * q__4.i + ap[
00459                                     i__3].i * q__4.r;
00460                             q__2.r = ap[i__2].r - q__3.r, q__2.i = ap[i__2].i 
00461                                     - q__3.i;
00462                             i__4 = i__ + (k - 2) * (k - 1) / 2;
00463                             r_cnjg(&q__6, &wkm1);
00464                             q__5.r = ap[i__4].r * q__6.r - ap[i__4].i * 
00465                                     q__6.i, q__5.i = ap[i__4].r * q__6.i + ap[
00466                                     i__4].i * q__6.r;
00467                             q__1.r = q__2.r - q__5.r, q__1.i = q__2.i - 
00468                                     q__5.i;
00469                             ap[i__1].r = q__1.r, ap[i__1].i = q__1.i;
00470 /* L40: */
00471                         }
00472                         i__1 = j + (k - 1) * k / 2;
00473                         ap[i__1].r = wk.r, ap[i__1].i = wk.i;
00474                         i__1 = j + (k - 2) * (k - 1) / 2;
00475                         ap[i__1].r = wkm1.r, ap[i__1].i = wkm1.i;
00476                         i__1 = j + (j - 1) * j / 2;
00477                         i__2 = j + (j - 1) * j / 2;
00478                         r__1 = ap[i__2].r;
00479                         q__1.r = r__1, q__1.i = 0.f;
00480                         ap[i__1].r = q__1.r, ap[i__1].i = q__1.i;
00481 /* L50: */
00482                     }
00483 
00484                 }
00485 
00486             }
00487         }
00488 
00489 /*        Store details of the interchanges in IPIV */
00490 
00491         if (kstep == 1) {
00492             ipiv[k] = kp;
00493         } else {
00494             ipiv[k] = -kp;
00495             ipiv[k - 1] = -kp;
00496         }
00497 
00498 /*        Decrease K and return to the start of the main loop */
00499 
00500         k -= kstep;
00501         kc = knc - k;
00502         goto L10;
00503 
00504     } else {
00505 
00506 /*        Factorize A as L*D*L' using the lower triangle of A */
00507 
00508 /*        K is the main loop index, increasing from 1 to N in steps of */
00509 /*        1 or 2 */
00510 
00511         k = 1;
00512         kc = 1;
00513         npp = *n * (*n + 1) / 2;
00514 L60:
00515         knc = kc;
00516 
00517 /*        If K > N, exit from loop */
00518 
00519         if (k > *n) {
00520             goto L110;
00521         }
00522         kstep = 1;
00523 
00524 /*        Determine rows and columns to be interchanged and whether */
00525 /*        a 1-by-1 or 2-by-2 pivot block will be used */
00526 
00527         i__1 = kc;
00528         absakk = (r__1 = ap[i__1].r, dabs(r__1));
00529 
00530 /*        IMAX is the row-index of the largest off-diagonal element in */
00531 /*        column K, and COLMAX is its absolute value */
00532 
00533         if (k < *n) {
00534             i__1 = *n - k;
00535             imax = k + icamax_(&i__1, &ap[kc + 1], &c__1);
00536             i__1 = kc + imax - k;
00537             colmax = (r__1 = ap[i__1].r, dabs(r__1)) + (r__2 = r_imag(&ap[kc 
00538                     + imax - k]), dabs(r__2));
00539         } else {
00540             colmax = 0.f;
00541         }
00542 
00543         if (dmax(absakk,colmax) == 0.f) {
00544 
00545 /*           Column K is zero: set INFO and continue */
00546 
00547             if (*info == 0) {
00548                 *info = k;
00549             }
00550             kp = k;
00551             i__1 = kc;
00552             i__2 = kc;
00553             r__1 = ap[i__2].r;
00554             ap[i__1].r = r__1, ap[i__1].i = 0.f;
00555         } else {
00556             if (absakk >= alpha * colmax) {
00557 
00558 /*              no interchange, use 1-by-1 pivot block */
00559 
00560                 kp = k;
00561             } else {
00562 
00563 /*              JMAX is the column-index of the largest off-diagonal */
00564 /*              element in row IMAX, and ROWMAX is its absolute value */
00565 
00566                 rowmax = 0.f;
00567                 kx = kc + imax - k;
00568                 i__1 = imax - 1;
00569                 for (j = k; j <= i__1; ++j) {
00570                     i__2 = kx;
00571                     if ((r__1 = ap[i__2].r, dabs(r__1)) + (r__2 = r_imag(&ap[
00572                             kx]), dabs(r__2)) > rowmax) {
00573                         i__2 = kx;
00574                         rowmax = (r__1 = ap[i__2].r, dabs(r__1)) + (r__2 = 
00575                                 r_imag(&ap[kx]), dabs(r__2));
00576                         jmax = j;
00577                     }
00578                     kx = kx + *n - j;
00579 /* L70: */
00580                 }
00581                 kpc = npp - (*n - imax + 1) * (*n - imax + 2) / 2 + 1;
00582                 if (imax < *n) {
00583                     i__1 = *n - imax;
00584                     jmax = imax + icamax_(&i__1, &ap[kpc + 1], &c__1);
00585 /* Computing MAX */
00586                     i__1 = kpc + jmax - imax;
00587                     r__3 = rowmax, r__4 = (r__1 = ap[i__1].r, dabs(r__1)) + (
00588                             r__2 = r_imag(&ap[kpc + jmax - imax]), dabs(r__2))
00589                             ;
00590                     rowmax = dmax(r__3,r__4);
00591                 }
00592 
00593                 if (absakk >= alpha * colmax * (colmax / rowmax)) {
00594 
00595 /*                 no interchange, use 1-by-1 pivot block */
00596 
00597                     kp = k;
00598                 } else /* if(complicated condition) */ {
00599                     i__1 = kpc;
00600                     if ((r__1 = ap[i__1].r, dabs(r__1)) >= alpha * rowmax) {
00601 
00602 /*                 interchange rows and columns K and IMAX, use 1-by-1 */
00603 /*                 pivot block */
00604 
00605                         kp = imax;
00606                     } else {
00607 
00608 /*                 interchange rows and columns K+1 and IMAX, use 2-by-2 */
00609 /*                 pivot block */
00610 
00611                         kp = imax;
00612                         kstep = 2;
00613                     }
00614                 }
00615             }
00616 
00617             kk = k + kstep - 1;
00618             if (kstep == 2) {
00619                 knc = knc + *n - k + 1;
00620             }
00621             if (kp != kk) {
00622 
00623 /*              Interchange rows and columns KK and KP in the trailing */
00624 /*              submatrix A(k:n,k:n) */
00625 
00626                 if (kp < *n) {
00627                     i__1 = *n - kp;
00628                     cswap_(&i__1, &ap[knc + kp - kk + 1], &c__1, &ap[kpc + 1], 
00629                              &c__1);
00630                 }
00631                 kx = knc + kp - kk;
00632                 i__1 = kp - 1;
00633                 for (j = kk + 1; j <= i__1; ++j) {
00634                     kx = kx + *n - j + 1;
00635                     r_cnjg(&q__1, &ap[knc + j - kk]);
00636                     t.r = q__1.r, t.i = q__1.i;
00637                     i__2 = knc + j - kk;
00638                     r_cnjg(&q__1, &ap[kx]);
00639                     ap[i__2].r = q__1.r, ap[i__2].i = q__1.i;
00640                     i__2 = kx;
00641                     ap[i__2].r = t.r, ap[i__2].i = t.i;
00642 /* L80: */
00643                 }
00644                 i__1 = knc + kp - kk;
00645                 r_cnjg(&q__1, &ap[knc + kp - kk]);
00646                 ap[i__1].r = q__1.r, ap[i__1].i = q__1.i;
00647                 i__1 = knc;
00648                 r1 = ap[i__1].r;
00649                 i__1 = knc;
00650                 i__2 = kpc;
00651                 r__1 = ap[i__2].r;
00652                 ap[i__1].r = r__1, ap[i__1].i = 0.f;
00653                 i__1 = kpc;
00654                 ap[i__1].r = r1, ap[i__1].i = 0.f;
00655                 if (kstep == 2) {
00656                     i__1 = kc;
00657                     i__2 = kc;
00658                     r__1 = ap[i__2].r;
00659                     ap[i__1].r = r__1, ap[i__1].i = 0.f;
00660                     i__1 = kc + 1;
00661                     t.r = ap[i__1].r, t.i = ap[i__1].i;
00662                     i__1 = kc + 1;
00663                     i__2 = kc + kp - k;
00664                     ap[i__1].r = ap[i__2].r, ap[i__1].i = ap[i__2].i;
00665                     i__1 = kc + kp - k;
00666                     ap[i__1].r = t.r, ap[i__1].i = t.i;
00667                 }
00668             } else {
00669                 i__1 = kc;
00670                 i__2 = kc;
00671                 r__1 = ap[i__2].r;
00672                 ap[i__1].r = r__1, ap[i__1].i = 0.f;
00673                 if (kstep == 2) {
00674                     i__1 = knc;
00675                     i__2 = knc;
00676                     r__1 = ap[i__2].r;
00677                     ap[i__1].r = r__1, ap[i__1].i = 0.f;
00678                 }
00679             }
00680 
00681 /*           Update the trailing submatrix */
00682 
00683             if (kstep == 1) {
00684 
00685 /*              1-by-1 pivot block D(k): column k now holds */
00686 
00687 /*              W(k) = L(k)*D(k) */
00688 
00689 /*              where L(k) is the k-th column of L */
00690 
00691                 if (k < *n) {
00692 
00693 /*                 Perform a rank-1 update of A(k+1:n,k+1:n) as */
00694 
00695 /*                 A := A - L(k)*D(k)*L(k)' = A - W(k)*(1/D(k))*W(k)' */
00696 
00697                     i__1 = kc;
00698                     r1 = 1.f / ap[i__1].r;
00699                     i__1 = *n - k;
00700                     r__1 = -r1;
00701                     chpr_(uplo, &i__1, &r__1, &ap[kc + 1], &c__1, &ap[kc + *n 
00702                             - k + 1]);
00703 
00704 /*                 Store L(k) in column K */
00705 
00706                     i__1 = *n - k;
00707                     csscal_(&i__1, &r1, &ap[kc + 1], &c__1);
00708                 }
00709             } else {
00710 
00711 /*              2-by-2 pivot block D(k): columns K and K+1 now hold */
00712 
00713 /*              ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k) */
00714 
00715 /*              where L(k) and L(k+1) are the k-th and (k+1)-th columns */
00716 /*              of L */
00717 
00718                 if (k < *n - 1) {
00719 
00720 /*                 Perform a rank-2 update of A(k+2:n,k+2:n) as */
00721 
00722 /*                 A := A - ( L(k) L(k+1) )*D(k)*( L(k) L(k+1) )' */
00723 /*                    = A - ( W(k) W(k+1) )*inv(D(k))*( W(k) W(k+1) )' */
00724 
00725 /*                 where L(k) and L(k+1) are the k-th and (k+1)-th */
00726 /*                 columns of L */
00727 
00728                     i__1 = k + 1 + (k - 1) * ((*n << 1) - k) / 2;
00729                     r__1 = ap[i__1].r;
00730                     r__2 = r_imag(&ap[k + 1 + (k - 1) * ((*n << 1) - k) / 2]);
00731                     d__ = slapy2_(&r__1, &r__2);
00732                     i__1 = k + 1 + k * ((*n << 1) - k - 1) / 2;
00733                     d11 = ap[i__1].r / d__;
00734                     i__1 = k + (k - 1) * ((*n << 1) - k) / 2;
00735                     d22 = ap[i__1].r / d__;
00736                     tt = 1.f / (d11 * d22 - 1.f);
00737                     i__1 = k + 1 + (k - 1) * ((*n << 1) - k) / 2;
00738                     q__1.r = ap[i__1].r / d__, q__1.i = ap[i__1].i / d__;
00739                     d21.r = q__1.r, d21.i = q__1.i;
00740                     d__ = tt / d__;
00741 
00742                     i__1 = *n;
00743                     for (j = k + 2; j <= i__1; ++j) {
00744                         i__2 = j + (k - 1) * ((*n << 1) - k) / 2;
00745                         q__3.r = d11 * ap[i__2].r, q__3.i = d11 * ap[i__2].i;
00746                         i__3 = j + k * ((*n << 1) - k - 1) / 2;
00747                         q__4.r = d21.r * ap[i__3].r - d21.i * ap[i__3].i, 
00748                                 q__4.i = d21.r * ap[i__3].i + d21.i * ap[i__3]
00749                                 .r;
00750                         q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
00751                         q__1.r = d__ * q__2.r, q__1.i = d__ * q__2.i;
00752                         wk.r = q__1.r, wk.i = q__1.i;
00753                         i__2 = j + k * ((*n << 1) - k - 1) / 2;
00754                         q__3.r = d22 * ap[i__2].r, q__3.i = d22 * ap[i__2].i;
00755                         r_cnjg(&q__5, &d21);
00756                         i__3 = j + (k - 1) * ((*n << 1) - k) / 2;
00757                         q__4.r = q__5.r * ap[i__3].r - q__5.i * ap[i__3].i, 
00758                                 q__4.i = q__5.r * ap[i__3].i + q__5.i * ap[
00759                                 i__3].r;
00760                         q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
00761                         q__1.r = d__ * q__2.r, q__1.i = d__ * q__2.i;
00762                         wkp1.r = q__1.r, wkp1.i = q__1.i;
00763                         i__2 = *n;
00764                         for (i__ = j; i__ <= i__2; ++i__) {
00765                             i__3 = i__ + (j - 1) * ((*n << 1) - j) / 2;
00766                             i__4 = i__ + (j - 1) * ((*n << 1) - j) / 2;
00767                             i__5 = i__ + (k - 1) * ((*n << 1) - k) / 2;
00768                             r_cnjg(&q__4, &wk);
00769                             q__3.r = ap[i__5].r * q__4.r - ap[i__5].i * 
00770                                     q__4.i, q__3.i = ap[i__5].r * q__4.i + ap[
00771                                     i__5].i * q__4.r;
00772                             q__2.r = ap[i__4].r - q__3.r, q__2.i = ap[i__4].i 
00773                                     - q__3.i;
00774                             i__6 = i__ + k * ((*n << 1) - k - 1) / 2;
00775                             r_cnjg(&q__6, &wkp1);
00776                             q__5.r = ap[i__6].r * q__6.r - ap[i__6].i * 
00777                                     q__6.i, q__5.i = ap[i__6].r * q__6.i + ap[
00778                                     i__6].i * q__6.r;
00779                             q__1.r = q__2.r - q__5.r, q__1.i = q__2.i - 
00780                                     q__5.i;
00781                             ap[i__3].r = q__1.r, ap[i__3].i = q__1.i;
00782 /* L90: */
00783                         }
00784                         i__2 = j + (k - 1) * ((*n << 1) - k) / 2;
00785                         ap[i__2].r = wk.r, ap[i__2].i = wk.i;
00786                         i__2 = j + k * ((*n << 1) - k - 1) / 2;
00787                         ap[i__2].r = wkp1.r, ap[i__2].i = wkp1.i;
00788                         i__2 = j + (j - 1) * ((*n << 1) - j) / 2;
00789                         i__3 = j + (j - 1) * ((*n << 1) - j) / 2;
00790                         r__1 = ap[i__3].r;
00791                         q__1.r = r__1, q__1.i = 0.f;
00792                         ap[i__2].r = q__1.r, ap[i__2].i = q__1.i;
00793 /* L100: */
00794                     }
00795                 }
00796             }
00797         }
00798 
00799 /*        Store details of the interchanges in IPIV */
00800 
00801         if (kstep == 1) {
00802             ipiv[k] = kp;
00803         } else {
00804             ipiv[k] = -kp;
00805             ipiv[k + 1] = -kp;
00806         }
00807 
00808 /*        Increase K and return to the start of the main loop */
00809 
00810         k += kstep;
00811         kc = knc + *n - k + 2;
00812         goto L60;
00813 
00814     }
00815 
00816 L110:
00817     return 0;
00818 
00819 /*     End of CHPTRF */
00820 
00821 } /* chptrf_ */


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