LAPACK 3.3.0
|
00001 SUBROUTINE SSPTRD( UPLO, N, AP, D, E, TAU, 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 REAL AP( * ), D( * ), E( * ), TAU( * ) 00014 * .. 00015 * 00016 * Purpose 00017 * ======= 00018 * 00019 * SSPTRD reduces a real symmetric matrix A stored in packed form to 00020 * symmetric tridiagonal form T by an orthogonal similarity 00021 * transformation: Q**T * A * Q = T. 00022 * 00023 * Arguments 00024 * ========= 00025 * 00026 * UPLO (input) CHARACTER*1 00027 * = 'U': Upper triangle of A is stored; 00028 * = 'L': Lower triangle of A is stored. 00029 * 00030 * N (input) INTEGER 00031 * The order of the matrix A. N >= 0. 00032 * 00033 * AP (input/output) REAL array, dimension (N*(N+1)/2) 00034 * On entry, the upper or lower triangle of the symmetric matrix 00035 * A, packed columnwise in a linear array. The j-th column of A 00036 * is stored in the array AP as follows: 00037 * if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; 00038 * if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. 00039 * On exit, if UPLO = 'U', the diagonal and first superdiagonal 00040 * of A are overwritten by the corresponding elements of the 00041 * tridiagonal matrix T, and the elements above the first 00042 * superdiagonal, with the array TAU, represent the orthogonal 00043 * matrix Q as a product of elementary reflectors; if UPLO 00044 * = 'L', the diagonal and first subdiagonal of A are over- 00045 * written by the corresponding elements of the tridiagonal 00046 * matrix T, and the elements below the first subdiagonal, with 00047 * the array TAU, represent the orthogonal matrix Q as a product 00048 * of elementary reflectors. See Further Details. 00049 * 00050 * D (output) REAL array, dimension (N) 00051 * The diagonal elements of the tridiagonal matrix T: 00052 * D(i) = A(i,i). 00053 * 00054 * E (output) REAL array, dimension (N-1) 00055 * The off-diagonal elements of the tridiagonal matrix T: 00056 * E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'. 00057 * 00058 * TAU (output) REAL array, dimension (N-1) 00059 * The scalar factors of the elementary reflectors (see Further 00060 * Details). 00061 * 00062 * INFO (output) INTEGER 00063 * = 0: successful exit 00064 * < 0: if INFO = -i, the i-th argument had an illegal value 00065 * 00066 * Further Details 00067 * =============== 00068 * 00069 * If UPLO = 'U', the matrix Q is represented as a product of elementary 00070 * reflectors 00071 * 00072 * Q = H(n-1) . . . H(2) H(1). 00073 * 00074 * Each H(i) has the form 00075 * 00076 * H(i) = I - tau * v * v' 00077 * 00078 * where tau is a real scalar, and v is a real vector with 00079 * v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in AP, 00080 * overwriting A(1:i-1,i+1), and tau is stored in TAU(i). 00081 * 00082 * If UPLO = 'L', the matrix Q is represented as a product of elementary 00083 * reflectors 00084 * 00085 * Q = H(1) H(2) . . . H(n-1). 00086 * 00087 * Each H(i) has the form 00088 * 00089 * H(i) = I - tau * v * v' 00090 * 00091 * where tau is a real scalar, and v is a real vector with 00092 * v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in AP, 00093 * overwriting A(i+2:n,i), and tau is stored in TAU(i). 00094 * 00095 * ===================================================================== 00096 * 00097 * .. Parameters .. 00098 REAL ONE, ZERO, HALF 00099 PARAMETER ( ONE = 1.0, ZERO = 0.0, HALF = 1.0 / 2.0 ) 00100 * .. 00101 * .. Local Scalars .. 00102 LOGICAL UPPER 00103 INTEGER I, I1, I1I1, II 00104 REAL ALPHA, TAUI 00105 * .. 00106 * .. External Subroutines .. 00107 EXTERNAL SAXPY, SLARFG, SSPMV, SSPR2, XERBLA 00108 * .. 00109 * .. External Functions .. 00110 LOGICAL LSAME 00111 REAL SDOT 00112 EXTERNAL LSAME, SDOT 00113 * .. 00114 * .. Executable Statements .. 00115 * 00116 * Test the input parameters 00117 * 00118 INFO = 0 00119 UPPER = LSAME( UPLO, 'U' ) 00120 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN 00121 INFO = -1 00122 ELSE IF( N.LT.0 ) THEN 00123 INFO = -2 00124 END IF 00125 IF( INFO.NE.0 ) THEN 00126 CALL XERBLA( 'SSPTRD', -INFO ) 00127 RETURN 00128 END IF 00129 * 00130 * Quick return if possible 00131 * 00132 IF( N.LE.0 ) 00133 $ RETURN 00134 * 00135 IF( UPPER ) THEN 00136 * 00137 * Reduce the upper triangle of A. 00138 * I1 is the index in AP of A(1,I+1). 00139 * 00140 I1 = N*( N-1 ) / 2 + 1 00141 DO 10 I = N - 1, 1, -1 00142 * 00143 * Generate elementary reflector H(i) = I - tau * v * v' 00144 * to annihilate A(1:i-1,i+1) 00145 * 00146 CALL SLARFG( I, AP( I1+I-1 ), AP( I1 ), 1, TAUI ) 00147 E( I ) = AP( I1+I-1 ) 00148 * 00149 IF( TAUI.NE.ZERO ) THEN 00150 * 00151 * Apply H(i) from both sides to A(1:i,1:i) 00152 * 00153 AP( I1+I-1 ) = ONE 00154 * 00155 * Compute y := tau * A * v storing y in TAU(1:i) 00156 * 00157 CALL SSPMV( UPLO, I, TAUI, AP, AP( I1 ), 1, ZERO, TAU, 00158 $ 1 ) 00159 * 00160 * Compute w := y - 1/2 * tau * (y'*v) * v 00161 * 00162 ALPHA = -HALF*TAUI*SDOT( I, TAU, 1, AP( I1 ), 1 ) 00163 CALL SAXPY( I, ALPHA, AP( I1 ), 1, TAU, 1 ) 00164 * 00165 * Apply the transformation as a rank-2 update: 00166 * A := A - v * w' - w * v' 00167 * 00168 CALL SSPR2( UPLO, I, -ONE, AP( I1 ), 1, TAU, 1, AP ) 00169 * 00170 AP( I1+I-1 ) = E( I ) 00171 END IF 00172 D( I+1 ) = AP( I1+I ) 00173 TAU( I ) = TAUI 00174 I1 = I1 - I 00175 10 CONTINUE 00176 D( 1 ) = AP( 1 ) 00177 ELSE 00178 * 00179 * Reduce the lower triangle of A. II is the index in AP of 00180 * A(i,i) and I1I1 is the index of A(i+1,i+1). 00181 * 00182 II = 1 00183 DO 20 I = 1, N - 1 00184 I1I1 = II + N - I + 1 00185 * 00186 * Generate elementary reflector H(i) = I - tau * v * v' 00187 * to annihilate A(i+2:n,i) 00188 * 00189 CALL SLARFG( N-I, AP( II+1 ), AP( II+2 ), 1, TAUI ) 00190 E( I ) = AP( II+1 ) 00191 * 00192 IF( TAUI.NE.ZERO ) THEN 00193 * 00194 * Apply H(i) from both sides to A(i+1:n,i+1:n) 00195 * 00196 AP( II+1 ) = ONE 00197 * 00198 * Compute y := tau * A * v storing y in TAU(i:n-1) 00199 * 00200 CALL SSPMV( UPLO, N-I, TAUI, AP( I1I1 ), AP( II+1 ), 1, 00201 $ ZERO, TAU( I ), 1 ) 00202 * 00203 * Compute w := y - 1/2 * tau * (y'*v) * v 00204 * 00205 ALPHA = -HALF*TAUI*SDOT( N-I, TAU( I ), 1, AP( II+1 ), 00206 $ 1 ) 00207 CALL SAXPY( N-I, ALPHA, AP( II+1 ), 1, TAU( I ), 1 ) 00208 * 00209 * Apply the transformation as a rank-2 update: 00210 * A := A - v * w' - w * v' 00211 * 00212 CALL SSPR2( UPLO, N-I, -ONE, AP( II+1 ), 1, TAU( I ), 1, 00213 $ AP( I1I1 ) ) 00214 * 00215 AP( II+1 ) = E( I ) 00216 END IF 00217 D( I ) = AP( II ) 00218 TAU( I ) = TAUI 00219 II = I1I1 00220 20 CONTINUE 00221 D( N ) = AP( II ) 00222 END IF 00223 * 00224 RETURN 00225 * 00226 * End of SSPTRD 00227 * 00228 END