Rate This Document
Findability
Accuracy
Completeness
Readability

?(or,un)grq

Generate a real or complex matrix Q with orthogonal rows. The matrix is defined as the first M rows of the product of K N-order elementary reflectors, i.e. Q=H(1)H(2)…H(k), where H is returned by calling ?gerqf.

Interface Definition

C interface:

void sorgrq_(const int *M, const int *N, const int *K, float *A, const int *lda, float *tau, float *work, const int *lwork, int *info);

void dorgrq_(const int *M, const int *N, const int *K, double *A, const int *lda, double *tau, double *work, const int *lwork, int *info);

void cungrq_(const int *M, const int *N, const int *K, float _Complex *A, const int *lda, float _Complex *tau, float _Complex *work, const int *lwork, int *info);

void zungrq_(const int *M, const int *N, const int *K, double _Complex *A, const int *lda, double _Complex *tau, double _Complex *work, const int *lwork, int *info);

Fortran interface:

SORGRQ(M,N,K,A,LDA,TAU,WORK,LWORK,INFO);

DORGRQ(M,N,K,A,LDA,TAU,WORK,LWORK,INFO);

CUNGRQ(M,N,K,A,LDA,TAU,WORK,LWORK,INFO);

ZUNGRQ(M,N,K,A,LDA,TAU,WORK,LWORK,INFO);

Parameters

Parameter

Type

Description

Input/Output

M

Integer

Number of rows in Q. M ≥ 0

Input

N

Integer

Number of columns in Q. N ≥ 0

Input

K

Integer

Number of elementary reflectors whose product defines matrix Q. M ≥ K ≥ 0

Input

A

  • A single-precision floating-point array in sorgrq
  • A double-precision floating-point array in dorgrq
  • A single-precision complex number array in cungrq
  • A double-precision complex number array in zungrq

Dimension (lda, n).

  • If a is used as an input, column i must contain the elementary reflector H(i) vector, where H(i) is returned by ?gerqf.
  • If a is used as an output, it is an m*n matrix Q.

Input/Output

lda

Integer

Leading dimension of matrix A. lda ≥ max(1, M)

Input

tau

  • A single-precision floating-point array in sorgrq
  • A double-precision floating-point array in dorgrq
  • A single-precision complex number array in cungrq
  • A double-precision complex number array in zungrq

tau(i) must contain the constant factor of the elementary reflector H(i), which is returned by ?gerqf.

Input

work

  • A single-precision floating-point array in sorgrq
  • A double-precision floating-point array in dorgrq
  • A single-precision complex number array in cungrq
  • A double-precision complex number array in zungrq

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, M). For the optimal performance, lwork >= M*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

  • info = 0: The execution is successful.
  • info < 0: If the value of info is -i, the ith parameter is invalid.

Output

Dependencies

#include "klapack.h"

Examples

C interface:

    int m = 4; 
    int n = 4; 
    int k = 4; 
    int lda = m; 
    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
 
     *
     */ 
    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}; 

    /* Query optimal work size */ 
    dorgrq_(&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 */ 
    dorgrq_(&m, &n, &k, a, &lda, tau, work, &lwork, &info); 
    free(work); 
    /* 
     * Output: 
     * A output (stored in column-major) 
     *   -0.002365       -0.692243       -0.268856       -0.000000 
     *   0.001733        0.036633        -0.993734       -0.000000 
     *   -0.002338       0.322332        -0.978923       -0.000000 
     *   0.000000        0.000000        0.000000        1.000000 
     */

Fortran interface:

        PARAMETER (m = 4) 
        PARAMETER (n = 4) 
        PARAMETER (k = 4) 
        PARAMETER (lda = 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
 
*
        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 / 
   
        EXTERNAL DORGLQ 
*       Query optimal work size 
        CALL DORGRQ(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 DORGRQ(m, n, k, a, lda, tau, work, lwork, info) 
        DEALLOCATE(work) 
 * 
 * Output: 
 * A output (stored in column-major) 
 *   -0.002365       -0.692243       -0.268856       -0.000000 
 *   0.001733        0.036633        -0.993734       -0.000000 
 *   -0.002338       0.322332        -0.978923       -0.000000 
 *   0.000000        0.000000        0.000000        1.000000