LAPACK  3.4.1
LAPACK: Linear Algebra PACKage
sgerqf.f
Go to the documentation of this file.
00001 *> \brief \b SGERQF
00002 *
00003 *  =========== DOCUMENTATION ===========
00004 *
00005 * Online html documentation available at 
00006 *            http://www.netlib.org/lapack/explore-html/ 
00007 *
00008 *> \htmlonly
00009 *> Download SGERQF + dependencies 
00010 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgerqf.f"> 
00011 *> [TGZ]</a> 
00012 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgerqf.f"> 
00013 *> [ZIP]</a> 
00014 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgerqf.f"> 
00015 *> [TXT]</a>
00016 *> \endhtmlonly 
00017 *
00018 *  Definition:
00019 *  ===========
00020 *
00021 *       SUBROUTINE SGERQF( M, N, A, LDA, TAU, WORK, LWORK, INFO )
00022 * 
00023 *       .. Scalar Arguments ..
00024 *       INTEGER            INFO, LDA, LWORK, M, N
00025 *       ..
00026 *       .. Array Arguments ..
00027 *       REAL               A( LDA, * ), TAU( * ), WORK( * )
00028 *       ..
00029 *  
00030 *
00031 *> \par Purpose:
00032 *  =============
00033 *>
00034 *> \verbatim
00035 *>
00036 *> SGERQF computes an RQ factorization of a real M-by-N matrix A:
00037 *> A = R * Q.
00038 *> \endverbatim
00039 *
00040 *  Arguments:
00041 *  ==========
00042 *
00043 *> \param[in] M
00044 *> \verbatim
00045 *>          M is INTEGER
00046 *>          The number of rows of the matrix A.  M >= 0.
00047 *> \endverbatim
00048 *>
00049 *> \param[in] N
00050 *> \verbatim
00051 *>          N is INTEGER
00052 *>          The number of columns of the matrix A.  N >= 0.
00053 *> \endverbatim
00054 *>
00055 *> \param[in,out] A
00056 *> \verbatim
00057 *>          A is REAL array, dimension (LDA,N)
00058 *>          On entry, the M-by-N matrix A.
00059 *>          On exit,
00060 *>          if m <= n, the upper triangle of the subarray
00061 *>          A(1:m,n-m+1:n) contains the M-by-M upper triangular matrix R;
00062 *>          if m >= n, the elements on and above the (m-n)-th subdiagonal
00063 *>          contain the M-by-N upper trapezoidal matrix R;
00064 *>          the remaining elements, with the array TAU, represent the
00065 *>          orthogonal matrix Q as a product of min(m,n) elementary
00066 *>          reflectors (see Further Details).
00067 *> \endverbatim
00068 *>
00069 *> \param[in] LDA
00070 *> \verbatim
00071 *>          LDA is INTEGER
00072 *>          The leading dimension of the array A.  LDA >= max(1,M).
00073 *> \endverbatim
00074 *>
00075 *> \param[out] TAU
00076 *> \verbatim
00077 *>          TAU is REAL array, dimension (min(M,N))
00078 *>          The scalar factors of the elementary reflectors (see Further
00079 *>          Details).
00080 *> \endverbatim
00081 *>
00082 *> \param[out] WORK
00083 *> \verbatim
00084 *>          WORK is REAL array, dimension (MAX(1,LWORK))
00085 *>          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
00086 *> \endverbatim
00087 *>
00088 *> \param[in] LWORK
00089 *> \verbatim
00090 *>          LWORK is INTEGER
00091 *>          The dimension of the array WORK.  LWORK >= max(1,M).
00092 *>          For optimum performance LWORK >= M*NB, where NB is
00093 *>          the optimal blocksize.
00094 *>
00095 *>          If LWORK = -1, then a workspace query is assumed; the routine
00096 *>          only calculates the optimal size of the WORK array, returns
00097 *>          this value as the first entry of the WORK array, and no error
00098 *>          message related to LWORK is issued by XERBLA.
00099 *> \endverbatim
00100 *>
00101 *> \param[out] INFO
00102 *> \verbatim
00103 *>          INFO is INTEGER
00104 *>          = 0:  successful exit
00105 *>          < 0:  if INFO = -i, the i-th argument had an illegal value
00106 *> \endverbatim
00107 *
00108 *  Authors:
00109 *  ========
00110 *
00111 *> \author Univ. of Tennessee 
00112 *> \author Univ. of California Berkeley 
00113 *> \author Univ. of Colorado Denver 
00114 *> \author NAG Ltd. 
00115 *
00116 *> \date November 2011
00117 *
00118 *> \ingroup realGEcomputational
00119 *
00120 *> \par Further Details:
00121 *  =====================
00122 *>
00123 *> \verbatim
00124 *>
00125 *>  The matrix Q is represented as a product of elementary reflectors
00126 *>
00127 *>     Q = H(1) H(2) . . . H(k), where k = min(m,n).
00128 *>
00129 *>  Each H(i) has the form
00130 *>
00131 *>     H(i) = I - tau * v * v**T
00132 *>
00133 *>  where tau is a real scalar, and v is a real vector with
00134 *>  v(n-k+i+1:n) = 0 and v(n-k+i) = 1; v(1:n-k+i-1) is stored on exit in
00135 *>  A(m-k+i,1:n-k+i-1), and tau in TAU(i).
00136 *> \endverbatim
00137 *>
00138 *  =====================================================================
00139       SUBROUTINE SGERQF( M, N, A, LDA, TAU, WORK, LWORK, INFO )
00140 *
00141 *  -- LAPACK computational routine (version 3.4.0) --
00142 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
00143 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
00144 *     November 2011
00145 *
00146 *     .. Scalar Arguments ..
00147       INTEGER            INFO, LDA, LWORK, M, N
00148 *     ..
00149 *     .. Array Arguments ..
00150       REAL               A( LDA, * ), TAU( * ), WORK( * )
00151 *     ..
00152 *
00153 *  =====================================================================
00154 *
00155 *     .. Local Scalars ..
00156       LOGICAL            LQUERY
00157       INTEGER            I, IB, IINFO, IWS, K, KI, KK, LDWORK, LWKOPT,
00158      $                   MU, NB, NBMIN, NU, NX
00159 *     ..
00160 *     .. External Subroutines ..
00161       EXTERNAL           SGERQ2, SLARFB, SLARFT, XERBLA
00162 *     ..
00163 *     .. Intrinsic Functions ..
00164       INTRINSIC          MAX, MIN
00165 *     ..
00166 *     .. External Functions ..
00167       INTEGER            ILAENV
00168       EXTERNAL           ILAENV
00169 *     ..
00170 *     .. Executable Statements ..
00171 *
00172 *     Test the input arguments
00173 *
00174       INFO = 0
00175       LQUERY = ( LWORK.EQ.-1 )
00176       IF( M.LT.0 ) THEN
00177          INFO = -1
00178       ELSE IF( N.LT.0 ) THEN
00179          INFO = -2
00180       ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
00181          INFO = -4
00182       ELSE IF( LWORK.LT.MAX( 1, M ) .AND. .NOT.LQUERY ) THEN
00183          INFO = -7
00184       END IF
00185 *
00186       IF( INFO.EQ.0 ) THEN
00187          K = MIN( M, N )
00188          IF( K.EQ.0 ) THEN
00189             LWKOPT = 1
00190          ELSE
00191             NB = ILAENV( 1, 'SGERQF', ' ', M, N, -1, -1 )
00192             LWKOPT = M*NB
00193             WORK( 1 ) = LWKOPT
00194          END IF
00195          WORK( 1 ) = LWKOPT
00196 *
00197          IF( LWORK.LT.MAX( 1, M ) .AND. .NOT.LQUERY ) THEN
00198             INFO = -7
00199          END IF
00200       END IF
00201 *
00202       IF( INFO.NE.0 ) THEN
00203          CALL XERBLA( 'SGERQF', -INFO )
00204          RETURN
00205       ELSE IF( LQUERY ) THEN
00206          RETURN
00207       END IF
00208 *
00209 *     Quick return if possible
00210 *
00211       IF( K.EQ.0 ) THEN
00212          RETURN
00213       END IF
00214 *
00215       NBMIN = 2
00216       NX = 1
00217       IWS = M
00218       IF( NB.GT.1 .AND. NB.LT.K ) THEN
00219 *
00220 *        Determine when to cross over from blocked to unblocked code.
00221 *
00222          NX = MAX( 0, ILAENV( 3, 'SGERQF', ' ', M, N, -1, -1 ) )
00223          IF( NX.LT.K ) THEN
00224 *
00225 *           Determine if workspace is large enough for blocked code.
00226 *
00227             LDWORK = M
00228             IWS = LDWORK*NB
00229             IF( LWORK.LT.IWS ) THEN
00230 *
00231 *              Not enough workspace to use optimal NB:  reduce NB and
00232 *              determine the minimum value of NB.
00233 *
00234                NB = LWORK / LDWORK
00235                NBMIN = MAX( 2, ILAENV( 2, 'SGERQF', ' ', M, N, -1,
00236      $                 -1 ) )
00237             END IF
00238          END IF
00239       END IF
00240 *
00241       IF( NB.GE.NBMIN .AND. NB.LT.K .AND. NX.LT.K ) THEN
00242 *
00243 *        Use blocked code initially.
00244 *        The last kk rows are handled by the block method.
00245 *
00246          KI = ( ( K-NX-1 ) / NB )*NB
00247          KK = MIN( K, KI+NB )
00248 *
00249          DO 10 I = K - KK + KI + 1, K - KK + 1, -NB
00250             IB = MIN( K-I+1, NB )
00251 *
00252 *           Compute the RQ factorization of the current block
00253 *           A(m-k+i:m-k+i+ib-1,1:n-k+i+ib-1)
00254 *
00255             CALL SGERQ2( IB, N-K+I+IB-1, A( M-K+I, 1 ), LDA, TAU( I ),
00256      $                   WORK, IINFO )
00257             IF( M-K+I.GT.1 ) THEN
00258 *
00259 *              Form the triangular factor of the block reflector
00260 *              H = H(i+ib-1) . . . H(i+1) H(i)
00261 *
00262                CALL SLARFT( 'Backward', 'Rowwise', N-K+I+IB-1, IB,
00263      $                      A( M-K+I, 1 ), LDA, TAU( I ), WORK, LDWORK )
00264 *
00265 *              Apply H to A(1:m-k+i-1,1:n-k+i+ib-1) from the right
00266 *
00267                CALL SLARFB( 'Right', 'No transpose', 'Backward',
00268      $                      'Rowwise', M-K+I-1, N-K+I+IB-1, IB,
00269      $                      A( M-K+I, 1 ), LDA, WORK, LDWORK, A, LDA,
00270      $                      WORK( IB+1 ), LDWORK )
00271             END IF
00272    10    CONTINUE
00273          MU = M - K + I + NB - 1
00274          NU = N - K + I + NB - 1
00275       ELSE
00276          MU = M
00277          NU = N
00278       END IF
00279 *
00280 *     Use unblocked code to factor the last or only block
00281 *
00282       IF( MU.GT.0 .AND. NU.GT.0 )
00283      $   CALL SGERQ2( MU, NU, A, LDA, TAU, WORK, IINFO )
00284 *
00285       WORK( 1 ) = IWS
00286       RETURN
00287 *
00288 *     End of SGERQF
00289 *
00290       END
 All Files Functions