Computes the QR factorization of a general m-by-n matrix.


lapack_int LAPACKE_sgeqrf (int matrix_layout, lapack_int m, lapack_int n, float* a, lapack_int lda, float* tau);

lapack_int LAPACKE_dgeqrf (int matrix_layout, lapack_int m, lapack_int n, double* a, lapack_int lda, double* tau);

lapack_int LAPACKE_cgeqrf (int matrix_layout, lapack_int m, lapack_int n, lapack_complex_float* a, lapack_int lda, lapack_complex_float* tau);

lapack_int LAPACKE_zgeqrf (int matrix_layout, lapack_int m, lapack_int n, lapack_complex_double* a, lapack_int lda, lapack_complex_double* tau);

Include Files

  • mkl.h


The routine forms the QR factorization of a general m-by-n matrix A (see Orthogonal Factorizations). No pivoting is performed.

The routine does not form the matrix Q explicitly. Instead, Q is represented as a product of min(m, n) elementary reflectors. Routines are provided to work with Q in this representation.


This routine supports the Progress Routine feature. See Progress Function for details.

Input Parameters


Specifies whether matrix storage layout is row major (LAPACK_ROW_MAJOR) or column major (LAPACK_COL_MAJOR).


The number of rows in the matrix A (m 0).


The number of columns in A (n 0).


Array a of size max(1, lda*n) for column major layout and max(1, lda*m) for row major layout contains the matrix A.


The leading dimension of a; at least max(1, m) for column major layout and at least max(1, n) for row major layout.

Output Parameters


Overwritten by the factorization data as follows:

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 mn); the elements below the diagonal, with the array tau, present the orthogonal matrix Q as a product of min(m,n) elementary reflectors (see Orthogonal Factorizations).


Array, size at least max (1, min(m, n)). Contains scalars that define elementary reflectors for the matrix Qin its decomposition in a product of elementary reflectors (see Orthogonal Factorizations).

Return Values

This function returns a value info.

If info=0, the execution is successful.

If info = -i, the i-th parameter had an illegal value.

Application Notes

The computed factorization is the exact factorization of a matrix A + E, where

||E||2 = O(ε)||A||2.

The approximate number of floating-point operations for real flavors is


if m = n,


if m > n,


if m < n.

The number of operations for complex flavors is 4 times greater.

To solve a set of least squares problems minimizing ||A*x - b||2 for all columns b of a given matrix B, you can call the following:

?geqrf (this routine)

to factorize A = QR;


to compute C = QT*B (for real matrices);


to compute C = QH*B (for complex matrices);

trsm (a BLAS routine)

to solve R*X = C.

(The columns of the computed X are the least squares solution vectors x.)

To compute the elements of Q explicitly, call


(for real matrices)


(for complex matrices).

For more complete information about compiler optimizations, see our Optimization Notice.