zgeqrf.c
Go to the documentation of this file.
00001 /* zgeqrf.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 zgeqrf_(integer *m, integer *n, doublecomplex *a, 
00024         integer *lda, doublecomplex *tau, doublecomplex *work, integer *lwork, 
00025          integer *info)
00026 {
00027     /* System generated locals */
00028     integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5, i__6;
00029     real r__1;
00030 
00031     /* Local variables */
00032     integer i__, j, k, ib, nb, nt, nx, iws;
00033     extern doublereal sceil_(real *);
00034     integer nbmin, iinfo;
00035     extern /* Subroutine */ int zgeqr2_(integer *, integer *, doublecomplex *, 
00036              integer *, doublecomplex *, doublecomplex *, integer *), xerbla_(
00037             char *, integer *);
00038     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00039             integer *, integer *);
00040     extern /* Subroutine */ int zlarfb_(char *, char *, char *, char *, 
00041             integer *, integer *, integer *, doublecomplex *, integer *, 
00042             doublecomplex *, integer *, doublecomplex *, integer *, 
00043             doublecomplex *, integer *);
00044     integer lbwork;
00045     extern /* Subroutine */ int zlarft_(char *, char *, integer *, integer *, 
00046             doublecomplex *, integer *, doublecomplex *, doublecomplex *, 
00047             integer *);
00048     integer llwork, lwkopt;
00049     logical lquery;
00050 
00051 
00052 /*  -- LAPACK routine (version 3.1) -- */
00053 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00054 /*     March 2008 */
00055 
00056 /*     .. Scalar Arguments .. */
00057 /*     .. */
00058 /*     .. Array Arguments .. */
00059 /*     .. */
00060 
00061 /*  Purpose */
00062 /*  ======= */
00063 
00064 /*  ZGEQRF computes a QR factorization of a real M-by-N matrix A: */
00065 /*  A = Q * R. */
00066 
00067 /*  This is the left-looking Level 3 BLAS version of the algorithm. */
00068 
00069 /*  Arguments */
00070 /*  ========= */
00071 
00072 /*  M       (input) INTEGER */
00073 /*          The number of rows of the matrix A.  M >= 0. */
00074 
00075 /*  N       (input) INTEGER */
00076 /*          The number of columns of the matrix A.  N >= 0. */
00077 
00078 /*  A       (input/output) COMPLEX*16 array, dimension (LDA,N) */
00079 /*          On entry, the M-by-N matrix A. */
00080 /*          On exit, the elements on and above the diagonal of the array */
00081 /*          contain the min(M,N)-by-N upper trapezoidal matrix R (R is */
00082 /*          upper triangular if m >= n); the elements below the diagonal, */
00083 /*          with the array TAU, represent the orthogonal matrix Q as a */
00084 /*          product of min(m,n) elementary reflectors (see Further */
00085 /*          Details). */
00086 
00087 /*  LDA     (input) INTEGER */
00088 /*          The leading dimension of the array A.  LDA >= max(1,M). */
00089 
00090 /*  TAU     (output) COMPLEX*16 array, dimension (min(M,N)) */
00091 /*          The scalar factors of the elementary reflectors (see Further */
00092 /*          Details). */
00093 
00094 /*  WORK    (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */
00095 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00096 
00097 /*  LWORK   (input) INTEGER */
00098 
00099 /*          The dimension of the array WORK. The dimension can be divided into three parts. */
00100 
00101 /*          1) The part for the triangular factor T. If the very last T is not bigger */
00102 /*             than any of the rest, then this part is NB x ceiling(K/NB), otherwise, */
00103 /*             NB x (K-NT), where K = min(M,N) and NT is the dimension of the very last T */
00104 
00105 /*          2) The part for the very last T when T is bigger than any of the rest T. */
00106 /*             The size of this part is NT x NT, where NT = K - ceiling ((K-NX)/NB) x NB, */
00107 /*             where K = min(M,N), NX is calculated by */
00108 /*                   NX = MAX( 0, ILAENV( 3, 'ZGEQRF', ' ', M, N, -1, -1 ) ) */
00109 
00110 /*          3) The part for dlarfb is of size max((N-M)*K, (N-M)*NB, K*NB, NB*NB) */
00111 
00112 /*          So LWORK = part1 + part2 + part3 */
00113 
00114 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00115 /*          only calculates the optimal size of the WORK array, returns */
00116 /*          this value as the first entry of the WORK array, and no error */
00117 /*          message related to LWORK is issued by XERBLA. */
00118 
00119 /*  INFO    (output) INTEGER */
00120 /*          = 0:  successful exit */
00121 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00122 
00123 /*  Further Details */
00124 /*  =============== */
00125 
00126 /*  The matrix Q is represented as a product of elementary reflectors */
00127 
00128 /*     Q = H(1) H(2) . . . H(k), where k = min(m,n). */
00129 
00130 /*  Each H(i) has the form */
00131 
00132 /*     H(i) = I - tau * v * v' */
00133 
00134 /*  where tau is a real scalar, and v is a real vector with */
00135 /*  v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i), */
00136 /*  and tau in TAU(i). */
00137 
00138 /*  ===================================================================== */
00139 
00140 /*     .. Local Scalars .. */
00141 /*     .. */
00142 /*     .. External Subroutines .. */
00143 /*     .. */
00144 /*     .. Intrinsic Functions .. */
00145 /*     .. */
00146 /*     .. External Functions .. */
00147 /*     .. */
00148 /*     .. Executable Statements .. */
00149     /* Parameter adjustments */
00150     a_dim1 = *lda;
00151     a_offset = 1 + a_dim1;
00152     a -= a_offset;
00153     --tau;
00154     --work;
00155 
00156     /* Function Body */
00157     *info = 0;
00158     nbmin = 2;
00159     nx = 0;
00160     iws = *n;
00161     k = min(*m,*n);
00162     nb = ilaenv_(&c__1, "ZGEQRF", " ", m, n, &c_n1, &c_n1);
00163     if (nb > 1 && nb < k) {
00164 
00165 /*        Determine when to cross over from blocked to unblocked code. */
00166 
00167 /* Computing MAX */
00168         i__1 = 0, i__2 = ilaenv_(&c__3, "ZGEQRF", " ", m, n, &c_n1, &c_n1);
00169         nx = max(i__1,i__2);
00170     }
00171 
00172 /*     Get NT, the size of the very last T, which is the left-over from in-between K-NX and K to K, eg.: */
00173 
00174 /*            NB=3     2NB=6       K=10 */
00175 /*            |        |           | */
00176 /*      1--2--3--4--5--6--7--8--9--10 */
00177 /*                  |     \________/ */
00178 /*               K-NX=5      NT=4 */
00179 
00180 /*     So here 4 x 4 is the last T stored in the workspace */
00181 
00182     r__1 = (real) (k - nx) / (real) nb;
00183     nt = k - sceil_(&r__1) * nb;
00184 
00185 /*     optimal workspace = space for dlarfb + space for normal T's + space for the last T */
00186 
00187 /* Computing MAX */
00188 /* Computing MAX */
00189     i__3 = (*n - *m) * k, i__4 = (*n - *m) * nb;
00190 /* Computing MAX */
00191     i__5 = k * nb, i__6 = nb * nb;
00192     i__1 = max(i__3,i__4), i__2 = max(i__5,i__6);
00193     llwork = max(i__1,i__2);
00194     r__1 = (real) llwork / (real) nb;
00195     llwork = sceil_(&r__1);
00196     if (nt > nb) {
00197         lbwork = k - nt;
00198 
00199 /*         Optimal workspace for dlarfb = MAX(1,N)*NT */
00200 
00201         lwkopt = (lbwork + llwork) * nb;
00202         i__1 = lwkopt + nt * nt;
00203         work[1].r = (doublereal) i__1, work[1].i = 0.;
00204     } else {
00205         r__1 = (real) k / (real) nb;
00206         lbwork = sceil_(&r__1) * nb;
00207         lwkopt = (lbwork + llwork - nb) * nb;
00208         work[1].r = (doublereal) lwkopt, work[1].i = 0.;
00209     }
00210 
00211 /*     Test the input arguments */
00212 
00213     lquery = *lwork == -1;
00214     if (*m < 0) {
00215         *info = -1;
00216     } else if (*n < 0) {
00217         *info = -2;
00218     } else if (*lda < max(1,*m)) {
00219         *info = -4;
00220     } else if (*lwork < max(1,*n) && ! lquery) {
00221         *info = -7;
00222     }
00223     if (*info != 0) {
00224         i__1 = -(*info);
00225         xerbla_("ZGEQRF", &i__1);
00226         return 0;
00227     } else if (lquery) {
00228         return 0;
00229     }
00230 
00231 /*     Quick return if possible */
00232 
00233     if (k == 0) {
00234         work[1].r = 1., work[1].i = 0.;
00235         return 0;
00236     }
00237 
00238     if (nb > 1 && nb < k) {
00239         if (nx < k) {
00240 
00241 /*           Determine if workspace is large enough for blocked code. */
00242 
00243             if (nt <= nb) {
00244                 iws = (lbwork + llwork - nb) * nb;
00245             } else {
00246                 iws = (lbwork + llwork) * nb + nt * nt;
00247             }
00248             if (*lwork < iws) {
00249 
00250 /*              Not enough workspace to use optimal NB:  reduce NB and */
00251 /*              determine the minimum value of NB. */
00252 
00253                 if (nt <= nb) {
00254                     nb = *lwork / (llwork + (lbwork - nb));
00255                 } else {
00256                     nb = (*lwork - nt * nt) / (lbwork + llwork);
00257                 }
00258 /* Computing MAX */
00259                 i__1 = 2, i__2 = ilaenv_(&c__2, "ZGEQRF", " ", m, n, &c_n1, &
00260                         c_n1);
00261                 nbmin = max(i__1,i__2);
00262             }
00263         }
00264     }
00265 
00266     if (nb >= nbmin && nb < k && nx < k) {
00267 
00268 /*        Use blocked code initially */
00269 
00270         i__1 = k - nx;
00271         i__2 = nb;
00272         for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
00273 /* Computing MIN */
00274             i__3 = k - i__ + 1;
00275             ib = min(i__3,nb);
00276 
00277 /*           Update the current column using old T's */
00278 
00279             i__3 = i__ - nb;
00280             i__4 = nb;
00281             for (j = 1; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) {
00282 
00283 /*              Apply H' to A(J:M,I:I+IB-1) from the left */
00284 
00285                 i__5 = *m - j + 1;
00286                 zlarfb_("Left", "Transpose", "Forward", "Columnwise", &i__5, &
00287                         ib, &nb, &a[j + j * a_dim1], lda, &work[j], &lbwork, &
00288                         a[j + i__ * a_dim1], lda, &work[lbwork * nb + nt * nt 
00289                         + 1], &ib);
00290 /* L20: */
00291             }
00292 
00293 /*           Compute the QR factorization of the current block */
00294 /*           A(I:M,I:I+IB-1) */
00295 
00296             i__4 = *m - i__ + 1;
00297             zgeqr2_(&i__4, &ib, &a[i__ + i__ * a_dim1], lda, &tau[i__], &work[
00298                     lbwork * nb + nt * nt + 1], &iinfo);
00299             if (i__ + ib <= *n) {
00300 
00301 /*              Form the triangular factor of the block reflector */
00302 /*              H = H(i) H(i+1) . . . H(i+ib-1) */
00303 
00304                 i__4 = *m - i__ + 1;
00305                 zlarft_("Forward", "Columnwise", &i__4, &ib, &a[i__ + i__ * 
00306                         a_dim1], lda, &tau[i__], &work[i__], &lbwork);
00307 
00308             }
00309 /* L10: */
00310         }
00311     } else {
00312         i__ = 1;
00313     }
00314 
00315 /*     Use unblocked code to factor the last or only block. */
00316 
00317     if (i__ <= k) {
00318         if (i__ != 1) {
00319             i__2 = i__ - nb;
00320             i__1 = nb;
00321             for (j = 1; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
00322 
00323 /*                Apply H' to A(J:M,I:K) from the left */
00324 
00325                 i__4 = *m - j + 1;
00326                 i__3 = k - i__ + 1;
00327                 i__5 = k - i__ + 1;
00328                 zlarfb_("Left", "Transpose", "Forward", "Columnwise", &i__4, &
00329                         i__3, &nb, &a[j + j * a_dim1], lda, &work[j], &lbwork, 
00330                          &a[j + i__ * a_dim1], lda, &work[lbwork * nb + nt * 
00331                         nt + 1], &i__5);
00332 /* L30: */
00333             }
00334             i__1 = *m - i__ + 1;
00335             i__2 = k - i__ + 1;
00336             zgeqr2_(&i__1, &i__2, &a[i__ + i__ * a_dim1], lda, &tau[i__], &
00337                     work[lbwork * nb + nt * nt + 1], &iinfo);
00338         } else {
00339 
00340 /*        Use unblocked code to factor the last or only block. */
00341 
00342             i__1 = *m - i__ + 1;
00343             i__2 = *n - i__ + 1;
00344             zgeqr2_(&i__1, &i__2, &a[i__ + i__ * a_dim1], lda, &tau[i__], &
00345                     work[1], &iinfo);
00346         }
00347     }
00348 
00349 /*     Apply update to the column M+1:N when N > M */
00350 
00351     if (*m < *n && i__ != 1) {
00352 
00353 /*         Form the last triangular factor of the block reflector */
00354 /*         H = H(i) H(i+1) . . . H(i+ib-1) */
00355 
00356         if (nt <= nb) {
00357             i__1 = *m - i__ + 1;
00358             i__2 = k - i__ + 1;
00359             zlarft_("Forward", "Columnwise", &i__1, &i__2, &a[i__ + i__ * 
00360                     a_dim1], lda, &tau[i__], &work[i__], &lbwork);
00361         } else {
00362             i__1 = *m - i__ + 1;
00363             i__2 = k - i__ + 1;
00364             zlarft_("Forward", "Columnwise", &i__1, &i__2, &a[i__ + i__ * 
00365                     a_dim1], lda, &tau[i__], &work[lbwork * nb + 1], &nt);
00366         }
00367 
00368 /*         Apply H' to A(1:M,M+1:N) from the left */
00369 
00370         i__1 = k - nx;
00371         i__2 = nb;
00372         for (j = 1; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
00373 /* Computing MIN */
00374             i__4 = k - j + 1;
00375             ib = min(i__4,nb);
00376             i__4 = *m - j + 1;
00377             i__3 = *n - *m;
00378             i__5 = *n - *m;
00379             zlarfb_("Left", "Transpose", "Forward", "Columnwise", &i__4, &
00380                     i__3, &ib, &a[j + j * a_dim1], lda, &work[j], &lbwork, &a[
00381                     j + (*m + 1) * a_dim1], lda, &work[lbwork * nb + nt * nt 
00382                     + 1], &i__5);
00383 /* L40: */
00384         }
00385         if (nt <= nb) {
00386             i__2 = *m - j + 1;
00387             i__1 = *n - *m;
00388             i__4 = k - j + 1;
00389             i__3 = *n - *m;
00390             zlarfb_("Left", "Transpose", "Forward", "Columnwise", &i__2, &
00391                     i__1, &i__4, &a[j + j * a_dim1], lda, &work[j], &lbwork, &
00392                     a[j + (*m + 1) * a_dim1], lda, &work[lbwork * nb + nt * 
00393                     nt + 1], &i__3);
00394         } else {
00395             i__2 = *m - j + 1;
00396             i__1 = *n - *m;
00397             i__4 = k - j + 1;
00398             i__3 = *n - *m;
00399             zlarfb_("Left", "Transpose", "Forward", "Columnwise", &i__2, &
00400                     i__1, &i__4, &a[j + j * a_dim1], lda, &work[lbwork * nb + 
00401                     1], &nt, &a[j + (*m + 1) * a_dim1], lda, &work[lbwork * 
00402                     nb + nt * nt + 1], &i__3);
00403         }
00404     }
00405     work[1].r = (doublereal) iws, work[1].i = 0.;
00406     return 0;
00407 
00408 /*     End of ZGEQRF */
00409 
00410 } /* zgeqrf_ */


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