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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:44