LAPACK 3.3.0

zsptrf.f

Go to the documentation of this file.
00001       SUBROUTINE ZSPTRF( UPLO, N, AP, IPIV, INFO )
00002 *
00003 *  -- LAPACK routine (version 3.2) --
00004 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
00005 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
00006 *     November 2006
00007 *
00008 *     .. Scalar Arguments ..
00009       CHARACTER          UPLO
00010       INTEGER            INFO, N
00011 *     ..
00012 *     .. Array Arguments ..
00013       INTEGER            IPIV( * )
00014       COMPLEX*16         AP( * )
00015 *     ..
00016 *
00017 *  Purpose
00018 *  =======
00019 *
00020 *  ZSPTRF computes the factorization of a complex symmetric matrix A
00021 *  stored in packed format using the Bunch-Kaufman diagonal pivoting
00022 *  method:
00023 *
00024 *     A = U*D*U**T  or  A = L*D*L**T
00025 *
00026 *  where U (or L) is a product of permutation and unit upper (lower)
00027 *  triangular matrices, and D is symmetric and block diagonal with
00028 *  1-by-1 and 2-by-2 diagonal blocks.
00029 *
00030 *  Arguments
00031 *  =========
00032 *
00033 *  UPLO    (input) CHARACTER*1
00034 *          = 'U':  Upper triangle of A is stored;
00035 *          = 'L':  Lower triangle of A is stored.
00036 *
00037 *  N       (input) INTEGER
00038 *          The order of the matrix A.  N >= 0.
00039 *
00040 *  AP      (input/output) COMPLEX*16 array, dimension (N*(N+1)/2)
00041 *          On entry, the upper or lower triangle of the symmetric matrix
00042 *          A, packed columnwise in a linear array.  The j-th column of A
00043 *          is stored in the array AP as follows:
00044 *          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
00045 *          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
00046 *
00047 *          On exit, the block diagonal matrix D and the multipliers used
00048 *          to obtain the factor U or L, stored as a packed triangular
00049 *          matrix overwriting A (see below for further details).
00050 *
00051 *  IPIV    (output) INTEGER array, dimension (N)
00052 *          Details of the interchanges and the block structure of D.
00053 *          If IPIV(k) > 0, then rows and columns k and IPIV(k) were
00054 *          interchanged and D(k,k) is a 1-by-1 diagonal block.
00055 *          If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and
00056 *          columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k)
00057 *          is a 2-by-2 diagonal block.  If UPLO = 'L' and IPIV(k) =
00058 *          IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were
00059 *          interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block.
00060 *
00061 *  INFO    (output) INTEGER
00062 *          = 0: successful exit
00063 *          < 0: if INFO = -i, the i-th argument had an illegal value
00064 *          > 0: if INFO = i, D(i,i) is exactly zero.  The factorization
00065 *               has been completed, but the block diagonal matrix D is
00066 *               exactly singular, and division by zero will occur if it
00067 *               is used to solve a system of equations.
00068 *
00069 *  Further Details
00070 *  ===============
00071 *
00072 *  5-96 - Based on modifications by J. Lewis, Boeing Computer Services
00073 *         Company
00074 *
00075 *  If UPLO = 'U', then A = U*D*U', where
00076 *     U = P(n)*U(n)* ... *P(k)U(k)* ...,
00077 *  i.e., U is a product of terms P(k)*U(k), where k decreases from n to
00078 *  1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
00079 *  and 2-by-2 diagonal blocks D(k).  P(k) is a permutation matrix as
00080 *  defined by IPIV(k), and U(k) is a unit upper triangular matrix, such
00081 *  that if the diagonal block D(k) is of order s (s = 1 or 2), then
00082 *
00083 *             (   I    v    0   )   k-s
00084 *     U(k) =  (   0    I    0   )   s
00085 *             (   0    0    I   )   n-k
00086 *                k-s   s   n-k
00087 *
00088 *  If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k).
00089 *  If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k),
00090 *  and A(k,k), and v overwrites A(1:k-2,k-1:k).
00091 *
00092 *  If UPLO = 'L', then A = L*D*L', where
00093 *     L = P(1)*L(1)* ... *P(k)*L(k)* ...,
00094 *  i.e., L is a product of terms P(k)*L(k), where k increases from 1 to
00095 *  n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
00096 *  and 2-by-2 diagonal blocks D(k).  P(k) is a permutation matrix as
00097 *  defined by IPIV(k), and L(k) is a unit lower triangular matrix, such
00098 *  that if the diagonal block D(k) is of order s (s = 1 or 2), then
00099 *
00100 *             (   I    0     0   )  k-1
00101 *     L(k) =  (   0    I     0   )  s
00102 *             (   0    v     I   )  n-k-s+1
00103 *                k-1   s  n-k-s+1
00104 *
00105 *  If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k).
00106 *  If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k),
00107 *  and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1).
00108 *
00109 *  =====================================================================
00110 *
00111 *     .. Parameters ..
00112       DOUBLE PRECISION   ZERO, ONE
00113       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
00114       DOUBLE PRECISION   EIGHT, SEVTEN
00115       PARAMETER          ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 )
00116       COMPLEX*16         CONE
00117       PARAMETER          ( CONE = ( 1.0D+0, 0.0D+0 ) )
00118 *     ..
00119 *     .. Local Scalars ..
00120       LOGICAL            UPPER
00121       INTEGER            I, IMAX, J, JMAX, K, KC, KK, KNC, KP, KPC,
00122      $                   KSTEP, KX, NPP
00123       DOUBLE PRECISION   ABSAKK, ALPHA, COLMAX, ROWMAX
00124       COMPLEX*16         D11, D12, D21, D22, R1, T, WK, WKM1, WKP1, ZDUM
00125 *     ..
00126 *     .. External Functions ..
00127       LOGICAL            LSAME
00128       INTEGER            IZAMAX
00129       EXTERNAL           LSAME, IZAMAX
00130 *     ..
00131 *     .. External Subroutines ..
00132       EXTERNAL           XERBLA, ZSCAL, ZSPR, ZSWAP
00133 *     ..
00134 *     .. Intrinsic Functions ..
00135       INTRINSIC          ABS, DBLE, DIMAG, MAX, SQRT
00136 *     ..
00137 *     .. Statement Functions ..
00138       DOUBLE PRECISION   CABS1
00139 *     ..
00140 *     .. Statement Function definitions ..
00141       CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
00142 *     ..
00143 *     .. Executable Statements ..
00144 *
00145 *     Test the input parameters.
00146 *
00147       INFO = 0
00148       UPPER = LSAME( UPLO, 'U' )
00149       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
00150          INFO = -1
00151       ELSE IF( N.LT.0 ) THEN
00152          INFO = -2
00153       END IF
00154       IF( INFO.NE.0 ) THEN
00155          CALL XERBLA( 'ZSPTRF', -INFO )
00156          RETURN
00157       END IF
00158 *
00159 *     Initialize ALPHA for use in choosing pivot block size.
00160 *
00161       ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT
00162 *
00163       IF( UPPER ) THEN
00164 *
00165 *        Factorize A as U*D*U' using the upper triangle of A
00166 *
00167 *        K is the main loop index, decreasing from N to 1 in steps of
00168 *        1 or 2
00169 *
00170          K = N
00171          KC = ( N-1 )*N / 2 + 1
00172    10    CONTINUE
00173          KNC = KC
00174 *
00175 *        If K < 1, exit from loop
00176 *
00177          IF( K.LT.1 )
00178      $      GO TO 110
00179          KSTEP = 1
00180 *
00181 *        Determine rows and columns to be interchanged and whether
00182 *        a 1-by-1 or 2-by-2 pivot block will be used
00183 *
00184          ABSAKK = CABS1( AP( KC+K-1 ) )
00185 *
00186 *        IMAX is the row-index of the largest off-diagonal element in
00187 *        column K, and COLMAX is its absolute value
00188 *
00189          IF( K.GT.1 ) THEN
00190             IMAX = IZAMAX( K-1, AP( KC ), 1 )
00191             COLMAX = CABS1( AP( KC+IMAX-1 ) )
00192          ELSE
00193             COLMAX = ZERO
00194          END IF
00195 *
00196          IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
00197 *
00198 *           Column K is zero: set INFO and continue
00199 *
00200             IF( INFO.EQ.0 )
00201      $         INFO = K
00202             KP = K
00203          ELSE
00204             IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
00205 *
00206 *              no interchange, use 1-by-1 pivot block
00207 *
00208                KP = K
00209             ELSE
00210 *
00211 *              JMAX is the column-index of the largest off-diagonal
00212 *              element in row IMAX, and ROWMAX is its absolute value
00213 *
00214                ROWMAX = ZERO
00215                JMAX = IMAX
00216                KX = IMAX*( IMAX+1 ) / 2 + IMAX
00217                DO 20 J = IMAX + 1, K
00218                   IF( CABS1( AP( KX ) ).GT.ROWMAX ) THEN
00219                      ROWMAX = CABS1( AP( KX ) )
00220                      JMAX = J
00221                   END IF
00222                   KX = KX + J
00223    20          CONTINUE
00224                KPC = ( IMAX-1 )*IMAX / 2 + 1
00225                IF( IMAX.GT.1 ) THEN
00226                   JMAX = IZAMAX( IMAX-1, AP( KPC ), 1 )
00227                   ROWMAX = MAX( ROWMAX, CABS1( AP( KPC+JMAX-1 ) ) )
00228                END IF
00229 *
00230                IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
00231 *
00232 *                 no interchange, use 1-by-1 pivot block
00233 *
00234                   KP = K
00235                ELSE IF( CABS1( AP( KPC+IMAX-1 ) ).GE.ALPHA*ROWMAX ) THEN
00236 *
00237 *                 interchange rows and columns K and IMAX, use 1-by-1
00238 *                 pivot block
00239 *
00240                   KP = IMAX
00241                ELSE
00242 *
00243 *                 interchange rows and columns K-1 and IMAX, use 2-by-2
00244 *                 pivot block
00245 *
00246                   KP = IMAX
00247                   KSTEP = 2
00248                END IF
00249             END IF
00250 *
00251             KK = K - KSTEP + 1
00252             IF( KSTEP.EQ.2 )
00253      $         KNC = KNC - K + 1
00254             IF( KP.NE.KK ) THEN
00255 *
00256 *              Interchange rows and columns KK and KP in the leading
00257 *              submatrix A(1:k,1:k)
00258 *
00259                CALL ZSWAP( KP-1, AP( KNC ), 1, AP( KPC ), 1 )
00260                KX = KPC + KP - 1
00261                DO 30 J = KP + 1, KK - 1
00262                   KX = KX + J - 1
00263                   T = AP( KNC+J-1 )
00264                   AP( KNC+J-1 ) = AP( KX )
00265                   AP( KX ) = T
00266    30          CONTINUE
00267                T = AP( KNC+KK-1 )
00268                AP( KNC+KK-1 ) = AP( KPC+KP-1 )
00269                AP( KPC+KP-1 ) = T
00270                IF( KSTEP.EQ.2 ) THEN
00271                   T = AP( KC+K-2 )
00272                   AP( KC+K-2 ) = AP( KC+KP-1 )
00273                   AP( KC+KP-1 ) = T
00274                END IF
00275             END IF
00276 *
00277 *           Update the leading submatrix
00278 *
00279             IF( KSTEP.EQ.1 ) THEN
00280 *
00281 *              1-by-1 pivot block D(k): column k now holds
00282 *
00283 *              W(k) = U(k)*D(k)
00284 *
00285 *              where U(k) is the k-th column of U
00286 *
00287 *              Perform a rank-1 update of A(1:k-1,1:k-1) as
00288 *
00289 *              A := A - U(k)*D(k)*U(k)' = A - W(k)*1/D(k)*W(k)'
00290 *
00291                R1 = CONE / AP( KC+K-1 )
00292                CALL ZSPR( UPLO, K-1, -R1, AP( KC ), 1, AP )
00293 *
00294 *              Store U(k) in column k
00295 *
00296                CALL ZSCAL( K-1, R1, AP( KC ), 1 )
00297             ELSE
00298 *
00299 *              2-by-2 pivot block D(k): columns k and k-1 now hold
00300 *
00301 *              ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
00302 *
00303 *              where U(k) and U(k-1) are the k-th and (k-1)-th columns
00304 *              of U
00305 *
00306 *              Perform a rank-2 update of A(1:k-2,1:k-2) as
00307 *
00308 *              A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )'
00309 *                 = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )'
00310 *
00311                IF( K.GT.2 ) THEN
00312 *
00313                   D12 = AP( K-1+( K-1 )*K / 2 )
00314                   D22 = AP( K-1+( K-2 )*( K-1 ) / 2 ) / D12
00315                   D11 = AP( K+( K-1 )*K / 2 ) / D12
00316                   T = CONE / ( D11*D22-CONE )
00317                   D12 = T / D12
00318 *
00319                   DO 50 J = K - 2, 1, -1
00320                      WKM1 = D12*( D11*AP( J+( K-2 )*( K-1 ) / 2 )-
00321      $                      AP( J+( K-1 )*K / 2 ) )
00322                      WK = D12*( D22*AP( J+( K-1 )*K / 2 )-
00323      $                    AP( J+( K-2 )*( K-1 ) / 2 ) )
00324                      DO 40 I = J, 1, -1
00325                         AP( I+( J-1 )*J / 2 ) = AP( I+( J-1 )*J / 2 ) -
00326      $                     AP( I+( K-1 )*K / 2 )*WK -
00327      $                     AP( I+( K-2 )*( K-1 ) / 2 )*WKM1
00328    40                CONTINUE
00329                      AP( J+( K-1 )*K / 2 ) = WK
00330                      AP( J+( K-2 )*( K-1 ) / 2 ) = WKM1
00331    50             CONTINUE
00332 *
00333                END IF
00334             END IF
00335          END IF
00336 *
00337 *        Store details of the interchanges in IPIV
00338 *
00339          IF( KSTEP.EQ.1 ) THEN
00340             IPIV( K ) = KP
00341          ELSE
00342             IPIV( K ) = -KP
00343             IPIV( K-1 ) = -KP
00344          END IF
00345 *
00346 *        Decrease K and return to the start of the main loop
00347 *
00348          K = K - KSTEP
00349          KC = KNC - K
00350          GO TO 10
00351 *
00352       ELSE
00353 *
00354 *        Factorize A as L*D*L' using the lower triangle of A
00355 *
00356 *        K is the main loop index, increasing from 1 to N in steps of
00357 *        1 or 2
00358 *
00359          K = 1
00360          KC = 1
00361          NPP = N*( N+1 ) / 2
00362    60    CONTINUE
00363          KNC = KC
00364 *
00365 *        If K > N, exit from loop
00366 *
00367          IF( K.GT.N )
00368      $      GO TO 110
00369          KSTEP = 1
00370 *
00371 *        Determine rows and columns to be interchanged and whether
00372 *        a 1-by-1 or 2-by-2 pivot block will be used
00373 *
00374          ABSAKK = CABS1( AP( KC ) )
00375 *
00376 *        IMAX is the row-index of the largest off-diagonal element in
00377 *        column K, and COLMAX is its absolute value
00378 *
00379          IF( K.LT.N ) THEN
00380             IMAX = K + IZAMAX( N-K, AP( KC+1 ), 1 )
00381             COLMAX = CABS1( AP( KC+IMAX-K ) )
00382          ELSE
00383             COLMAX = ZERO
00384          END IF
00385 *
00386          IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
00387 *
00388 *           Column K is zero: set INFO and continue
00389 *
00390             IF( INFO.EQ.0 )
00391      $         INFO = K
00392             KP = K
00393          ELSE
00394             IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
00395 *
00396 *              no interchange, use 1-by-1 pivot block
00397 *
00398                KP = K
00399             ELSE
00400 *
00401 *              JMAX is the column-index of the largest off-diagonal
00402 *              element in row IMAX, and ROWMAX is its absolute value
00403 *
00404                ROWMAX = ZERO
00405                KX = KC + IMAX - K
00406                DO 70 J = K, IMAX - 1
00407                   IF( CABS1( AP( KX ) ).GT.ROWMAX ) THEN
00408                      ROWMAX = CABS1( AP( KX ) )
00409                      JMAX = J
00410                   END IF
00411                   KX = KX + N - J
00412    70          CONTINUE
00413                KPC = NPP - ( N-IMAX+1 )*( N-IMAX+2 ) / 2 + 1
00414                IF( IMAX.LT.N ) THEN
00415                   JMAX = IMAX + IZAMAX( N-IMAX, AP( KPC+1 ), 1 )
00416                   ROWMAX = MAX( ROWMAX, CABS1( AP( KPC+JMAX-IMAX ) ) )
00417                END IF
00418 *
00419                IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
00420 *
00421 *                 no interchange, use 1-by-1 pivot block
00422 *
00423                   KP = K
00424                ELSE IF( CABS1( AP( KPC ) ).GE.ALPHA*ROWMAX ) THEN
00425 *
00426 *                 interchange rows and columns K and IMAX, use 1-by-1
00427 *                 pivot block
00428 *
00429                   KP = IMAX
00430                ELSE
00431 *
00432 *                 interchange rows and columns K+1 and IMAX, use 2-by-2
00433 *                 pivot block
00434 *
00435                   KP = IMAX
00436                   KSTEP = 2
00437                END IF
00438             END IF
00439 *
00440             KK = K + KSTEP - 1
00441             IF( KSTEP.EQ.2 )
00442      $         KNC = KNC + N - K + 1
00443             IF( KP.NE.KK ) THEN
00444 *
00445 *              Interchange rows and columns KK and KP in the trailing
00446 *              submatrix A(k:n,k:n)
00447 *
00448                IF( KP.LT.N )
00449      $            CALL ZSWAP( N-KP, AP( KNC+KP-KK+1 ), 1, AP( KPC+1 ),
00450      $                        1 )
00451                KX = KNC + KP - KK
00452                DO 80 J = KK + 1, KP - 1
00453                   KX = KX + N - J + 1
00454                   T = AP( KNC+J-KK )
00455                   AP( KNC+J-KK ) = AP( KX )
00456                   AP( KX ) = T
00457    80          CONTINUE
00458                T = AP( KNC )
00459                AP( KNC ) = AP( KPC )
00460                AP( KPC ) = T
00461                IF( KSTEP.EQ.2 ) THEN
00462                   T = AP( KC+1 )
00463                   AP( KC+1 ) = AP( KC+KP-K )
00464                   AP( KC+KP-K ) = T
00465                END IF
00466             END IF
00467 *
00468 *           Update the trailing submatrix
00469 *
00470             IF( KSTEP.EQ.1 ) THEN
00471 *
00472 *              1-by-1 pivot block D(k): column k now holds
00473 *
00474 *              W(k) = L(k)*D(k)
00475 *
00476 *              where L(k) is the k-th column of L
00477 *
00478                IF( K.LT.N ) THEN
00479 *
00480 *                 Perform a rank-1 update of A(k+1:n,k+1:n) as
00481 *
00482 *                 A := A - L(k)*D(k)*L(k)' = A - W(k)*(1/D(k))*W(k)'
00483 *
00484                   R1 = CONE / AP( KC )
00485                   CALL ZSPR( UPLO, N-K, -R1, AP( KC+1 ), 1,
00486      $                       AP( KC+N-K+1 ) )
00487 *
00488 *                 Store L(k) in column K
00489 *
00490                   CALL ZSCAL( N-K, R1, AP( KC+1 ), 1 )
00491                END IF
00492             ELSE
00493 *
00494 *              2-by-2 pivot block D(k): columns K and K+1 now hold
00495 *
00496 *              ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k)
00497 *
00498 *              where L(k) and L(k+1) are the k-th and (k+1)-th columns
00499 *              of L
00500 *
00501                IF( K.LT.N-1 ) THEN
00502 *
00503 *                 Perform a rank-2 update of A(k+2:n,k+2:n) as
00504 *
00505 *                 A := A - ( L(k) L(k+1) )*D(k)*( L(k) L(k+1) )'
00506 *                    = A - ( W(k) W(k+1) )*inv(D(k))*( W(k) W(k+1) )'
00507 *
00508 *                 where L(k) and L(k+1) are the k-th and (k+1)-th
00509 *                 columns of L
00510 *
00511                   D21 = AP( K+1+( K-1 )*( 2*N-K ) / 2 )
00512                   D11 = AP( K+1+K*( 2*N-K-1 ) / 2 ) / D21
00513                   D22 = AP( K+( K-1 )*( 2*N-K ) / 2 ) / D21
00514                   T = CONE / ( D11*D22-CONE )
00515                   D21 = T / D21
00516 *
00517                   DO 100 J = K + 2, N
00518                      WK = D21*( D11*AP( J+( K-1 )*( 2*N-K ) / 2 )-
00519      $                    AP( J+K*( 2*N-K-1 ) / 2 ) )
00520                      WKP1 = D21*( D22*AP( J+K*( 2*N-K-1 ) / 2 )-
00521      $                      AP( J+( K-1 )*( 2*N-K ) / 2 ) )
00522                      DO 90 I = J, N
00523                         AP( I+( J-1 )*( 2*N-J ) / 2 ) = AP( I+( J-1 )*
00524      $                     ( 2*N-J ) / 2 ) - AP( I+( K-1 )*( 2*N-K ) /
00525      $                     2 )*WK - AP( I+K*( 2*N-K-1 ) / 2 )*WKP1
00526    90                CONTINUE
00527                      AP( J+( K-1 )*( 2*N-K ) / 2 ) = WK
00528                      AP( J+K*( 2*N-K-1 ) / 2 ) = WKP1
00529   100             CONTINUE
00530                END IF
00531             END IF
00532          END IF
00533 *
00534 *        Store details of the interchanges in IPIV
00535 *
00536          IF( KSTEP.EQ.1 ) THEN
00537             IPIV( K ) = KP
00538          ELSE
00539             IPIV( K ) = -KP
00540             IPIV( K+1 ) = -KP
00541          END IF
00542 *
00543 *        Increase K and return to the start of the main loop
00544 *
00545          K = K + KSTEP
00546          KC = KNC + N - K + 2
00547          GO TO 60
00548 *
00549       END IF
00550 *
00551   110 CONTINUE
00552       RETURN
00553 *
00554 *     End of ZSPTRF
00555 *
00556       END
 All Files Functions