sgeqp3.c
Go to the documentation of this file.
00001 /* sgeqp3.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 static integer c__3 = 3;
00021 static integer c__2 = 2;
00022 
00023 /* Subroutine */ int sgeqp3_(integer *m, integer *n, real *a, integer *lda, 
00024         integer *jpvt, real *tau, real *work, integer *lwork, integer *info)
00025 {
00026     /* System generated locals */
00027     integer a_dim1, a_offset, i__1, i__2, i__3;
00028 
00029     /* Local variables */
00030     integer j, jb, na, nb, sm, sn, nx, fjb, iws, nfxd;
00031     extern doublereal snrm2_(integer *, real *, integer *);
00032     integer nbmin, minmn, minws;
00033     extern /* Subroutine */ int sswap_(integer *, real *, integer *, real *, 
00034             integer *), slaqp2_(integer *, integer *, integer *, real *, 
00035             integer *, integer *, real *, real *, real *, real *), xerbla_(
00036             char *, integer *);
00037     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00038             integer *, integer *);
00039     extern /* Subroutine */ int sgeqrf_(integer *, integer *, real *, integer 
00040             *, real *, real *, integer *, integer *);
00041     integer topbmn, sminmn;
00042     extern /* Subroutine */ int slaqps_(integer *, integer *, integer *, 
00043             integer *, integer *, real *, integer *, integer *, real *, real *
00044 , real *, real *, real *, integer *);
00045     integer lwkopt;
00046     logical lquery;
00047     extern /* Subroutine */ int sormqr_(char *, char *, integer *, integer *, 
00048             integer *, real *, integer *, real *, real *, integer *, real *, 
00049             integer *, integer *);
00050 
00051 
00052 /*  -- LAPACK routine (version 3.2) -- */
00053 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00054 /*     November 2006 */
00055 
00056 /*     .. Scalar Arguments .. */
00057 /*     .. */
00058 /*     .. Array Arguments .. */
00059 /*     .. */
00060 
00061 /*  Purpose */
00062 /*  ======= */
00063 
00064 /*  SGEQP3 computes a QR factorization with column pivoting of a */
00065 /*  matrix A:  A*P = Q*R  using Level 3 BLAS. */
00066 
00067 /*  Arguments */
00068 /*  ========= */
00069 
00070 /*  M       (input) INTEGER */
00071 /*          The number of rows of the matrix A. M >= 0. */
00072 
00073 /*  N       (input) INTEGER */
00074 /*          The number of columns of the matrix A.  N >= 0. */
00075 
00076 /*  A       (input/output) REAL array, dimension (LDA,N) */
00077 /*          On entry, the M-by-N matrix A. */
00078 /*          On exit, the upper triangle of the array contains the */
00079 /*          min(M,N)-by-N upper trapezoidal matrix R; the elements below */
00080 /*          the diagonal, together with the array TAU, represent the */
00081 /*          orthogonal matrix Q as a product of min(M,N) elementary */
00082 /*          reflectors. */
00083 
00084 /*  LDA     (input) INTEGER */
00085 /*          The leading dimension of the array A. LDA >= max(1,M). */
00086 
00087 /*  JPVT    (input/output) INTEGER array, dimension (N) */
00088 /*          On entry, if JPVT(J).ne.0, the J-th column of A is permuted */
00089 /*          to the front of A*P (a leading column); if JPVT(J)=0, */
00090 /*          the J-th column of A is a free column. */
00091 /*          On exit, if JPVT(J)=K, then the J-th column of A*P was the */
00092 /*          the K-th column of A. */
00093 
00094 /*  TAU     (output) REAL array, dimension (min(M,N)) */
00095 /*          The scalar factors of the elementary reflectors. */
00096 
00097 /*  WORK    (workspace/output) REAL array, dimension (MAX(1,LWORK)) */
00098 /*          On exit, if INFO=0, WORK(1) returns the optimal LWORK. */
00099 
00100 /*  LWORK   (input) INTEGER */
00101 /*          The dimension of the array WORK. LWORK >= 3*N+1. */
00102 /*          For optimal performance LWORK >= 2*N+( N+1 )*NB, where NB */
00103 /*          is the optimal blocksize. */
00104 
00105 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00106 /*          only calculates the optimal size of the WORK array, returns */
00107 /*          this value as the first entry of the WORK array, and no error */
00108 /*          message related to LWORK is issued by XERBLA. */
00109 
00110 /*  INFO    (output) INTEGER */
00111 /*          = 0: successful exit. */
00112 /*          < 0: if INFO = -i, the i-th argument had an illegal value. */
00113 
00114 /*  Further Details */
00115 /*  =============== */
00116 
00117 /*  The matrix Q is represented as a product of elementary reflectors */
00118 
00119 /*     Q = H(1) H(2) . . . H(k), where k = min(m,n). */
00120 
00121 /*  Each H(i) has the form */
00122 
00123 /*     H(i) = I - tau * v * v' */
00124 
00125 /*  where tau is a real/complex scalar, and v is a real/complex vector */
00126 /*  with v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in */
00127 /*  A(i+1:m,i), and tau in TAU(i). */
00128 
00129 /*  Based on contributions by */
00130 /*    G. Quintana-Orti, Depto. de Informatica, Universidad Jaime I, Spain */
00131 /*    X. Sun, Computer Science Dept., Duke University, USA */
00132 
00133 /*  ===================================================================== */
00134 
00135 /*     .. Parameters .. */
00136 /*     .. */
00137 /*     .. Local Scalars .. */
00138 /*     .. */
00139 /*     .. External Subroutines .. */
00140 /*     .. */
00141 /*     .. External Functions .. */
00142 /*     .. */
00143 /*     .. Intrinsic Functions .. */
00144 /*     .. */
00145 /*     .. Executable Statements .. */
00146 
00147     /* Parameter adjustments */
00148     a_dim1 = *lda;
00149     a_offset = 1 + a_dim1;
00150     a -= a_offset;
00151     --jpvt;
00152     --tau;
00153     --work;
00154 
00155     /* Function Body */
00156     *info = 0;
00157     lquery = *lwork == -1;
00158     if (*m < 0) {
00159         *info = -1;
00160     } else if (*n < 0) {
00161         *info = -2;
00162     } else if (*lda < max(1,*m)) {
00163         *info = -4;
00164     }
00165 
00166     if (*info == 0) {
00167         minmn = min(*m,*n);
00168         if (minmn == 0) {
00169             iws = 1;
00170             lwkopt = 1;
00171         } else {
00172             iws = *n * 3 + 1;
00173             nb = ilaenv_(&c__1, "SGEQRF", " ", m, n, &c_n1, &c_n1);
00174             lwkopt = (*n << 1) + (*n + 1) * nb;
00175         }
00176         work[1] = (real) lwkopt;
00177 
00178         if (*lwork < iws && ! lquery) {
00179             *info = -8;
00180         }
00181     }
00182 
00183     if (*info != 0) {
00184         i__1 = -(*info);
00185         xerbla_("SGEQP3", &i__1);
00186         return 0;
00187     } else if (lquery) {
00188         return 0;
00189     }
00190 
00191 /*     Quick return if possible. */
00192 
00193     if (minmn == 0) {
00194         return 0;
00195     }
00196 
00197 /*     Move initial columns up front. */
00198 
00199     nfxd = 1;
00200     i__1 = *n;
00201     for (j = 1; j <= i__1; ++j) {
00202         if (jpvt[j] != 0) {
00203             if (j != nfxd) {
00204                 sswap_(m, &a[j * a_dim1 + 1], &c__1, &a[nfxd * a_dim1 + 1], &
00205                         c__1);
00206                 jpvt[j] = jpvt[nfxd];
00207                 jpvt[nfxd] = j;
00208             } else {
00209                 jpvt[j] = j;
00210             }
00211             ++nfxd;
00212         } else {
00213             jpvt[j] = j;
00214         }
00215 /* L10: */
00216     }
00217     --nfxd;
00218 
00219 /*     Factorize fixed columns */
00220 /*     ======================= */
00221 
00222 /*     Compute the QR factorization of fixed columns and update */
00223 /*     remaining columns. */
00224 
00225     if (nfxd > 0) {
00226         na = min(*m,nfxd);
00227 /* CC      CALL SGEQR2( M, NA, A, LDA, TAU, WORK, INFO ) */
00228         sgeqrf_(m, &na, &a[a_offset], lda, &tau[1], &work[1], lwork, info);
00229 /* Computing MAX */
00230         i__1 = iws, i__2 = (integer) work[1];
00231         iws = max(i__1,i__2);
00232         if (na < *n) {
00233 /* CC         CALL SORM2R( 'Left', 'Transpose', M, N-NA, NA, A, LDA, */
00234 /* CC  $                   TAU, A( 1, NA+1 ), LDA, WORK, INFO ) */
00235             i__1 = *n - na;
00236             sormqr_("Left", "Transpose", m, &i__1, &na, &a[a_offset], lda, &
00237                     tau[1], &a[(na + 1) * a_dim1 + 1], lda, &work[1], lwork, 
00238                     info);
00239 /* Computing MAX */
00240             i__1 = iws, i__2 = (integer) work[1];
00241             iws = max(i__1,i__2);
00242         }
00243     }
00244 
00245 /*     Factorize free columns */
00246 /*     ====================== */
00247 
00248     if (nfxd < minmn) {
00249 
00250         sm = *m - nfxd;
00251         sn = *n - nfxd;
00252         sminmn = minmn - nfxd;
00253 
00254 /*        Determine the block size. */
00255 
00256         nb = ilaenv_(&c__1, "SGEQRF", " ", &sm, &sn, &c_n1, &c_n1);
00257         nbmin = 2;
00258         nx = 0;
00259 
00260         if (nb > 1 && nb < sminmn) {
00261 
00262 /*           Determine when to cross over from blocked to unblocked code. */
00263 
00264 /* Computing MAX */
00265             i__1 = 0, i__2 = ilaenv_(&c__3, "SGEQRF", " ", &sm, &sn, &c_n1, &
00266                     c_n1);
00267             nx = max(i__1,i__2);
00268 
00269 
00270             if (nx < sminmn) {
00271 
00272 /*              Determine if workspace is large enough for blocked code. */
00273 
00274                 minws = (sn << 1) + (sn + 1) * nb;
00275                 iws = max(iws,minws);
00276                 if (*lwork < minws) {
00277 
00278 /*                 Not enough workspace to use optimal NB: Reduce NB and */
00279 /*                 determine the minimum value of NB. */
00280 
00281                     nb = (*lwork - (sn << 1)) / (sn + 1);
00282 /* Computing MAX */
00283                     i__1 = 2, i__2 = ilaenv_(&c__2, "SGEQRF", " ", &sm, &sn, &
00284                             c_n1, &c_n1);
00285                     nbmin = max(i__1,i__2);
00286 
00287 
00288                 }
00289             }
00290         }
00291 
00292 /*        Initialize partial column norms. The first N elements of work */
00293 /*        store the exact column norms. */
00294 
00295         i__1 = *n;
00296         for (j = nfxd + 1; j <= i__1; ++j) {
00297             work[j] = snrm2_(&sm, &a[nfxd + 1 + j * a_dim1], &c__1);
00298             work[*n + j] = work[j];
00299 /* L20: */
00300         }
00301 
00302         if (nb >= nbmin && nb < sminmn && nx < sminmn) {
00303 
00304 /*           Use blocked code initially. */
00305 
00306             j = nfxd + 1;
00307 
00308 /*           Compute factorization: while loop. */
00309 
00310 
00311             topbmn = minmn - nx;
00312 L30:
00313             if (j <= topbmn) {
00314 /* Computing MIN */
00315                 i__1 = nb, i__2 = topbmn - j + 1;
00316                 jb = min(i__1,i__2);
00317 
00318 /*              Factorize JB columns among columns J:N. */
00319 
00320                 i__1 = *n - j + 1;
00321                 i__2 = j - 1;
00322                 i__3 = *n - j + 1;
00323                 slaqps_(m, &i__1, &i__2, &jb, &fjb, &a[j * a_dim1 + 1], lda, &
00324                         jpvt[j], &tau[j], &work[j], &work[*n + j], &work[(*n 
00325                         << 1) + 1], &work[(*n << 1) + jb + 1], &i__3);
00326 
00327                 j += fjb;
00328                 goto L30;
00329             }
00330         } else {
00331             j = nfxd + 1;
00332         }
00333 
00334 /*        Use unblocked code to factor the last or only block. */
00335 
00336 
00337         if (j <= minmn) {
00338             i__1 = *n - j + 1;
00339             i__2 = j - 1;
00340             slaqp2_(m, &i__1, &i__2, &a[j * a_dim1 + 1], lda, &jpvt[j], &tau[
00341                     j], &work[j], &work[*n + j], &work[(*n << 1) + 1]);
00342         }
00343 
00344     }
00345 
00346     work[1] = (real) iws;
00347     return 0;
00348 
00349 /*     End of SGEQP3 */
00350 
00351 } /* sgeqp3_ */


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