?(or,un)mqr
Calculate
or
, where Q is returned by calling ?geqrf. If Q is transposed and it is a real matrix,
indicates
; if Q is transposed and it is a complex matrix,
indicates
. If Q is not transposed,
indicates Q.
Interface Definition
C Interface:
void sormqr_(const char *side, const char *trans, const int *m, const int *n, const int *k, float *a, const int *lda, float *tau, float *c, const int *ldc, float *work, const int *lwork, int *info);
void dormqr_(const char *side, const char *trans, const int *m, const int *n, const int *k, double *a, const int *lda, double *tau, double *c, const int *ldc, double *work, const int *lwork, int *info);
void cunmqr_(const char *side, const char *trans, const int *m, const int *n, const int *k, float _Complex *a, const int *lda, float _Complex *tau, float _Complex *c, const int *ldc, float _Complex *work, const int *lwork, int *info);
void zunmqr_(const char *side, const char *trans, const int *m, const int *n, const int *k, double _Complex *a, const int *lda, double _Complex *tau, double _Complex *c, const int *ldc, double _Complex *work, const int *lwork, int *info);
Fortran interface:
SORMQR(SIDE,TRANS,M,N,K,A,LDA,TAU,C,LDC,WORK, LWORK, INFO);
DORMQR(SIDE,TRANS,M,N,K,A,LDA,TAU,C,LDC,WORK, LWORK, INFO);
CUNMQR(SIDE,TRANS,M,N,K,A,LDA,TAU,C,LDC,WORK, LWORK, INFO);
ZUNMQR(SIDE,TRANS,M,N,K,A,LDA,TAU,C,LDC,WORK, LWORK, INFO);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
side |
Character |
|
Input |
trans |
Character |
|
Input |
M |
Integer |
Number of rows in C. M ≥ 0 |
Input |
N |
Integer |
Number of columns in C. N ≥ 0 |
Input |
K |
Integer |
Number of elementary reflectors whose product that defines Q.
|
Input |
A |
|
Original matrix |
Input |
lda |
Integer |
Leading dimension of matrix A.
|
Input |
tau |
|
tau(i) must contain the constant factor of the elementary reflector H(i), which is returned by ?geqrf. |
Input |
C |
|
Matrix to be calculated. The number of dimensions is (ldc, N). |
Input/Output |
ldc |
Integer |
Leading dimension of matrix C. ldc ≥ max(1, M) |
Input |
work |
|
Number of dimensions, max(1, lwork). If info is set to 0, work(1) returns the optimal lwork value. |
Output |
lwork |
Integer |
Work 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 |
Dependencies
#include "klapack.h"
Examples
C interface:
char side = 'L';
char trans = 'N';
int m = 4;
int n = 4;
int k = 4;
int lda = 4;
int ldc = 4;
int info = 0;
double tau[4] = {1.003949, 1.125229, 1.978923, 0.000000};
double *work = NULL;
double qwork;
int lwork = -1;
/*
* tau:
* 1.003949 1.125229 1.978923 0.000000
* A (4x4, stored in column-major):
* -1.036040 -0.892502 -0.120115 -0.425611
* 0.654120 0.468127 0.644302 -0.601906
* -0.135860 0.502159 1.077637 -0.103204
* -0.480109 -1.207226 0.162668 0.227483
*
*C (4x4, stored in column-major):
* 2.229, 8.103, 7.810, 0.087,
* 8.667, 8.859, 2.911, 4.091,
* 0.205, 1.273, 1.396, 2.553,
* 2.758, 4.317, 3.161, 8.791
*/
double a[] = {-1.036040, 0.654120, 0.135860, -0.480109,
-0.892502, 0.468127, 0.502159, -1.207226,
-0.120115, 0.644302, 1.077637, 0.162668,
-0.425611, -0.601906, -0.103204, 0.227483};
double c[] = {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};
/* Query optimal work size */
dormqr_(&side, &trans, &m, &n, &k, a, &lda, tau, c, &ldc, &qwork, &lwork, &info);
if (info != 0) {
return ERROR;
}
lwork = (int)qwork;
work = (double *)malloc(sizeof(double) * lwork);
/* Calculate Q */
dormqr_(&side, &trans, &m, &n, &k, a, &lda, tau, c, &ldc, &qwork, &lwork, &info);
free(work);
/*
* Output:
* C output (stored in column-major)
* 3.095833 3.557362 -3.821313 8.984414
* 0.830861 0.623616 -5.370613 11.371951
* -2.390220 -2.230944 -3.001512 5.595986
* -9.592006 6.367668 -2.321534 1.764135
*/
Fortran interface:
CHARACTER :: side = "L"
CHARACTER :: trans = "N"
PARAMETER (m = 4)
PARAMETER (n = 4)
PARAMETER (k = 4)
PARAMETER (lda = 4)
PARAMETER (ldc = 4)
INTEGER :: info = 0
REAL(8) :: tau(4)
REAL(8) :: qwork(1)
INTEGER :: lwork = -1
REAL(8), ALLOCATABLE :: work(:)
*
* tau:
* 1.003949 1.125229 1.978923 0.000000
* A (4x4, stored in column-major):
* -1.036040 -0.892502 -0.120115 -0.425611
* 0.654120 0.468127 0.644302 -0.601906
* -0.135860 0.502159 1.077637 -0.103204
* -0.480109 -1.207226 0.162668 0.227483
* C (4x4, stored in column-major):
* 2.229, 8.103, 7.810, 0.087,
* 8.667, 8.859, 2.911, 4.091,
* 0.205, 1.273, 1.396, 2.553,
* 2.758, 4.317, 3.161, 8.791
*
DATA tau /1.003949, 1.125229, 1.978923, 0.000000/
REAL(8) :: a(m, n)
DATA a / -1.036040, 0.654120, 0.135860, -0.480109,
$ -0.892502, 0.468127, 0.502159, -1.207226,
$ -0.120115, 0.644302, 1.077637, 0.162668,
$ -0.425611, -0.601906, -0.103204, 0.227483 /
DATA c / 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
EXTERNAL DORGLQ
* Query optimal work size
CALL DORMQR(side, trans, m, n, k, a, lda, tau, c, ldc, qwork, lwork, info)
IF (info.NE.0) THEN
CALL EXIT(1)
END IF
lwork = INT(qwork(1))
ALLOCATE(work(lwork))
* Calculate Q
CALL DORMQR(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
DEALLOCATE(work)
*
* Output:
* C output (stored in column-major)
* 3.095833 3.557362 -3.821313 8.984414
* 0.830861 0.623616 -5.370613 11.371951
* -2.390220 -2.230944 -3.001512 5.595986
* -9.592006 6.367668 -2.321534 1.764135
*