| 1 |
SUBROUTINE SGERQ2( M, N, A, LDA, TAU, WORK, INFO ) |
| 2 |
* |
| 3 |
* -- LAPACK routine (version 3.0) -- |
| 4 |
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., |
| 5 |
* Courant Institute, Argonne National Lab, and Rice University |
| 6 |
* February 29, 1992 |
| 7 |
* |
| 8 |
* .. Scalar Arguments .. |
| 9 |
INTEGER INFO, LDA, M, N |
| 10 |
* .. |
| 11 |
* .. Array Arguments .. |
| 12 |
REAL A( LDA, * ), TAU( * ), WORK( * ) |
| 13 |
* .. |
| 14 |
* |
| 15 |
* Purpose |
| 16 |
* ======= |
| 17 |
* |
| 18 |
* SGERQ2 computes an RQ factorization of a real m by n matrix A: |
| 19 |
* A = R * Q. |
| 20 |
* |
| 21 |
* Arguments |
| 22 |
* ========= |
| 23 |
* |
| 24 |
* M (input) INTEGER |
| 25 |
* The number of rows of the matrix A. M >= 0. |
| 26 |
* |
| 27 |
* N (input) INTEGER |
| 28 |
* The number of columns of the matrix A. N >= 0. |
| 29 |
* |
| 30 |
* A (input/output) REAL array, dimension (LDA,N) |
| 31 |
* On entry, the m by n matrix A. |
| 32 |
* On exit, if m <= n, the upper triangle of the subarray |
| 33 |
* A(1:m,n-m+1:n) contains the m by m upper triangular matrix R; |
| 34 |
* if m >= n, the elements on and above the (m-n)-th subdiagonal |
| 35 |
* contain the m by n upper trapezoidal matrix R; the remaining |
| 36 |
* elements, with the array TAU, represent the orthogonal matrix |
| 37 |
* Q as a product of elementary reflectors (see Further |
| 38 |
* Details). |
| 39 |
* |
| 40 |
* LDA (input) INTEGER |
| 41 |
* The leading dimension of the array A. LDA >= max(1,M). |
| 42 |
* |
| 43 |
* TAU (output) REAL array, dimension (min(M,N)) |
| 44 |
* The scalar factors of the elementary reflectors (see Further |
| 45 |
* Details). |
| 46 |
* |
| 47 |
* WORK (workspace) REAL array, dimension (M) |
| 48 |
* |
| 49 |
* INFO (output) INTEGER |
| 50 |
* = 0: successful exit |
| 51 |
* < 0: if INFO = -i, the i-th argument had an illegal value |
| 52 |
* |
| 53 |
* Further Details |
| 54 |
* =============== |
| 55 |
* |
| 56 |
* The matrix Q is represented as a product of elementary reflectors |
| 57 |
* |
| 58 |
* Q = H(1) H(2) . . . H(k), where k = min(m,n). |
| 59 |
* |
| 60 |
* Each H(i) has the form |
| 61 |
* |
| 62 |
* H(i) = I - tau * v * v' |
| 63 |
* |
| 64 |
* where tau is a real scalar, and v is a real vector with |
| 65 |
* v(n-k+i+1:n) = 0 and v(n-k+i) = 1; v(1:n-k+i-1) is stored on exit in |
| 66 |
* A(m-k+i,1:n-k+i-1), and tau in TAU(i). |
| 67 |
* |
| 68 |
* ===================================================================== |
| 69 |
* |
| 70 |
* .. Parameters .. |
| 71 |
REAL ONE |
| 72 |
PARAMETER ( ONE = 1.0E+0 ) |
| 73 |
* .. |
| 74 |
* .. Local Scalars .. |
| 75 |
INTEGER I, K |
| 76 |
REAL AII |
| 77 |
* .. |
| 78 |
* .. External Subroutines .. |
| 79 |
EXTERNAL SLARF, SLARFG, XERBLA |
| 80 |
* .. |
| 81 |
* .. Intrinsic Functions .. |
| 82 |
INTRINSIC MAX, MIN |
| 83 |
* .. |
| 84 |
* .. Executable Statements .. |
| 85 |
* |
| 86 |
* Test the input arguments |
| 87 |
* |
| 88 |
INFO = 0 |
| 89 |
IF( M.LT.0 ) THEN |
| 90 |
INFO = -1 |
| 91 |
ELSE IF( N.LT.0 ) THEN |
| 92 |
INFO = -2 |
| 93 |
ELSE IF( LDA.LT.MAX( 1, M ) ) THEN |
| 94 |
INFO = -4 |
| 95 |
END IF |
| 96 |
IF( INFO.NE.0 ) THEN |
| 97 |
CALL XERBLA( 'SGERQ2', -INFO ) |
| 98 |
RETURN |
| 99 |
END IF |
| 100 |
* |
| 101 |
K = MIN( M, N ) |
| 102 |
* |
| 103 |
DO 10 I = K, 1, -1 |
| 104 |
* |
| 105 |
* Generate elementary reflector H(i) to annihilate |
| 106 |
* A(m-k+i,1:n-k+i-1) |
| 107 |
* |
| 108 |
CALL SLARFG( N-K+I, A( M-K+I, N-K+I ), A( M-K+I, 1 ), LDA, |
| 109 |
$ TAU( I ) ) |
| 110 |
* |
| 111 |
* Apply H(i) to A(1:m-k+i-1,1:n-k+i) from the right |
| 112 |
* |
| 113 |
AII = A( M-K+I, N-K+I ) |
| 114 |
A( M-K+I, N-K+I ) = ONE |
| 115 |
CALL SLARF( 'Right', M-K+I-1, N-K+I, A( M-K+I, 1 ), LDA, |
| 116 |
$ TAU( I ), A, LDA, WORK ) |
| 117 |
A( M-K+I, N-K+I ) = AII |
| 118 |
10 CONTINUE |
| 119 |
RETURN |
| 120 |
* |
| 121 |
* End of SGERQ2 |
| 122 |
* |
| 123 |
END |