?(or,un)gqr
Generate a real or complex matrix Q with orthonormal rows. The matrix is defined as the first M rows of the product of K N-order elementary reflectors, i.e. Q=H(k)...H(2)H(1), where H is returned by ?geqrf.
Interface Definition
C interface:
void sorgqr_(const int *m, const int *n, const int *k, float *a, const int *lda, const float *tau, float *work, const int *lwork, int *info);
void dorgqr_(const int *m, const int *n, const int *k, double *a, const int *lda, const double *tau, double *work, const int *lwork, int *info);
void cungqr_(const int *m, const int *n, const int *k, float_Complex *a, const int *lda, const float_Complex *tau, float_Complex *work, const int *lwork, int *info);
void zungqr_(const int *m, const int *n, const int *k, double_Complex *a, const int *lda, const double_Complex *tau, double_Complex *work, const int *lwork, int *info);
Fortran interface:
SORGQR(M, N, K, A, LDA, TAU, WORK, LWORK, INFO);
DORGQR(M, N, K, A, LDA, TAU, WORK, LWORK, INFO);
CUNGQR(M, N, K, A, LDA, TAU, WORK, LWORK, INFO);
ZUNGQR(M, N, K, A, LDA, TAU, WORK, LWORK, INFO);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
m |
Integer |
Number of rows in matrix Q. m ≥ 0. |
Input |
n |
Integer |
Number of columns in matrix Q. m ≥ n ≥ 0. |
Input |
k |
Integer |
Number of elementary reflectors whose product defines matrix Q. n ≥ k ≥ 0. |
Input |
a |
|
Dimension (lda, n).
|
Input, output |
lda |
Integer |
Leading dimension of matrix A. lda ≥ max(1, m). |
Input |
tau |
|
tau(i) must contain the constant factor of the basic reflector H(i), which is returned by ?gelqf. |
Input |
work |
|
Number of dimensions, max(1, lwork). If info = 0, work(1) returns the optimal lwork value. |
Output |
lwork |
Integer |
Number of dimensions of the work array. lwork ≥ max(1, n). For the optimal performance, lwork ≥ n*nb, where nb is the optimal block size. If lwork = -1, this routine calculates only the optimal size of the work array and returns the first value of the work array. |
Input |
info |
Integer |
|
Output |
Dependency
#include "klapack.h"
Examples
C interface:
int m = 3;
int n = 3;
int k = 3;
int lda = 3;
int info = 0;
double tau[3] = {1.421559, 1.259761, 0.000000};
double *work = NULL;
double qwork;
int lwork = -1;
/*
* tau:
* 1.421559 1.259761 0.000000
* A (3x3, stored in column-major):
* -1.053312 -0.004846 1.108093
* 0.372543 -1.483477 0.560874
* 0.517801 -0.766553 0.127926
*/
double a[] = {-1.053312, 0.372543, 0.517801,
-0.004846, -1.483477, -0.766553,
1.108093, 0.560874, 0.127926};
/* Query optimal work size */
dorgqr_(&m, &n, &k, a, &lda, tau, &qwork, &lwork, &info);
if (info != 0) {
return ERROR;
}
lwork = (int)qwork;
work = (double *)malloc(sizeof(double) * lwork);
/* Calculate Q */
dorgqr_(&m, &n, &k, a, &lda, tau, work, &lwork, &info);
free(work);
/*
* Output:
* A output (stored in column-major)
* -0.421559 -0.529592 -0.736085
* -0.573250 -0.473321 0.668844
* -0.702618 0.703918 -0.104055
*/
Fortran interface:
PARAMETER (m = 3)
PARAMETER (n = 3)
PARAMETER (k = 3)
PARAMETER (lda = 3)
INTEGER :: info = 0
REAL(8) :: tau(3)
REAL(8) :: qwork(1)
INTEGER :: lwork = -1
REAL(8), ALLOCATABLE :: work(:)
*
* tau:
* 1.421559 1.259761 0.000000
* A (3x3, stored in column-major):
* -1.053312 -0.004846 1.108093
* 0.372543 -1.483477 0.560874
* 0.517801 -0.766553 0.127926
*
DATA tau /1.421559, 1.259761, 0.000000/
REAL(8) :: a(m, n)
DATA a / -1.053312, 0.372543, 0.517801,
$ -0.004846, -1.483477, -0.766553,
$ 1.108093, 0.560874, 0.127926 /
EXTERNAL DORGQR
* Query optimal work size
CALL DORGQR(m, n, k, a, lda, tau, qwork, lwork, info)
IF (info.NE.0) THEN
CALL EXIT(1)
END IF
lwork = INT(qwork(1))
ALLOCATE(work(lwork))
* Calculate Q
CALL DORGQR(m, n, k, a, lda, tau, work, lwork, info)
DEALLOCATE(work)
* Output:
* A output (stored in column-major)
* -0.421559 -0.529592 -0.736085
* -0.573250 -0.473321 0.668844
* -0.702618 0.703918 -0.104055