00001 /* sggrqf.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 /* Table of constant values */ 00017 00018 static integer c__1 = 1; 00019 static integer c_n1 = -1; 00020 00021 /* Subroutine */ int sggrqf_(integer *m, integer *p, integer *n, real *a, 00022 integer *lda, real *taua, real *b, integer *ldb, real *taub, real * 00023 work, integer *lwork, integer *info) 00024 { 00025 /* System generated locals */ 00026 integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3; 00027 00028 /* Local variables */ 00029 integer nb, nb1, nb2, nb3, lopt; 00030 extern /* Subroutine */ int xerbla_(char *, integer *); 00031 extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 00032 integer *, integer *); 00033 extern /* Subroutine */ int sgeqrf_(integer *, integer *, real *, integer 00034 *, real *, real *, integer *, integer *), sgerqf_(integer *, 00035 integer *, real *, integer *, real *, real *, integer *, integer * 00036 ); 00037 integer lwkopt; 00038 logical lquery; 00039 extern /* Subroutine */ int sormrq_(char *, char *, integer *, integer *, 00040 integer *, real *, integer *, real *, real *, integer *, real *, 00041 integer *, integer *); 00042 00043 00044 /* -- LAPACK routine (version 3.2) -- */ 00045 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00046 /* November 2006 */ 00047 00048 /* .. Scalar Arguments .. */ 00049 /* .. */ 00050 /* .. Array Arguments .. */ 00051 /* .. */ 00052 00053 /* Purpose */ 00054 /* ======= */ 00055 00056 /* SGGRQF computes a generalized RQ factorization of an M-by-N matrix A */ 00057 /* and a P-by-N matrix B: */ 00058 00059 /* A = R*Q, B = Z*T*Q, */ 00060 00061 /* where Q is an N-by-N orthogonal matrix, Z is a P-by-P orthogonal */ 00062 /* matrix, and R and T assume one of the forms: */ 00063 00064 /* if M <= N, R = ( 0 R12 ) M, or if M > N, R = ( R11 ) M-N, */ 00065 /* N-M M ( R21 ) N */ 00066 /* N */ 00067 00068 /* where R12 or R21 is upper triangular, and */ 00069 00070 /* if P >= N, T = ( T11 ) N , or if P < N, T = ( T11 T12 ) P, */ 00071 /* ( 0 ) P-N P N-P */ 00072 /* N */ 00073 00074 /* where T11 is upper triangular. */ 00075 00076 /* In particular, if B is square and nonsingular, the GRQ factorization */ 00077 /* of A and B implicitly gives the RQ factorization of A*inv(B): */ 00078 00079 /* A*inv(B) = (R*inv(T))*Z' */ 00080 00081 /* where inv(B) denotes the inverse of the matrix B, and Z' denotes the */ 00082 /* transpose of the matrix Z. */ 00083 00084 /* Arguments */ 00085 /* ========= */ 00086 00087 /* M (input) INTEGER */ 00088 /* The number of rows of the matrix A. M >= 0. */ 00089 00090 /* P (input) INTEGER */ 00091 /* The number of rows of the matrix B. P >= 0. */ 00092 00093 /* N (input) INTEGER */ 00094 /* The number of columns of the matrices A and B. N >= 0. */ 00095 00096 /* A (input/output) REAL array, dimension (LDA,N) */ 00097 /* On entry, the M-by-N matrix A. */ 00098 /* On exit, if M <= N, the upper triangle of the subarray */ 00099 /* A(1:M,N-M+1:N) contains the M-by-M upper triangular matrix R; */ 00100 /* if M > N, the elements on and above the (M-N)-th subdiagonal */ 00101 /* contain the M-by-N upper trapezoidal matrix R; the remaining */ 00102 /* elements, with the array TAUA, represent the orthogonal */ 00103 /* matrix Q as a product of elementary reflectors (see Further */ 00104 /* Details). */ 00105 00106 /* LDA (input) INTEGER */ 00107 /* The leading dimension of the array A. LDA >= max(1,M). */ 00108 00109 /* TAUA (output) REAL array, dimension (min(M,N)) */ 00110 /* The scalar factors of the elementary reflectors which */ 00111 /* represent the orthogonal matrix Q (see Further Details). */ 00112 00113 /* B (input/output) REAL array, dimension (LDB,N) */ 00114 /* On entry, the P-by-N matrix B. */ 00115 /* On exit, the elements on and above the diagonal of the array */ 00116 /* contain the min(P,N)-by-N upper trapezoidal matrix T (T is */ 00117 /* upper triangular if P >= N); the elements below the diagonal, */ 00118 /* with the array TAUB, represent the orthogonal matrix Z as a */ 00119 /* product of elementary reflectors (see Further Details). */ 00120 00121 /* LDB (input) INTEGER */ 00122 /* The leading dimension of the array B. LDB >= max(1,P). */ 00123 00124 /* TAUB (output) REAL array, dimension (min(P,N)) */ 00125 /* The scalar factors of the elementary reflectors which */ 00126 /* represent the orthogonal matrix Z (see Further Details). */ 00127 00128 /* WORK (workspace/output) REAL array, dimension (MAX(1,LWORK)) */ 00129 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ 00130 00131 /* LWORK (input) INTEGER */ 00132 /* The dimension of the array WORK. LWORK >= max(1,N,M,P). */ 00133 /* For optimum performance LWORK >= max(N,M,P)*max(NB1,NB2,NB3), */ 00134 /* where NB1 is the optimal blocksize for the RQ factorization */ 00135 /* of an M-by-N matrix, NB2 is the optimal blocksize for the */ 00136 /* QR factorization of a P-by-N matrix, and NB3 is the optimal */ 00137 /* blocksize for a call of SORMRQ. */ 00138 00139 /* If LWORK = -1, then a workspace query is assumed; the routine */ 00140 /* only calculates the optimal size of the WORK array, returns */ 00141 /* this value as the first entry of the WORK array, and no error */ 00142 /* message related to LWORK is issued by XERBLA. */ 00143 00144 /* INFO (output) INTEGER */ 00145 /* = 0: successful exit */ 00146 /* < 0: if INF0= -i, the i-th argument had an illegal value. */ 00147 00148 /* Further Details */ 00149 /* =============== */ 00150 00151 /* The matrix Q is represented as a product of elementary reflectors */ 00152 00153 /* Q = H(1) H(2) . . . H(k), where k = min(m,n). */ 00154 00155 /* Each H(i) has the form */ 00156 00157 /* H(i) = I - taua * v * v' */ 00158 00159 /* where taua is a real scalar, and v is a real vector with */ 00160 /* v(n-k+i+1:n) = 0 and v(n-k+i) = 1; v(1:n-k+i-1) is stored on exit in */ 00161 /* A(m-k+i,1:n-k+i-1), and taua in TAUA(i). */ 00162 /* To form Q explicitly, use LAPACK subroutine SORGRQ. */ 00163 /* To use Q to update another matrix, use LAPACK subroutine SORMRQ. */ 00164 00165 /* The matrix Z is represented as a product of elementary reflectors */ 00166 00167 /* Z = H(1) H(2) . . . H(k), where k = min(p,n). */ 00168 00169 /* Each H(i) has the form */ 00170 00171 /* H(i) = I - taub * v * v' */ 00172 00173 /* where taub is a real scalar, and v is a real vector with */ 00174 /* v(1:i-1) = 0 and v(i) = 1; v(i+1:p) is stored on exit in B(i+1:p,i), */ 00175 /* and taub in TAUB(i). */ 00176 /* To form Z explicitly, use LAPACK subroutine SORGQR. */ 00177 /* To use Z to update another matrix, use LAPACK subroutine SORMQR. */ 00178 00179 /* ===================================================================== */ 00180 00181 /* .. Local Scalars .. */ 00182 /* .. */ 00183 /* .. External Subroutines .. */ 00184 /* .. */ 00185 /* .. External Functions .. */ 00186 /* .. */ 00187 /* .. Intrinsic Functions .. */ 00188 /* .. */ 00189 /* .. Executable Statements .. */ 00190 00191 /* Test the input parameters */ 00192 00193 /* Parameter adjustments */ 00194 a_dim1 = *lda; 00195 a_offset = 1 + a_dim1; 00196 a -= a_offset; 00197 --taua; 00198 b_dim1 = *ldb; 00199 b_offset = 1 + b_dim1; 00200 b -= b_offset; 00201 --taub; 00202 --work; 00203 00204 /* Function Body */ 00205 *info = 0; 00206 nb1 = ilaenv_(&c__1, "SGERQF", " ", m, n, &c_n1, &c_n1); 00207 nb2 = ilaenv_(&c__1, "SGEQRF", " ", p, n, &c_n1, &c_n1); 00208 nb3 = ilaenv_(&c__1, "SORMRQ", " ", m, n, p, &c_n1); 00209 /* Computing MAX */ 00210 i__1 = max(nb1,nb2); 00211 nb = max(i__1,nb3); 00212 /* Computing MAX */ 00213 i__1 = max(*n,*m); 00214 lwkopt = max(i__1,*p) * nb; 00215 work[1] = (real) lwkopt; 00216 lquery = *lwork == -1; 00217 if (*m < 0) { 00218 *info = -1; 00219 } else if (*p < 0) { 00220 *info = -2; 00221 } else if (*n < 0) { 00222 *info = -3; 00223 } else if (*lda < max(1,*m)) { 00224 *info = -5; 00225 } else if (*ldb < max(1,*p)) { 00226 *info = -8; 00227 } else /* if(complicated condition) */ { 00228 /* Computing MAX */ 00229 i__1 = max(1,*m), i__1 = max(i__1,*p); 00230 if (*lwork < max(i__1,*n) && ! lquery) { 00231 *info = -11; 00232 } 00233 } 00234 if (*info != 0) { 00235 i__1 = -(*info); 00236 xerbla_("SGGRQF", &i__1); 00237 return 0; 00238 } else if (lquery) { 00239 return 0; 00240 } 00241 00242 /* RQ factorization of M-by-N matrix A: A = R*Q */ 00243 00244 sgerqf_(m, n, &a[a_offset], lda, &taua[1], &work[1], lwork, info); 00245 lopt = work[1]; 00246 00247 /* Update B := B*Q' */ 00248 00249 i__1 = min(*m,*n); 00250 /* Computing MAX */ 00251 i__2 = 1, i__3 = *m - *n + 1; 00252 sormrq_("Right", "Transpose", p, n, &i__1, &a[max(i__2, i__3)+ a_dim1], 00253 lda, &taua[1], &b[b_offset], ldb, &work[1], lwork, info); 00254 /* Computing MAX */ 00255 i__1 = lopt, i__2 = (integer) work[1]; 00256 lopt = max(i__1,i__2); 00257 00258 /* QR factorization of P-by-N matrix B: B = Z*T */ 00259 00260 sgeqrf_(p, n, &b[b_offset], ldb, &taub[1], &work[1], lwork, info); 00261 /* Computing MAX */ 00262 i__1 = lopt, i__2 = (integer) work[1]; 00263 work[1] = (real) max(i__1,i__2); 00264 00265 return 0; 00266 00267 /* End of SGGRQF */ 00268 00269 } /* sggrqf_ */