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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:08