zgelqf.c
Go to the documentation of this file.
00001 /* zgelqf.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 zgelqf_(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 zgelq2_(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 /*  ZGELQF computes an LQ factorization of a complex M-by-N matrix A: */
00062 /*  A = L * Q. */
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 below the diagonal of the array */
00076 /*          contain the m-by-min(m,n) lower trapezoidal matrix L (L is */
00077 /*          lower triangular if m <= n); the elements above the diagonal, */
00078 /*          with the array TAU, represent the unitary matrix Q as a */
00079 /*          product of elementary reflectors (see Further Details). */
00080 
00081 /*  LDA     (input) INTEGER */
00082 /*          The leading dimension of the array A.  LDA >= max(1,M). */
00083 
00084 /*  TAU     (output) COMPLEX*16 array, dimension (min(M,N)) */
00085 /*          The scalar factors of the elementary reflectors (see Further */
00086 /*          Details). */
00087 
00088 /*  WORK    (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */
00089 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00090 
00091 /*  LWORK   (input) INTEGER */
00092 /*          The dimension of the array WORK.  LWORK >= max(1,M). */
00093 /*          For optimum performance LWORK >= M*NB, where NB is the */
00094 /*          optimal blocksize. */
00095 
00096 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00097 /*          only calculates the optimal size of the WORK array, returns */
00098 /*          this value as the first entry of the WORK array, and no error */
00099 /*          message related to LWORK is issued by XERBLA. */
00100 
00101 /*  INFO    (output) INTEGER */
00102 /*          = 0:  successful exit */
00103 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00104 
00105 /*  Further Details */
00106 /*  =============== */
00107 
00108 /*  The matrix Q is represented as a product of elementary reflectors */
00109 
00110 /*     Q = H(k)' . . . H(2)' H(1)', where k = min(m,n). */
00111 
00112 /*  Each H(i) has the form */
00113 
00114 /*     H(i) = I - tau * v * v' */
00115 
00116 /*  where tau is a complex scalar, and v is a complex vector with */
00117 /*  v(1:i-1) = 0 and v(i) = 1; conjg(v(i+1:n)) is stored on exit in */
00118 /*  A(i,i+1:n), and tau in TAU(i). */
00119 
00120 /*  ===================================================================== */
00121 
00122 /*     .. Local Scalars .. */
00123 /*     .. */
00124 /*     .. External Subroutines .. */
00125 /*     .. */
00126 /*     .. Intrinsic Functions .. */
00127 /*     .. */
00128 /*     .. External Functions .. */
00129 /*     .. */
00130 /*     .. Executable Statements .. */
00131 
00132 /*     Test the input arguments */
00133 
00134     /* Parameter adjustments */
00135     a_dim1 = *lda;
00136     a_offset = 1 + a_dim1;
00137     a -= a_offset;
00138     --tau;
00139     --work;
00140 
00141     /* Function Body */
00142     *info = 0;
00143     nb = ilaenv_(&c__1, "ZGELQF", " ", m, n, &c_n1, &c_n1);
00144     lwkopt = *m * nb;
00145     work[1].r = (doublereal) lwkopt, work[1].i = 0.;
00146     lquery = *lwork == -1;
00147     if (*m < 0) {
00148         *info = -1;
00149     } else if (*n < 0) {
00150         *info = -2;
00151     } else if (*lda < max(1,*m)) {
00152         *info = -4;
00153     } else if (*lwork < max(1,*m) && ! lquery) {
00154         *info = -7;
00155     }
00156     if (*info != 0) {
00157         i__1 = -(*info);
00158         xerbla_("ZGELQF", &i__1);
00159         return 0;
00160     } else if (lquery) {
00161         return 0;
00162     }
00163 
00164 /*     Quick return if possible */
00165 
00166     k = min(*m,*n);
00167     if (k == 0) {
00168         work[1].r = 1., work[1].i = 0.;
00169         return 0;
00170     }
00171 
00172     nbmin = 2;
00173     nx = 0;
00174     iws = *m;
00175     if (nb > 1 && nb < k) {
00176 
00177 /*        Determine when to cross over from blocked to unblocked code. */
00178 
00179 /* Computing MAX */
00180         i__1 = 0, i__2 = ilaenv_(&c__3, "ZGELQF", " ", m, n, &c_n1, &c_n1);
00181         nx = max(i__1,i__2);
00182         if (nx < k) {
00183 
00184 /*           Determine if workspace is large enough for blocked code. */
00185 
00186             ldwork = *m;
00187             iws = ldwork * nb;
00188             if (*lwork < iws) {
00189 
00190 /*              Not enough workspace to use optimal NB:  reduce NB and */
00191 /*              determine the minimum value of NB. */
00192 
00193                 nb = *lwork / ldwork;
00194 /* Computing MAX */
00195                 i__1 = 2, i__2 = ilaenv_(&c__2, "ZGELQF", " ", m, n, &c_n1, &
00196                         c_n1);
00197                 nbmin = max(i__1,i__2);
00198             }
00199         }
00200     }
00201 
00202     if (nb >= nbmin && nb < k && nx < k) {
00203 
00204 /*        Use blocked code initially */
00205 
00206         i__1 = k - nx;
00207         i__2 = nb;
00208         for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
00209 /* Computing MIN */
00210             i__3 = k - i__ + 1;
00211             ib = min(i__3,nb);
00212 
00213 /*           Compute the LQ factorization of the current block */
00214 /*           A(i:i+ib-1,i:n) */
00215 
00216             i__3 = *n - i__ + 1;
00217             zgelq2_(&ib, &i__3, &a[i__ + i__ * a_dim1], lda, &tau[i__], &work[
00218                     1], &iinfo);
00219             if (i__ + ib <= *m) {
00220 
00221 /*              Form the triangular factor of the block reflector */
00222 /*              H = H(i) H(i+1) . . . H(i+ib-1) */
00223 
00224                 i__3 = *n - i__ + 1;
00225                 zlarft_("Forward", "Rowwise", &i__3, &ib, &a[i__ + i__ * 
00226                         a_dim1], lda, &tau[i__], &work[1], &ldwork);
00227 
00228 /*              Apply H to A(i+ib:m,i:n) from the right */
00229 
00230                 i__3 = *m - i__ - ib + 1;
00231                 i__4 = *n - i__ + 1;
00232                 zlarfb_("Right", "No transpose", "Forward", "Rowwise", &i__3, 
00233                         &i__4, &ib, &a[i__ + i__ * a_dim1], lda, &work[1], &
00234                         ldwork, &a[i__ + ib + i__ * a_dim1], lda, &work[ib + 
00235                         1], &ldwork);
00236             }
00237 /* L10: */
00238         }
00239     } else {
00240         i__ = 1;
00241     }
00242 
00243 /*     Use unblocked code to factor the last or only block. */
00244 
00245     if (i__ <= k) {
00246         i__2 = *m - i__ + 1;
00247         i__1 = *n - i__ + 1;
00248         zgelq2_(&i__2, &i__1, &a[i__ + i__ * a_dim1], lda, &tau[i__], &work[1]
00249 , &iinfo);
00250     }
00251 
00252     work[1].r = (doublereal) iws, work[1].i = 0.;
00253     return 0;
00254 
00255 /*     End of ZGELQF */
00256 
00257 } /* zgelqf_ */


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