LAPACK 3.3.0

dorgbr.f

Go to the documentation of this file.
00001       SUBROUTINE DORGBR( VECT, M, N, K, A, LDA, TAU, WORK, LWORK, 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          VECT
00010       INTEGER            INFO, K, LDA, LWORK, M, N
00011 *     ..
00012 *     .. Array Arguments ..
00013       DOUBLE PRECISION   A( LDA, * ), TAU( * ), WORK( * )
00014 *     ..
00015 *
00016 *  Purpose
00017 *  =======
00018 *
00019 *  DORGBR generates one of the real orthogonal matrices Q or P**T
00020 *  determined by DGEBRD when reducing a real matrix A to bidiagonal
00021 *  form: A = Q * B * P**T.  Q and P**T are defined as products of
00022 *  elementary reflectors H(i) or G(i) respectively.
00023 *
00024 *  If VECT = 'Q', A is assumed to have been an M-by-K matrix, and Q
00025 *  is of order M:
00026 *  if m >= k, Q = H(1) H(2) . . . H(k) and DORGBR returns the first n
00027 *  columns of Q, where m >= n >= k;
00028 *  if m < k, Q = H(1) H(2) . . . H(m-1) and DORGBR returns Q as an
00029 *  M-by-M matrix.
00030 *
00031 *  If VECT = 'P', A is assumed to have been a K-by-N matrix, and P**T
00032 *  is of order N:
00033 *  if k < n, P**T = G(k) . . . G(2) G(1) and DORGBR returns the first m
00034 *  rows of P**T, where n >= m >= k;
00035 *  if k >= n, P**T = G(n-1) . . . G(2) G(1) and DORGBR returns P**T as
00036 *  an N-by-N matrix.
00037 *
00038 *  Arguments
00039 *  =========
00040 *
00041 *  VECT    (input) CHARACTER*1
00042 *          Specifies whether the matrix Q or the matrix P**T is
00043 *          required, as defined in the transformation applied by DGEBRD:
00044 *          = 'Q':  generate Q;
00045 *          = 'P':  generate P**T.
00046 *
00047 *  M       (input) INTEGER
00048 *          The number of rows of the matrix Q or P**T to be returned.
00049 *          M >= 0.
00050 *
00051 *  N       (input) INTEGER
00052 *          The number of columns of the matrix Q or P**T to be returned.
00053 *          N >= 0.
00054 *          If VECT = 'Q', M >= N >= min(M,K);
00055 *          if VECT = 'P', N >= M >= min(N,K).
00056 *
00057 *  K       (input) INTEGER
00058 *          If VECT = 'Q', the number of columns in the original M-by-K
00059 *          matrix reduced by DGEBRD.
00060 *          If VECT = 'P', the number of rows in the original K-by-N
00061 *          matrix reduced by DGEBRD.
00062 *          K >= 0.
00063 *
00064 *  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
00065 *          On entry, the vectors which define the elementary reflectors,
00066 *          as returned by DGEBRD.
00067 *          On exit, the M-by-N matrix Q or P**T.
00068 *
00069 *  LDA     (input) INTEGER
00070 *          The leading dimension of the array A. LDA >= max(1,M).
00071 *
00072 *  TAU     (input) DOUBLE PRECISION array, dimension
00073 *                                (min(M,K)) if VECT = 'Q'
00074 *                                (min(N,K)) if VECT = 'P'
00075 *          TAU(i) must contain the scalar factor of the elementary
00076 *          reflector H(i) or G(i), which determines Q or P**T, as
00077 *          returned by DGEBRD in its array argument TAUQ or TAUP.
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. LWORK >= max(1,min(M,N)).
00084 *          For optimum performance LWORK >= min(M,N)*NB, where NB
00085 *          is the optimal blocksize.
00086 *
00087 *          If LWORK = -1, then a workspace query is assumed; the routine
00088 *          only calculates the optimal size of the WORK array, returns
00089 *          this value as the first entry of the WORK array, and no error
00090 *          message related to LWORK is issued by XERBLA.
00091 *
00092 *  INFO    (output) INTEGER
00093 *          = 0:  successful exit
00094 *          < 0:  if INFO = -i, the i-th argument had an illegal value
00095 *
00096 *  =====================================================================
00097 *
00098 *     .. Parameters ..
00099       DOUBLE PRECISION   ZERO, ONE
00100       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
00101 *     ..
00102 *     .. Local Scalars ..
00103       LOGICAL            LQUERY, WANTQ
00104       INTEGER            I, IINFO, J, LWKOPT, MN, NB
00105 *     ..
00106 *     .. External Functions ..
00107       LOGICAL            LSAME
00108       INTEGER            ILAENV
00109       EXTERNAL           LSAME, ILAENV
00110 *     ..
00111 *     .. External Subroutines ..
00112       EXTERNAL           DORGLQ, DORGQR, XERBLA
00113 *     ..
00114 *     .. Intrinsic Functions ..
00115       INTRINSIC          MAX, MIN
00116 *     ..
00117 *     .. Executable Statements ..
00118 *
00119 *     Test the input arguments
00120 *
00121       INFO = 0
00122       WANTQ = LSAME( VECT, 'Q' )
00123       MN = MIN( M, N )
00124       LQUERY = ( LWORK.EQ.-1 )
00125       IF( .NOT.WANTQ .AND. .NOT.LSAME( VECT, 'P' ) ) THEN
00126          INFO = -1
00127       ELSE IF( M.LT.0 ) THEN
00128          INFO = -2
00129       ELSE IF( N.LT.0 .OR. ( WANTQ .AND. ( N.GT.M .OR. N.LT.MIN( M,
00130      $         K ) ) ) .OR. ( .NOT.WANTQ .AND. ( M.GT.N .OR. M.LT.
00131      $         MIN( N, K ) ) ) ) THEN
00132          INFO = -3
00133       ELSE IF( K.LT.0 ) THEN
00134          INFO = -4
00135       ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
00136          INFO = -6
00137       ELSE IF( LWORK.LT.MAX( 1, MN ) .AND. .NOT.LQUERY ) THEN
00138          INFO = -9
00139       END IF
00140 *
00141       IF( INFO.EQ.0 ) THEN
00142          IF( WANTQ ) THEN
00143             NB = ILAENV( 1, 'DORGQR', ' ', M, N, K, -1 )
00144          ELSE
00145             NB = ILAENV( 1, 'DORGLQ', ' ', M, N, K, -1 )
00146          END IF
00147          LWKOPT = MAX( 1, MN )*NB
00148          WORK( 1 ) = LWKOPT
00149       END IF
00150 *
00151       IF( INFO.NE.0 ) THEN
00152          CALL XERBLA( 'DORGBR', -INFO )
00153          RETURN
00154       ELSE IF( LQUERY ) THEN
00155          RETURN
00156       END IF
00157 *
00158 *     Quick return if possible
00159 *
00160       IF( M.EQ.0 .OR. N.EQ.0 ) THEN
00161          WORK( 1 ) = 1
00162          RETURN
00163       END IF
00164 *
00165       IF( WANTQ ) THEN
00166 *
00167 *        Form Q, determined by a call to DGEBRD to reduce an m-by-k
00168 *        matrix
00169 *
00170          IF( M.GE.K ) THEN
00171 *
00172 *           If m >= k, assume m >= n >= k
00173 *
00174             CALL DORGQR( M, N, K, A, LDA, TAU, WORK, LWORK, IINFO )
00175 *
00176          ELSE
00177 *
00178 *           If m < k, assume m = n
00179 *
00180 *           Shift the vectors which define the elementary reflectors one
00181 *           column to the right, and set the first row and column of Q
00182 *           to those of the unit matrix
00183 *
00184             DO 20 J = M, 2, -1
00185                A( 1, J ) = ZERO
00186                DO 10 I = J + 1, M
00187                   A( I, J ) = A( I, J-1 )
00188    10          CONTINUE
00189    20       CONTINUE
00190             A( 1, 1 ) = ONE
00191             DO 30 I = 2, M
00192                A( I, 1 ) = ZERO
00193    30       CONTINUE
00194             IF( M.GT.1 ) THEN
00195 *
00196 *              Form Q(2:m,2:m)
00197 *
00198                CALL DORGQR( M-1, M-1, M-1, A( 2, 2 ), LDA, TAU, WORK,
00199      $                      LWORK, IINFO )
00200             END IF
00201          END IF
00202       ELSE
00203 *
00204 *        Form P', determined by a call to DGEBRD to reduce a k-by-n
00205 *        matrix
00206 *
00207          IF( K.LT.N ) THEN
00208 *
00209 *           If k < n, assume k <= m <= n
00210 *
00211             CALL DORGLQ( M, N, K, A, LDA, TAU, WORK, LWORK, IINFO )
00212 *
00213          ELSE
00214 *
00215 *           If k >= n, assume m = n
00216 *
00217 *           Shift the vectors which define the elementary reflectors one
00218 *           row downward, and set the first row and column of P' to
00219 *           those of the unit matrix
00220 *
00221             A( 1, 1 ) = ONE
00222             DO 40 I = 2, N
00223                A( I, 1 ) = ZERO
00224    40       CONTINUE
00225             DO 60 J = 2, N
00226                DO 50 I = J - 1, 2, -1
00227                   A( I, J ) = A( I-1, J )
00228    50          CONTINUE
00229                A( 1, J ) = ZERO
00230    60       CONTINUE
00231             IF( N.GT.1 ) THEN
00232 *
00233 *              Form P'(2:n,2:n)
00234 *
00235                CALL DORGLQ( N-1, N-1, N-1, A( 2, 2 ), LDA, TAU, WORK,
00236      $                      LWORK, IINFO )
00237             END IF
00238          END IF
00239       END IF
00240       WORK( 1 ) = LWKOPT
00241       RETURN
00242 *
00243 *     End of DORGBR
00244 *
00245       END
 All Files Functions