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


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