LAPACK 3.3.0

dormbr.f

Go to the documentation of this file.
00001       SUBROUTINE DORMBR( VECT, SIDE, TRANS, M, N, K, A, LDA, TAU, C,
00002      $                   LDC, 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, VECT
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 *  If VECT = 'Q', DORMBR overwrites the general real M-by-N matrix C
00021 *  with
00022 *                  SIDE = 'L'     SIDE = 'R'
00023 *  TRANS = 'N':      Q * C          C * Q
00024 *  TRANS = 'T':      Q**T * C       C * Q**T
00025 *
00026 *  If VECT = 'P', DORMBR overwrites the general real M-by-N matrix C
00027 *  with
00028 *                  SIDE = 'L'     SIDE = 'R'
00029 *  TRANS = 'N':      P * C          C * P
00030 *  TRANS = 'T':      P**T * C       C * P**T
00031 *
00032 *  Here Q and P**T are the orthogonal matrices determined by DGEBRD when
00033 *  reducing a real matrix A to bidiagonal form: A = Q * B * P**T. Q and
00034 *  P**T are defined as products of elementary reflectors H(i) and G(i)
00035 *  respectively.
00036 *
00037 *  Let nq = m if SIDE = 'L' and nq = n if SIDE = 'R'. Thus nq is the
00038 *  order of the orthogonal matrix Q or P**T that is applied.
00039 *
00040 *  If VECT = 'Q', A is assumed to have been an NQ-by-K matrix:
00041 *  if nq >= k, Q = H(1) H(2) . . . H(k);
00042 *  if nq < k, Q = H(1) H(2) . . . H(nq-1).
00043 *
00044 *  If VECT = 'P', A is assumed to have been a K-by-NQ matrix:
00045 *  if k < nq, P = G(1) G(2) . . . G(k);
00046 *  if k >= nq, P = G(1) G(2) . . . G(nq-1).
00047 *
00048 *  Arguments
00049 *  =========
00050 *
00051 *  VECT    (input) CHARACTER*1
00052 *          = 'Q': apply Q or Q**T;
00053 *          = 'P': apply P or P**T.
00054 *
00055 *  SIDE    (input) CHARACTER*1
00056 *          = 'L': apply Q, Q**T, P or P**T from the Left;
00057 *          = 'R': apply Q, Q**T, P or P**T from the Right.
00058 *
00059 *  TRANS   (input) CHARACTER*1
00060 *          = 'N':  No transpose, apply Q  or P;
00061 *          = 'T':  Transpose, apply Q**T or P**T.
00062 *
00063 *  M       (input) INTEGER
00064 *          The number of rows of the matrix C. M >= 0.
00065 *
00066 *  N       (input) INTEGER
00067 *          The number of columns of the matrix C. N >= 0.
00068 *
00069 *  K       (input) INTEGER
00070 *          If VECT = 'Q', the number of columns in the original
00071 *          matrix reduced by DGEBRD.
00072 *          If VECT = 'P', the number of rows in the original
00073 *          matrix reduced by DGEBRD.
00074 *          K >= 0.
00075 *
00076 *  A       (input) DOUBLE PRECISION array, dimension
00077 *                                (LDA,min(nq,K)) if VECT = 'Q'
00078 *                                (LDA,nq)        if VECT = 'P'
00079 *          The vectors which define the elementary reflectors H(i) and
00080 *          G(i), whose products determine the matrices Q and P, as
00081 *          returned by DGEBRD.
00082 *
00083 *  LDA     (input) INTEGER
00084 *          The leading dimension of the array A.
00085 *          If VECT = 'Q', LDA >= max(1,nq);
00086 *          if VECT = 'P', LDA >= max(1,min(nq,K)).
00087 *
00088 *  TAU     (input) DOUBLE PRECISION array, dimension (min(nq,K))
00089 *          TAU(i) must contain the scalar factor of the elementary
00090 *          reflector H(i) or G(i) which determines Q or P, as returned
00091 *          by DGEBRD in the array argument TAUQ or TAUP.
00092 *
00093 *  C       (input/output) DOUBLE PRECISION array, dimension (LDC,N)
00094 *          On entry, the M-by-N matrix C.
00095 *          On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q
00096 *          or P*C or P**T*C or C*P or C*P**T.
00097 *
00098 *  LDC     (input) INTEGER
00099 *          The leading dimension of the array C. LDC >= max(1,M).
00100 *
00101 *  WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
00102 *          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
00103 *
00104 *  LWORK   (input) INTEGER
00105 *          The dimension of the array WORK.
00106 *          If SIDE = 'L', LWORK >= max(1,N);
00107 *          if SIDE = 'R', LWORK >= max(1,M).
00108 *          For optimum performance LWORK >= N*NB if SIDE = 'L', and
00109 *          LWORK >= M*NB if SIDE = 'R', where NB is the optimal
00110 *          blocksize.
00111 *
00112 *          If LWORK = -1, then a workspace query is assumed; the routine
00113 *          only calculates the optimal size of the WORK array, returns
00114 *          this value as the first entry of the WORK array, and no error
00115 *          message related to LWORK is issued by XERBLA.
00116 *
00117 *  INFO    (output) INTEGER
00118 *          = 0:  successful exit
00119 *          < 0:  if INFO = -i, the i-th argument had an illegal value
00120 *
00121 *  =====================================================================
00122 *
00123 *     .. Local Scalars ..
00124       LOGICAL            APPLYQ, LEFT, LQUERY, NOTRAN
00125       CHARACTER          TRANST
00126       INTEGER            I1, I2, IINFO, LWKOPT, MI, NB, NI, NQ, NW
00127 *     ..
00128 *     .. External Functions ..
00129       LOGICAL            LSAME
00130       INTEGER            ILAENV
00131       EXTERNAL           LSAME, ILAENV
00132 *     ..
00133 *     .. External Subroutines ..
00134       EXTERNAL           DORMLQ, DORMQR, XERBLA
00135 *     ..
00136 *     .. Intrinsic Functions ..
00137       INTRINSIC          MAX, MIN
00138 *     ..
00139 *     .. Executable Statements ..
00140 *
00141 *     Test the input arguments
00142 *
00143       INFO = 0
00144       APPLYQ = LSAME( VECT, 'Q' )
00145       LEFT = LSAME( SIDE, 'L' )
00146       NOTRAN = LSAME( TRANS, 'N' )
00147       LQUERY = ( LWORK.EQ.-1 )
00148 *
00149 *     NQ is the order of Q or P and NW is the minimum dimension of WORK
00150 *
00151       IF( LEFT ) THEN
00152          NQ = M
00153          NW = N
00154       ELSE
00155          NQ = N
00156          NW = M
00157       END IF
00158       IF( .NOT.APPLYQ .AND. .NOT.LSAME( VECT, 'P' ) ) THEN
00159          INFO = -1
00160       ELSE IF( .NOT.LEFT .AND. .NOT.LSAME( SIDE, 'R' ) ) THEN
00161          INFO = -2
00162       ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) ) THEN
00163          INFO = -3
00164       ELSE IF( M.LT.0 ) THEN
00165          INFO = -4
00166       ELSE IF( N.LT.0 ) THEN
00167          INFO = -5
00168       ELSE IF( K.LT.0 ) THEN
00169          INFO = -6
00170       ELSE IF( ( APPLYQ .AND. LDA.LT.MAX( 1, NQ ) ) .OR.
00171      $         ( .NOT.APPLYQ .AND. LDA.LT.MAX( 1, MIN( NQ, K ) ) ) )
00172      $          THEN
00173          INFO = -8
00174       ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
00175          INFO = -11
00176       ELSE IF( LWORK.LT.MAX( 1, NW ) .AND. .NOT.LQUERY ) THEN
00177          INFO = -13
00178       END IF
00179 *
00180       IF( INFO.EQ.0 ) THEN
00181          IF( APPLYQ ) THEN
00182             IF( LEFT ) THEN
00183                NB = ILAENV( 1, 'DORMQR', SIDE // TRANS, M-1, N, M-1,
00184      $              -1 )
00185             ELSE
00186                NB = ILAENV( 1, 'DORMQR', SIDE // TRANS, M, N-1, N-1,
00187      $              -1 )
00188             END IF
00189          ELSE
00190             IF( LEFT ) THEN
00191                NB = ILAENV( 1, 'DORMLQ', SIDE // TRANS, M-1, N, M-1,
00192      $              -1 )
00193             ELSE
00194                NB = ILAENV( 1, 'DORMLQ', SIDE // TRANS, M, N-1, N-1,
00195      $              -1 )
00196             END IF
00197          END IF
00198          LWKOPT = MAX( 1, NW )*NB
00199          WORK( 1 ) = LWKOPT
00200       END IF
00201 *
00202       IF( INFO.NE.0 ) THEN
00203          CALL XERBLA( 'DORMBR', -INFO )
00204          RETURN
00205       ELSE IF( LQUERY ) THEN
00206          RETURN
00207       END IF
00208 *
00209 *     Quick return if possible
00210 *
00211       WORK( 1 ) = 1
00212       IF( M.EQ.0 .OR. N.EQ.0 )
00213      $   RETURN
00214 *
00215       IF( APPLYQ ) THEN
00216 *
00217 *        Apply Q
00218 *
00219          IF( NQ.GE.K ) THEN
00220 *
00221 *           Q was determined by a call to DGEBRD with nq >= k
00222 *
00223             CALL DORMQR( SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC,
00224      $                   WORK, LWORK, IINFO )
00225          ELSE IF( NQ.GT.1 ) THEN
00226 *
00227 *           Q was determined by a call to DGEBRD with nq < k
00228 *
00229             IF( LEFT ) THEN
00230                MI = M - 1
00231                NI = N
00232                I1 = 2
00233                I2 = 1
00234             ELSE
00235                MI = M
00236                NI = N - 1
00237                I1 = 1
00238                I2 = 2
00239             END IF
00240             CALL DORMQR( SIDE, TRANS, MI, NI, NQ-1, A( 2, 1 ), LDA, TAU,
00241      $                   C( I1, I2 ), LDC, WORK, LWORK, IINFO )
00242          END IF
00243       ELSE
00244 *
00245 *        Apply P
00246 *
00247          IF( NOTRAN ) THEN
00248             TRANST = 'T'
00249          ELSE
00250             TRANST = 'N'
00251          END IF
00252          IF( NQ.GT.K ) THEN
00253 *
00254 *           P was determined by a call to DGEBRD with nq > k
00255 *
00256             CALL DORMLQ( SIDE, TRANST, M, N, K, A, LDA, TAU, C, LDC,
00257      $                   WORK, LWORK, IINFO )
00258          ELSE IF( NQ.GT.1 ) THEN
00259 *
00260 *           P was determined by a call to DGEBRD with nq <= k
00261 *
00262             IF( LEFT ) THEN
00263                MI = M - 1
00264                NI = N
00265                I1 = 2
00266                I2 = 1
00267             ELSE
00268                MI = M
00269                NI = N - 1
00270                I1 = 1
00271                I2 = 2
00272             END IF
00273             CALL DORMLQ( SIDE, TRANST, MI, NI, NQ-1, A( 1, 2 ), LDA,
00274      $                   TAU, C( I1, I2 ), LDC, WORK, LWORK, IINFO )
00275          END IF
00276       END IF
00277       WORK( 1 ) = LWKOPT
00278       RETURN
00279 *
00280 *     End of DORMBR
00281 *
00282       END
 All Files Functions