00001 /* sgerq2.f -- translated by f2c (version 20061008). 00002 You must link the resulting object file with libf2c: 00003 on Microsoft Windows system, link with libf2c.lib; 00004 on Linux or Unix systems, link with .../path/to/libf2c.a -lm 00005 or, if you install libf2c.a in a standard place, with -lf2c -lm 00006 -- in that order, at the end of the command line, as in 00007 cc *.o -lf2c -lm 00008 Source for libf2c is in /netlib/f2c/libf2c.zip, e.g., 00009 00010 http://www.netlib.org/f2c/libf2c.zip 00011 */ 00012 00013 #include "f2c.h" 00014 #include "blaswrap.h" 00015 00016 /* Subroutine */ int sgerq2_(integer *m, integer *n, real *a, integer *lda, 00017 real *tau, real *work, integer *info) 00018 { 00019 /* System generated locals */ 00020 integer a_dim1, a_offset, i__1, i__2; 00021 00022 /* Local variables */ 00023 integer i__, k; 00024 real aii; 00025 extern /* Subroutine */ int slarf_(char *, integer *, integer *, real *, 00026 integer *, real *, real *, integer *, real *), xerbla_( 00027 char *, integer *), slarfp_(integer *, real *, real *, 00028 integer *, real *); 00029 00030 00031 /* -- LAPACK routine (version 3.2) -- */ 00032 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00033 /* November 2006 */ 00034 00035 /* .. Scalar Arguments .. */ 00036 /* .. */ 00037 /* .. Array Arguments .. */ 00038 /* .. */ 00039 00040 /* Purpose */ 00041 /* ======= */ 00042 00043 /* SGERQ2 computes an RQ factorization of a real m by n matrix A: */ 00044 /* A = R * Q. */ 00045 00046 /* Arguments */ 00047 /* ========= */ 00048 00049 /* M (input) INTEGER */ 00050 /* The number of rows of the matrix A. M >= 0. */ 00051 00052 /* N (input) INTEGER */ 00053 /* The number of columns of the matrix A. N >= 0. */ 00054 00055 /* A (input/output) REAL array, dimension (LDA,N) */ 00056 /* On entry, the m by n matrix A. */ 00057 /* On exit, if m <= n, the upper triangle of the subarray */ 00058 /* A(1:m,n-m+1:n) contains the m by m upper triangular matrix R; */ 00059 /* if m >= n, the elements on and above the (m-n)-th subdiagonal */ 00060 /* contain the m by n upper trapezoidal matrix R; the remaining */ 00061 /* elements, with the array TAU, represent the orthogonal matrix */ 00062 /* Q as a product of elementary reflectors (see Further */ 00063 /* Details). */ 00064 00065 /* LDA (input) INTEGER */ 00066 /* The leading dimension of the array A. LDA >= max(1,M). */ 00067 00068 /* TAU (output) REAL array, dimension (min(M,N)) */ 00069 /* The scalar factors of the elementary reflectors (see Further */ 00070 /* Details). */ 00071 00072 /* WORK (workspace) REAL array, dimension (M) */ 00073 00074 /* INFO (output) INTEGER */ 00075 /* = 0: successful exit */ 00076 /* < 0: if INFO = -i, the i-th argument had an illegal value */ 00077 00078 /* Further Details */ 00079 /* =============== */ 00080 00081 /* The matrix Q is represented as a product of elementary reflectors */ 00082 00083 /* Q = H(1) H(2) . . . H(k), where k = min(m,n). */ 00084 00085 /* Each H(i) has the form */ 00086 00087 /* H(i) = I - tau * v * v' */ 00088 00089 /* where tau is a real scalar, and v is a real vector with */ 00090 /* v(n-k+i+1:n) = 0 and v(n-k+i) = 1; v(1:n-k+i-1) is stored on exit in */ 00091 /* A(m-k+i,1:n-k+i-1), and tau in TAU(i). */ 00092 00093 /* ===================================================================== */ 00094 00095 /* .. Parameters .. */ 00096 /* .. */ 00097 /* .. Local Scalars .. */ 00098 /* .. */ 00099 /* .. External Subroutines .. */ 00100 /* .. */ 00101 /* .. Intrinsic Functions .. */ 00102 /* .. */ 00103 /* .. Executable Statements .. */ 00104 00105 /* Test the input arguments */ 00106 00107 /* Parameter adjustments */ 00108 a_dim1 = *lda; 00109 a_offset = 1 + a_dim1; 00110 a -= a_offset; 00111 --tau; 00112 --work; 00113 00114 /* Function Body */ 00115 *info = 0; 00116 if (*m < 0) { 00117 *info = -1; 00118 } else if (*n < 0) { 00119 *info = -2; 00120 } else if (*lda < max(1,*m)) { 00121 *info = -4; 00122 } 00123 if (*info != 0) { 00124 i__1 = -(*info); 00125 xerbla_("SGERQ2", &i__1); 00126 return 0; 00127 } 00128 00129 k = min(*m,*n); 00130 00131 for (i__ = k; i__ >= 1; --i__) { 00132 00133 /* Generate elementary reflector H(i) to annihilate */ 00134 /* A(m-k+i,1:n-k+i-1) */ 00135 00136 i__1 = *n - k + i__; 00137 slarfp_(&i__1, &a[*m - k + i__ + (*n - k + i__) * a_dim1], &a[*m - k 00138 + i__ + a_dim1], lda, &tau[i__]); 00139 00140 /* Apply H(i) to A(1:m-k+i-1,1:n-k+i) from the right */ 00141 00142 aii = a[*m - k + i__ + (*n - k + i__) * a_dim1]; 00143 a[*m - k + i__ + (*n - k + i__) * a_dim1] = 1.f; 00144 i__1 = *m - k + i__ - 1; 00145 i__2 = *n - k + i__; 00146 slarf_("Right", &i__1, &i__2, &a[*m - k + i__ + a_dim1], lda, &tau[ 00147 i__], &a[a_offset], lda, &work[1]); 00148 a[*m - k + i__ + (*n - k + i__) * a_dim1] = aii; 00149 /* L10: */ 00150 } 00151 return 0; 00152 00153 /* End of SGERQ2 */ 00154 00155 } /* sgerq2_ */