LAPACK 3.3.1
Linear Algebra PACKage

ssptrf.f

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