LAPACK  3.9.0
LAPACK: Linear Algebra PACKage

◆ sgeqrf()

subroutine sgeqrf ( integer  M,
integer  N,
real, dimension( lda, * )  A,
integer  LDA,
real, dimension( * )  TAU,
real, dimension( * )  WORK,
integer  LWORK,
integer  INFO 
)

SGEQRF

Download SGEQRF + dependencies [TGZ] [ZIP] [TXT]

Purpose:
 SGEQRF computes a QR factorization of a real M-by-N matrix A:

    A = Q * ( R ),
            ( 0 )

 where:

    Q is a M-by-M orthogonal matrix;
    R is an upper-triangular N-by-N matrix;
    0 is a (M-N)-by-N zero matrix, if M > N.
Parameters
[in]M
          M is INTEGER
          The number of rows of the matrix A.  M >= 0.
[in]N
          N is INTEGER
          The number of columns of the matrix A.  N >= 0.
[in,out]A
          A is REAL array, dimension (LDA,N)
          On entry, the M-by-N matrix A.
          On exit, the elements on and above the diagonal of the array
          contain the min(M,N)-by-N upper trapezoidal matrix R (R is
          upper triangular if m >= n); the elements below the diagonal,
          with the array TAU, represent the orthogonal matrix Q as a
          product of min(m,n) elementary reflectors (see Further
          Details).
[in]LDA
          LDA is INTEGER
          The leading dimension of the array A.  LDA >= max(1,M).
[out]TAU
          TAU is REAL array, dimension (min(M,N))
          The scalar factors of the elementary reflectors (see Further
          Details).
[out]WORK
          WORK is REAL array, dimension (MAX(1,LWORK))
          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
[in]LWORK
          LWORK is INTEGER
          The dimension of the array WORK.  LWORK >= max(1,N).
          For optimum performance LWORK >= N*NB, where NB is
          the optimal blocksize.

          If LWORK = -1, then a workspace query is assumed; the routine
          only calculates the optimal size of the WORK array, returns
          this value as the first entry of the WORK array, and no error
          message related to LWORK is issued by XERBLA.
[out]INFO
          INFO is INTEGER
          = 0:  successful exit
          < 0:  if INFO = -i, the i-th argument had an illegal value
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.
Date
November 2019
Further Details:
  The matrix Q is represented as a product of elementary reflectors

     Q = H(1) H(2) . . . H(k), where k = min(m,n).

  Each H(i) has the form

     H(i) = I - tau * v * v**T

  where tau is a real scalar, and v is a real vector with
  v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i),
  and tau in TAU(i).

Definition at line 147 of file sgeqrf.f.

