我要评分
获取效率
正确性
完整性
易理解

?gelqf

Compute the LQ factorization of a matrix, that is, A = L * Q.

Interface Definition

C interface:

void sgelqf_(const int *M, const int *N, float *A, const int *LDA, float *TAU, float *WORK, const int *LWORK, int *INFO);

void dgelqf_(const int *M, const int *N, double *A, const int *LDA, double *TAU, double *WORK, const int *LWORK, int *INFO);

void cgelqf_(const int *M, const int *N, float _Complex *A, const int *LDA, float _Complex *TAU, float _Complex *WORK, const int *LWORK, int *INFO);

void zgelqf_(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:

DGELQF(m, n, a, lda, tau, work, lwork, info);

SGELQF(m, n, a, lda, tau, work, lwork, info);

CGELQF(m, n, a, lda, tau, work, lwork, info);

ZGELQF(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

  • For sgelqf, a is a single-precision floating-point array.
  • For dgelqf, a is a double-precision floating-point array.
  • For cgelqf, a is a single-precision complex number array.
  • For zgelqf, a is a double-precision complex number array.
  • Stores matrix A to be factorized before this function is called.
  • After this function is called, a matrix R with a size of min(m,n)*n (when m ≥ n, L is a lower triangular matrix) is stored on and above the diagonal. Elements below the diagonal and tau jointly represent an orthogonal matrix Q (see the NOTE).

Input/output

lda

Integer

Leading dimension of matrix A. ldamax(1, m)

Output

tau

  • For sgelqf, tau is a single-precision floating-point array.
  • For dgelqf, tau is a double-precision floating-point array.
  • For cgelqf, tau is a single-precision complex number array.
  • For zgelqf, tau is a double-precision complex number array.

Elementary reflection coefficient. Its length is min(m, n). For details, see the NOTE.

Output

work

  • For sgelqf, work is a single-precision floating-point array.
  • For dgelqf, work is a double-precision floating-point array.
  • For cgelqf, work is a single-precision complex number array.
  • For zgelqf, work is a double-precision complex number array.

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:

  • 0: The execution is successful.
  • Smaller than 0: The value of the -info-th parameter is invalid.

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 */ 
    dgelqf_(&m, &n, a, &lda, tau, &qwork, &lwork, &info); 
    if (info != 0) { 
        return ERROR; 
    } 
    lwork = (int)qwork; 
    work = (double *)malloc(sizeof(double) * lwork); 
    /* Calculate LQ */ 
    dgelqf_(&m, &n, a, &lda, tau, work, &lwork, &info); 
    free(work); 
    /* 
     * Output: 
     * tau 
     *   1.867784        1.115696        1.413422        0.000000 
     * A output (stored in column-major) 
     *  -2.568611       -9.848324       -4.223656       -4.202616
     *  -7.832678       -9.363028       0.265340        5.150248
     *  5.402586        9.567440        4.194706        4.480431
     *  0.018134        -0.653528       -7.929047       -1.156667
     *  1.133611        -0.463361       0.007295        -0.604570
     *  0.644209        -2.887734       3.399866        4.103192
     */

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 DGELQF 
*       Query optimal work size 
        CALL DGELQF(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 LQ 
        CALL DGELQF(m, n, a, lda, tau, work, lwork, info) 
        DEALLOCATE(work) 
 
*       Output: 
*       tau 
*         1.867784        1.115696        1.413422        0.000000 
*       A output (stored in column-major) 
*        -2.568611       -9.848324       -4.223656       -4.202616
*        -7.832678       -9.363028       0.265340        5.150248
*        5.402586        9.567440        4.194706        4.480431
*        0.018134        -0.653528       -7.929047       -1.156667
*        1.133611        -0.463361       0.007295        -0.604570
*        0.644209        -2.887734       3.399866        4.103192