?gerqf
Compute the RQ factorization of a matrix, that is, A = R * Q.
Interface Definition
C interface:
void sgerqf_(const int *M, const int *N, float *A, const int *LDA, float *TAU, float *WORK, const int *LWORK, int *INFO);
void dgerqf_(const int *M, const int *N, double *A, const int *LDA, double *TAU, double *WORK, const int *LWORK, int *INFO);
void cgerqf_(const int *M, const int *N, float _Complex *A, const int *LDA, float _Complex *TAU, float _Complex *WORK, const int *LWORK, int *INFO);
void zgerqf_(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:
DGERQF(m, n, a, lda, tau, work, lwork, info);
SGERQF(m, n, a, lda, tau, work, lwork, info);
CGERQF(m, n, a, lda, tau, work, lwork, info);
ZGERQF(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 lwork=-1 is called, 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, and the i-th element is 1. The remaining elements are stored in the i-th column of a (the lower triangle 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 */
dgerqf_(&m, &n, a, &lda, tau, &qwork, &lwork, &info);
if (info != 0) {
return ERROR;
}
lwork = (int)qwork;
work = (double *)malloc(sizeof(double) * lwork);
/* Calculate RQ */
dgerqf_(&m, &n, a, &lda, tau, work, &lwork, &info);
free(work);
/*
* Output:
* tau
* 0.000000 1.683018 1.409717 1.534598
* A output (stored in column-major)
* 1.359608 2.967627 -1.011896 -0.433983
* 0.345857 0.516770 0.307017 -2.757397
* -5.500889 -8.779283 -0.546907 0.184390
* 0.141517 -0.775170 6.494784 -1.230625
* -1.582355 0.047133 -2.152892 -10.320058
* -6.035814 -6.347009 -9.449164 -11.171009
*/
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 DGERQF
* Query optimal work size
CALL DGERQF(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 RQ
CALL DGERQF(m, n, a, lda, tau, work, lwork, info)
DEALLOCATE(work)
* Output:
* tau
* 0.000000 1.683018 1.409717 1.534598
* A output (stored in column-major)
* 1.359608 2.967627 -1.011896 -0.433983
* 0.345857 0.516770 0.307017 -2.757397
* -5.500889 -8.779283 -0.546907 0.184390
* 0.141517 -0.775170 6.494784 -1.230625
* -1.582355 0.047133 -2.152892 -10.320058
* -6.035814 -6.347009 -9.449164 -11.171009