147 *
148 * -- LAPACK computational routine (version 3.9.0) --
149 * -- LAPACK is a software package provided by Univ. of Tennessee, --
150 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
151 * November 2019
152 *
153 * .. Scalar Arguments ..
154  INTEGER INFO, LDA, LWORK, M, N
155 * ..
156 * .. Array Arguments ..
157  REAL A( LDA, * ), TAU( * ), WORK( * )
158 * ..
159 *
160 * =====================================================================
161 *
162 * .. Local Scalars ..
163  LOGICAL LQUERY
164  INTEGER I, IB, IINFO, IWS, K, LDWORK, LWKOPT, NB,
165  $ NBMIN, NX
166 * ..
167 * .. External Subroutines ..
168  EXTERNAL sgeqr2, slarfb, slarft, xerbla
169 * ..
170 * .. Intrinsic Functions ..
171  INTRINSIC max, min
172 * ..
173 * .. External Functions ..
174  INTEGER ILAENV
175  EXTERNAL ilaenv
176 * ..
177 * .. Executable Statements ..
178 *
179 * Test the input arguments
180 *
181  info = 0
182  nb = ilaenv( 1, 'SGEQRF', ' ', m, n, -1, -1 )
183  lwkopt = n*nb
184  work( 1 ) = lwkopt
185  lquery = ( lwork.EQ.-1 )
186  IF( m.LT.0 ) THEN
187  info = -1
188  ELSE IF( n.LT.0 ) THEN
189  info = -2
190  ELSE IF( lda.LT.max( 1, m ) ) THEN
191  info = -4
192  ELSE IF( lwork.LT.max( 1, n ) .AND. .NOT.lquery ) THEN
193  info = -7
194  END IF
195  IF( info.NE.0 ) THEN
196  CALL xerbla( 'SGEQRF', -info )
197  RETURN
198  ELSE IF( lquery ) THEN
199  RETURN
200  END IF
201 *
202 * Quick return if possible
203 *
204  k = min( m, n )
205  IF( k.EQ.0 ) THEN
206  work( 1 ) = 1
207  RETURN
208  END IF
209 *
210  nbmin = 2
211  nx = 0
212  iws = n
213  IF( nb.GT.1 .AND. nb.LT.k ) THEN
214 *
215 * Determine when to cross over from blocked to unblocked code.
216 *
217  nx = max( 0, ilaenv( 3, 'SGEQRF', ' ', m, n, -1, -1 ) )
218  IF( nx.LT.k ) THEN
219 *
220 * Determine if workspace is large enough for blocked code.
221 *
222  ldwork = n
223  iws = ldwork*nb
224  IF( lwork.LT.iws ) THEN
225 *
226 * Not enough workspace to use optimal NB: reduce NB and
227 * determine the minimum value of NB.
228 *
229  nb = lwork / ldwork
230  nbmin = max( 2, ilaenv( 2, 'SGEQRF', ' ', m, n, -1,
231  $ -1 ) )
232  END IF
233  END IF
234  END IF
235 *
236  IF( nb.GE.nbmin .AND. nb.LT.k .AND. nx.LT.k ) THEN
237 *
238 * Use blocked code initially
239 *
240  DO 10 i = 1, k - nx, nb
241  ib = min( k-i+1, nb )
242 *
243 * Compute the QR factorization of the current block
244 * A(i:m,i:i+ib-1)
245 *
246  CALL sgeqr2( m-i+1, ib, a( i, i ), lda, tau( i ), work,
247  $ iinfo )
248  IF( i+ib.LE.n ) THEN
249 *
250 * Form the triangular factor of the block reflector
251 * H = H(i) H(i+1) . . . H(i+ib-1)
252 *
253  CALL slarft( 'Forward', 'Columnwise', m-i+1, ib,
254  $ a( i, i ), lda, tau( i ), work, ldwork )
255 *
256 * Apply H**T to A(i:m,i+ib:n) from the left
257 *
258  CALL slarfb( 'Left', 'Transpose', 'Forward',
259  $ 'Columnwise', m-i+1, n-i-ib+1, ib,
260  $ a( i, i ), lda, work, ldwork, a( i, i+ib ),
261  $ lda, work( ib+1 ), ldwork )
262  END IF
263  10 CONTINUE
264  ELSE
265  i = 1
266  END IF
267 *
268 * Use unblocked code to factor the last or only block.
269 *
270  IF( i.LE.k )
271  $ CALL sgeqr2( m-i+1, n-i+1, a( i, i ), lda, tau( i ), work,
272  $ iinfo )
273 *
274  work( 1 ) = iws
275  RETURN
276 *
277 * End of SGEQRF
278 *
Here is the call graph for this function:
Here is the caller graph for this function:
slarfb
subroutine slarfb(SIDE, TRANS, DIRECT, STOREV, M, N, K, V, LDV, T, LDT, C, LDC, WORK, LDWORK)
SLARFB applies a block reflector or its transpose to a general rectangular matrix.
Definition: slarfb.f:199
slarft
subroutine slarft(DIRECT, STOREV, N, K, V, LDV, TAU, T, LDT)
SLARFT forms the triangular factor T of a block reflector H = I - vtvH
Definition: slarft.f:165
sgeqr2
subroutine sgeqr2(M, N, A, LDA, TAU, WORK, INFO)
SGEQR2 computes the QR factorization of a general rectangular matrix using an unblocked algorithm.
Definition: sgeqr2.f:132
xerbla
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:62
ilaenv
integer function ilaenv(ISPEC, NAME, OPTS, N1, N2, N3, N4)
ILAENV
Definition: tstiee.f:83