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


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