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;
00029 
00030     /* Local variables */
00031     integer i__, k, ib, nb, nx, iws, nbmin, iinfo;
00032     extern /* Subroutine */ int zgeqr2_(integer *, integer *, doublecomplex *, 
00033              integer *, doublecomplex *, doublecomplex *, integer *), xerbla_(
00034             char *, integer *);
00035     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00036             integer *, integer *);
00037     extern /* Subroutine */ int zlarfb_(char *, char *, char *, char *, 
00038             integer *, integer *, integer *, doublecomplex *, integer *, 
00039             doublecomplex *, integer *, doublecomplex *, integer *, 
00040             doublecomplex *, integer *);
00041     integer ldwork;
00042     extern /* Subroutine */ int zlarft_(char *, char *, integer *, integer *, 
00043             doublecomplex *, integer *, doublecomplex *, doublecomplex *, 
00044             integer *);
00045     integer lwkopt;
00046     logical lquery;
00047 
00048 
00049 /*  -- LAPACK routine (version 3.2) -- */
00050 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00051 /*     November 2006 */
00052 
00053 /*     .. Scalar Arguments .. */
00054 /*     .. */
00055 /*     .. Array Arguments .. */
00056 /*     .. */
00057 
00058 /*  Purpose */
00059 /*  ======= */
00060 
00061 /*  ZGEQRF computes a QR factorization of a complex M-by-N matrix A: */
00062 /*  A = Q * R. */
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*16 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 unitary 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*16 array, dimension (min(M,N)) */
00086 /*          The scalar factors of the elementary reflectors (see Further */
00087 /*          Details). */
00088 
00089 /*  WORK    (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */
00090 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00091 
00092 /*  LWORK   (input) INTEGER */
00093 /*          The dimension of the array WORK.  LWORK >= max(1,N). */
00094 /*          For optimum performance LWORK >= N*NB, where NB is */
00095 /*          the optimal blocksize. */
00096 
00097 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00098 /*          only calculates the optimal size of the WORK array, returns */
00099 /*          this value as the first entry of the WORK array, and no error */
00100 /*          message related to LWORK is issued by XERBLA. */
00101 
00102 /*  INFO    (output) INTEGER */
00103 /*          = 0:  successful exit */
00104 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00105 
00106 /*  Further Details */
00107 /*  =============== */
00108 
00109 /*  The matrix Q is represented as a product of elementary reflectors */
00110 
00111 /*     Q = H(1) H(2) . . . H(k), where k = min(m,n). */
00112 
00113 /*  Each H(i) has the form */
00114 
00115 /*     H(i) = I - tau * v * v' */
00116 
00117 /*  where tau is a complex scalar, and v is a complex vector with */
00118 /*  v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i), */
00119 /*  and tau in TAU(i). */
00120 
00121 /*  ===================================================================== */
00122 
00123 /*     .. Local Scalars .. */
00124 /*     .. */
00125 /*     .. External Subroutines .. */
00126 /*     .. */
00127 /*     .. Intrinsic Functions .. */
00128 /*     .. */
00129 /*     .. External Functions .. */
00130 /*     .. */
00131 /*     .. Executable Statements .. */
00132 
00133 /*     Test the input arguments */
00134 
00135     /* Parameter adjustments */
00136     a_dim1 = *lda;
00137     a_offset = 1 + a_dim1;
00138     a -= a_offset;
00139     --tau;
00140     --work;
00141 
00142     /* Function Body */
00143     *info = 0;
00144     nb = ilaenv_(&c__1, "ZGEQRF", " ", m, n, &c_n1, &c_n1);
00145     lwkopt = *n * nb;
00146     work[1].r = (doublereal) lwkopt, work[1].i = 0.;
00147     lquery = *lwork == -1;
00148     if (*m < 0) {
00149         *info = -1;
00150     } else if (*n < 0) {
00151         *info = -2;
00152     } else if (*lda < max(1,*m)) {
00153         *info = -4;
00154     } else if (*lwork < max(1,*n) && ! lquery) {
00155         *info = -7;
00156     }
00157     if (*info != 0) {
00158         i__1 = -(*info);
00159         xerbla_("ZGEQRF", &i__1);
00160         return 0;
00161     } else if (lquery) {
00162         return 0;
00163     }
00164 
00165 /*     Quick return if possible */
00166 
00167     k = min(*m,*n);
00168     if (k == 0) {
00169         work[1].r = 1., work[1].i = 0.;
00170         return 0;
00171     }
00172 
00173     nbmin = 2;
00174     nx = 0;
00175     iws = *n;
00176     if (nb > 1 && nb < k) {
00177 
00178 /*        Determine when to cross over from blocked to unblocked code. */
00179 
00180 /* Computing MAX */
00181         i__1 = 0, i__2 = ilaenv_(&c__3, "ZGEQRF", " ", m, n, &c_n1, &c_n1);
00182         nx = max(i__1,i__2);
00183         if (nx < k) {
00184 
00185 /*           Determine if workspace is large enough for blocked code. */
00186 
00187             ldwork = *n;
00188             iws = ldwork * nb;
00189             if (*lwork < iws) {
00190 
00191 /*              Not enough workspace to use optimal NB:  reduce NB and */
00192 /*              determine the minimum value of NB. */
00193 
00194                 nb = *lwork / ldwork;
00195 /* Computing MAX */
00196                 i__1 = 2, i__2 = ilaenv_(&c__2, "ZGEQRF", " ", m, n, &c_n1, &
00197                         c_n1);
00198                 nbmin = max(i__1,i__2);
00199             }
00200         }
00201     }
00202 
00203     if (nb >= nbmin && nb < k && nx < k) {
00204 
00205 /*        Use blocked code initially */
00206 
00207         i__1 = k - nx;
00208         i__2 = nb;
00209         for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
00210 /* Computing MIN */
00211             i__3 = k - i__ + 1;
00212             ib = min(i__3,nb);
00213 
00214 /*           Compute the QR factorization of the current block */
00215 /*           A(i:m,i:i+ib-1) */
00216 
00217             i__3 = *m - i__ + 1;
00218             zgeqr2_(&i__3, &ib, &a[i__ + i__ * a_dim1], lda, &tau[i__], &work[
00219                     1], &iinfo);
00220             if (i__ + ib <= *n) {
00221 
00222 /*              Form the triangular factor of the block reflector */
00223 /*              H = H(i) H(i+1) . . . H(i+ib-1) */
00224 
00225                 i__3 = *m - i__ + 1;
00226                 zlarft_("Forward", "Columnwise", &i__3, &ib, &a[i__ + i__ * 
00227                         a_dim1], lda, &tau[i__], &work[1], &ldwork);
00228 
00229 /*              Apply H' to A(i:m,i+ib:n) from the left */
00230 
00231                 i__3 = *m - i__ + 1;
00232                 i__4 = *n - i__ - ib + 1;
00233                 zlarfb_("Left", "Conjugate transpose", "Forward", "Columnwise"
00234 , &i__3, &i__4, &ib, &a[i__ + i__ * a_dim1], lda, &
00235                         work[1], &ldwork, &a[i__ + (i__ + ib) * a_dim1], lda, 
00236                         &work[ib + 1], &ldwork);
00237             }
00238 /* L10: */
00239         }
00240     } else {
00241         i__ = 1;
00242     }
00243 
00244 /*     Use unblocked code to factor the last or only block. */
00245 
00246     if (i__ <= k) {
00247         i__2 = *m - i__ + 1;
00248         i__1 = *n - i__ + 1;
00249         zgeqr2_(&i__2, &i__1, &a[i__ + i__ * a_dim1], lda, &tau[i__], &work[1]
00250 , &iinfo);
00251     }
00252 
00253     work[1].r = (doublereal) iws, work[1].i = 0.;
00254     return 0;
00255 
00256 /*     End of ZGEQRF */
00257 
00258 } /* zgeqrf_ */


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