?geqrf
Compute the QR factorization of a matrix, that is,
.
Interface Definition
C interface:
void dgeqrf_(const int *m, const int *n, double *a, const int *lda, double *tau, double *work, const int *lwork, int *info);
void sgeqrf_(const int *m, const int *n, float *a, const int *lda, float *tau, float *work, const int *lwork, int *info);
void cgeqrf_(const int *m, const int *n, float _Complex *a, const int *lda, float _Complex *tau, float _Complex *work, const int *lwork, int *info);
void zgeqrf_(const int *m, const int *n, double _Complex *a, const int *lda, double _Complex *tau, double _Complex *work, const int *lwork, int *info);
Fortran interface:
DGEQRF(m, n, a, lda, tau, work, lwork, info);
SGEQRF(m, n, a, lda, tau, work, lwork, info);
CGEQRF(m, n, a, lda, tau, work, lwork, info);
ZGEQRF(m, n, a, lda, tau, work, lwork, info);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
m |
Integer |
Number of rows in matrix A |
Input |
n |
Integer |
Number of columns in matrix A |
Input |
a |
|
|
Input/Output |
lda |
Integer |
Leading dimension of matrix A. lda ≥ max(1, m). |
Output |
tau |
|
Elementary reflection coefficient. Its length is min(m,n). For details, see the NOTE. |
Output |
work |
|
Temporary storage space. After this interface is called with lwork = -1, work[0] is the optimal lwork value. |
Output |
lwork |
Integer |
Length of the work array. If lwork = -1, the optimal work size is queried and the result is saved in work[0]. If lwork ≠ -1, the value of lwork must be greater than or equal to n. |
Input |
info |
Integer |
Execution result:
|
Output |
The factorization result matrix Q is represented by a series of elementary reflection products: Q=H(1)*H(2)*...*H(k), k=min(m,n). H(i)=I-tau*v*v' tau is a scalar, v is a vector, the first (i-1) elements are 0, the i-th element is 1, and the remaining elements are stored in the i-th column (the lower triangle of a) of a.
Dependencies
#include "klapack.h"
Examples
C interface:
int m = 6;
int n = 4;
int lda = 6;
int info = 0;
double tau[4];
double *work = NULL;
double qwork;
int lwork = -1;
/*
* A (6x4, stored in column-major):
* 2.229 1.273 0.087 0.035
* 8.667 4.317 4.091 3.609
* 0.205 7.810 2.553 6.507
* 2.758 2.911 8.791 5.051
* 8.103 1.396 1.317 4.738
* 8.859 3.161 0.808 5.972
*/
double a[] = {2.229, 8.667, 0.205, 2.758, 8.103, 8.859,
1.273, 4.317, 7.810, 2.911, 1.396, 3.161,
0.087, 4.091, 2.553, 8.791, 1.317, 0.808,
0.035, 3.609, 6.507, 5.051, 4.738, 5.972};
/* Query optimal work size */
dgeqrf_(&m, &n, a, &lda, tau, &qwork, &lwork, &info);
if (info != 0) {
return ERROR;
}
lwork = (int)qwork;
work = (double *)malloc(sizeof(double) * lwork);
/* Calculate QR */
dgeqrf_(&m, &n, a, &lda, tau, work, &lwork, &info);
free(work);
/*
* Output:
* tau
* 1.1464 1.0946 1.3670 1.7415
* A output (stored in column-major)
* -15.2274 -5.8577 -5.1387 -9.0573
* 0.4965 -8.2070 -4.5806 -6.5291
* 0.0117 0.8600 7.4527 1.3953
* 0.1580 0.1986 -0.6634 -3.5188
* 0.4642 -0.2130 -0.0183 0.2805
* 0.5075 -0.0510 0.1506 0.2642
*/
Fortran interface:
PARAMETER (m = 6)
PARAMETER (n = 4)
PARAMETER (lda = 6)
INTEGER :: info = 0
REAL(8) :: tau(4)
REAL(8) :: qwork(1)
INTEGER :: lwork = -1
REAL(8), ALLOCATABLE :: work(:)
*
* A (6x4, stored in column-major):
* 2.229 1.273 0.087 0.035
* 8.667 4.317 4.091 3.609
* 0.205 7.810 2.553 6.507
* 2.758 2.911 8.791 5.051
* 8.103 1.396 1.317 4.738
* 8.859 3.161 0.808 5.972
*
REAL(8) :: a(m, n)
DATA a / 2.229, 8.667, 0.205, 2.758, 8.103, 8.859,
$ 1.273, 4.317, 7.810, 2.911, 1.396, 3.161,
$ 0.087, 4.091, 2.553, 8.791, 1.317, 0.808,
$ 0.035, 3.609, 6.507, 5.051, 4.738, 5.972 /
EXTERNAL DGEQRF
* Query optimal work size
CALL DGEQRF(m, n, a, lda, tau, qwork, lwork, info)
IF (info.NE.0) THEN
CALL EXIT(1)
END IF
lwork = INT(qwork(1))
ALLOCATE(work(lwork))
* Calculate QR
CALL DGEQRF(m, n, a, lda, tau, work, lwork, info)
DEALLOCATE(work)
* Output:
* tau
* 1.1464 1.0946 1.3670 1.7415
* A output (stored in column-major)
* -15.2274 -5.8577 -5.1387 -9.0573
* 0.4965 -8.2070 -4.5806 -6.5291
* 0.0117 0.8600 7.4527 1.3953
* 0.1580 0.1986 -0.6634 -3.5188
* 0.4642 -0.2130 -0.0183 0.2805
* 0.5075 -0.0510 0.1506 0.2642