LAPACK 3.3.1
Linear Algebra PACKage

dormqr.f

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