LAPACK 3.3.0
|
00001 SUBROUTINE SORMLQ( SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC, 00002 $ WORK, LWORK, INFO ) 00003 * 00004 * -- LAPACK routine (version 3.2) -- 00005 * -- LAPACK is a software package provided by Univ. of Tennessee, -- 00006 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- 00007 * November 2006 00008 * 00009 * .. Scalar Arguments .. 00010 CHARACTER SIDE, TRANS 00011 INTEGER INFO, K, LDA, LDC, LWORK, M, N 00012 * .. 00013 * .. Array Arguments .. 00014 REAL A( LDA, * ), C( LDC, * ), TAU( * ), 00015 $ WORK( * ) 00016 * .. 00017 * 00018 * Purpose 00019 * ======= 00020 * 00021 * SORMLQ overwrites the general real M-by-N matrix C with 00022 * 00023 * SIDE = 'L' SIDE = 'R' 00024 * TRANS = 'N': Q * C C * Q 00025 * TRANS = 'T': Q**T * C C * Q**T 00026 * 00027 * where Q is a real orthogonal matrix defined as the product of k 00028 * elementary reflectors 00029 * 00030 * Q = H(k) . . . H(2) H(1) 00031 * 00032 * as returned by SGELQF. Q is of order M if SIDE = 'L' and of order N 00033 * if SIDE = 'R'. 00034 * 00035 * Arguments 00036 * ========= 00037 * 00038 * SIDE (input) CHARACTER*1 00039 * = 'L': apply Q or Q**T from the Left; 00040 * = 'R': apply Q or Q**T from the Right. 00041 * 00042 * TRANS (input) CHARACTER*1 00043 * = 'N': No transpose, apply Q; 00044 * = 'T': Transpose, apply Q**T. 00045 * 00046 * M (input) INTEGER 00047 * The number of rows of the matrix C. M >= 0. 00048 * 00049 * N (input) INTEGER 00050 * The number of columns of the matrix C. N >= 0. 00051 * 00052 * K (input) INTEGER 00053 * The number of elementary reflectors whose product defines 00054 * the matrix Q. 00055 * If SIDE = 'L', M >= K >= 0; 00056 * if SIDE = 'R', N >= K >= 0. 00057 * 00058 * A (input) REAL array, dimension 00059 * (LDA,M) if SIDE = 'L', 00060 * (LDA,N) if SIDE = 'R' 00061 * The i-th row must contain the vector which defines the 00062 * elementary reflector H(i), for i = 1,2,...,k, as returned by 00063 * SGELQF in the first k rows of its array argument A. 00064 * A is modified by the routine but restored on exit. 00065 * 00066 * LDA (input) INTEGER 00067 * The leading dimension of the array A. LDA >= max(1,K). 00068 * 00069 * TAU (input) REAL array, dimension (K) 00070 * TAU(i) must contain the scalar factor of the elementary 00071 * reflector H(i), as returned by SGELQF. 00072 * 00073 * C (input/output) REAL array, dimension (LDC,N) 00074 * On entry, the M-by-N matrix C. 00075 * On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q. 00076 * 00077 * LDC (input) INTEGER 00078 * The leading dimension of the array C. LDC >= max(1,M). 00079 * 00080 * WORK (workspace/output) REAL array, dimension (MAX(1,LWORK)) 00081 * On exit, if INFO = 0, WORK(1) returns the optimal LWORK. 00082 * 00083 * LWORK (input) INTEGER 00084 * The dimension of the array WORK. 00085 * If SIDE = 'L', LWORK >= max(1,N); 00086 * if SIDE = 'R', LWORK >= max(1,M). 00087 * For optimum performance LWORK >= N*NB if SIDE = 'L', and 00088 * LWORK >= M*NB if SIDE = 'R', where NB is the optimal 00089 * blocksize. 00090 * 00091 * If LWORK = -1, then a workspace query is assumed; the routine 00092 * only calculates the optimal size of the WORK array, returns 00093 * this value as the first entry of the WORK array, and no error 00094 * message related to LWORK is issued by XERBLA. 00095 * 00096 * INFO (output) INTEGER 00097 * = 0: successful exit 00098 * < 0: if INFO = -i, the i-th argument had an illegal value 00099 * 00100 * ===================================================================== 00101 * 00102 * .. Parameters .. 00103 INTEGER NBMAX, LDT 00104 PARAMETER ( NBMAX = 64, LDT = NBMAX+1 ) 00105 * .. 00106 * .. Local Scalars .. 00107 LOGICAL LEFT, LQUERY, NOTRAN 00108 CHARACTER TRANST 00109 INTEGER I, I1, I2, I3, IB, IC, IINFO, IWS, JC, LDWORK, 00110 $ LWKOPT, MI, NB, NBMIN, NI, NQ, NW 00111 * .. 00112 * .. Local Arrays .. 00113 REAL T( LDT, NBMAX ) 00114 * .. 00115 * .. External Functions .. 00116 LOGICAL LSAME 00117 INTEGER ILAENV 00118 EXTERNAL LSAME, ILAENV 00119 * .. 00120 * .. External Subroutines .. 00121 EXTERNAL SLARFB, SLARFT, SORML2, XERBLA 00122 * .. 00123 * .. Intrinsic Functions .. 00124 INTRINSIC MAX, MIN 00125 * .. 00126 * .. Executable Statements .. 00127 * 00128 * Test the input arguments 00129 * 00130 INFO = 0 00131 LEFT = LSAME( SIDE, 'L' ) 00132 NOTRAN = LSAME( TRANS, 'N' ) 00133 LQUERY = ( LWORK.EQ.-1 ) 00134 * 00135 * NQ is the order of Q and NW is the minimum dimension of WORK 00136 * 00137 IF( LEFT ) THEN 00138 NQ = M 00139 NW = N 00140 ELSE 00141 NQ = N 00142 NW = M 00143 END IF 00144 IF( .NOT.LEFT .AND. .NOT.LSAME( SIDE, 'R' ) ) THEN 00145 INFO = -1 00146 ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) ) THEN 00147 INFO = -2 00148 ELSE IF( M.LT.0 ) THEN 00149 INFO = -3 00150 ELSE IF( N.LT.0 ) THEN 00151 INFO = -4 00152 ELSE IF( K.LT.0 .OR. K.GT.NQ ) THEN 00153 INFO = -5 00154 ELSE IF( LDA.LT.MAX( 1, K ) ) THEN 00155 INFO = -7 00156 ELSE IF( LDC.LT.MAX( 1, M ) ) THEN 00157 INFO = -10 00158 ELSE IF( LWORK.LT.MAX( 1, NW ) .AND. .NOT.LQUERY ) THEN 00159 INFO = -12 00160 END IF 00161 * 00162 IF( INFO.EQ.0 ) THEN 00163 * 00164 * Determine the block size. NB may be at most NBMAX, where NBMAX 00165 * is used to define the local array T. 00166 * 00167 NB = MIN( NBMAX, ILAENV( 1, 'SORMLQ', SIDE // TRANS, M, N, K, 00168 $ -1 ) ) 00169 LWKOPT = MAX( 1, NW )*NB 00170 WORK( 1 ) = LWKOPT 00171 END IF 00172 * 00173 IF( INFO.NE.0 ) THEN 00174 CALL XERBLA( 'SORMLQ', -INFO ) 00175 RETURN 00176 ELSE IF( LQUERY ) THEN 00177 RETURN 00178 END IF 00179 * 00180 * Quick return if possible 00181 * 00182 IF( M.EQ.0 .OR. N.EQ.0 .OR. K.EQ.0 ) THEN 00183 WORK( 1 ) = 1 00184 RETURN 00185 END IF 00186 * 00187 NBMIN = 2 00188 LDWORK = NW 00189 IF( NB.GT.1 .AND. NB.LT.K ) THEN 00190 IWS = NW*NB 00191 IF( LWORK.LT.IWS ) THEN 00192 NB = LWORK / LDWORK 00193 NBMIN = MAX( 2, ILAENV( 2, 'SORMLQ', SIDE // TRANS, M, N, K, 00194 $ -1 ) ) 00195 END IF 00196 ELSE 00197 IWS = NW 00198 END IF 00199 * 00200 IF( NB.LT.NBMIN .OR. NB.GE.K ) THEN 00201 * 00202 * Use unblocked code 00203 * 00204 CALL SORML2( SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC, WORK, 00205 $ IINFO ) 00206 ELSE 00207 * 00208 * Use blocked code 00209 * 00210 IF( ( LEFT .AND. NOTRAN ) .OR. 00211 $ ( .NOT.LEFT .AND. .NOT.NOTRAN ) ) THEN 00212 I1 = 1 00213 I2 = K 00214 I3 = NB 00215 ELSE 00216 I1 = ( ( K-1 ) / NB )*NB + 1 00217 I2 = 1 00218 I3 = -NB 00219 END IF 00220 * 00221 IF( LEFT ) THEN 00222 NI = N 00223 JC = 1 00224 ELSE 00225 MI = M 00226 IC = 1 00227 END IF 00228 * 00229 IF( NOTRAN ) THEN 00230 TRANST = 'T' 00231 ELSE 00232 TRANST = 'N' 00233 END IF 00234 * 00235 DO 10 I = I1, I2, I3 00236 IB = MIN( NB, K-I+1 ) 00237 * 00238 * Form the triangular factor of the block reflector 00239 * H = H(i) H(i+1) . . . H(i+ib-1) 00240 * 00241 CALL SLARFT( 'Forward', 'Rowwise', NQ-I+1, IB, A( I, I ), 00242 $ LDA, TAU( I ), T, LDT ) 00243 IF( LEFT ) THEN 00244 * 00245 * H or H' is applied to C(i:m,1:n) 00246 * 00247 MI = M - I + 1 00248 IC = I 00249 ELSE 00250 * 00251 * H or H' is applied to C(1:m,i:n) 00252 * 00253 NI = N - I + 1 00254 JC = I 00255 END IF 00256 * 00257 * Apply H or H' 00258 * 00259 CALL SLARFB( SIDE, TRANST, 'Forward', 'Rowwise', MI, NI, IB, 00260 $ A( I, I ), LDA, T, LDT, C( IC, JC ), LDC, WORK, 00261 $ LDWORK ) 00262 10 CONTINUE 00263 END IF 00264 WORK( 1 ) = LWKOPT 00265 RETURN 00266 * 00267 * End of SORMLQ 00268 * 00269 END