zunglq.c
Go to the documentation of this file.
00001 /* zunglq.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 zunglq_(integer *m, integer *n, integer *k, 
00024         doublecomplex *a, integer *lda, doublecomplex *tau, doublecomplex *
00025         work, integer *lwork, 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__, j, l, ib, nb, ki, kk, nx, iws, nbmin, iinfo;
00032     extern /* Subroutine */ int zungl2_(integer *, integer *, integer *, 
00033             doublecomplex *, integer *, doublecomplex *, doublecomplex *, 
00034             integer *), xerbla_(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     logical lquery;
00046     integer lwkopt;
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 /*  ZUNGLQ generates an M-by-N complex matrix Q with orthonormal rows, */
00062 /*  which is defined as the first M rows of a product of K elementary */
00063 /*  reflectors of order N */
00064 
00065 /*        Q  =  H(k)' . . . H(2)' H(1)' */
00066 
00067 /*  as returned by ZGELQF. */
00068 
00069 /*  Arguments */
00070 /*  ========= */
00071 
00072 /*  M       (input) INTEGER */
00073 /*          The number of rows of the matrix Q. M >= 0. */
00074 
00075 /*  N       (input) INTEGER */
00076 /*          The number of columns of the matrix Q. N >= M. */
00077 
00078 /*  K       (input) INTEGER */
00079 /*          The number of elementary reflectors whose product defines the */
00080 /*          matrix Q. M >= K >= 0. */
00081 
00082 /*  A       (input/output) COMPLEX*16 array, dimension (LDA,N) */
00083 /*          On entry, the i-th row must contain the vector which defines */
00084 /*          the elementary reflector H(i), for i = 1,2,...,k, as returned */
00085 /*          by ZGELQF in the first k rows of its array argument A. */
00086 /*          On exit, the M-by-N matrix Q. */
00087 
00088 /*  LDA     (input) INTEGER */
00089 /*          The first dimension of the array A. LDA >= max(1,M). */
00090 
00091 /*  TAU     (input) COMPLEX*16 array, dimension (K) */
00092 /*          TAU(i) must contain the scalar factor of the elementary */
00093 /*          reflector H(i), as returned by ZGELQF. */
00094 
00095 /*  WORK    (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */
00096 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00097 
00098 /*  LWORK   (input) INTEGER */
00099 /*          The dimension of the array WORK. LWORK >= max(1,M). */
00100 /*          For optimum performance LWORK >= M*NB, where NB is */
00101 /*          the optimal blocksize. */
00102 
00103 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00104 /*          only calculates the optimal size of the WORK array, returns */
00105 /*          this value as the first entry of the WORK array, and no error */
00106 /*          message related to LWORK is issued by XERBLA. */
00107 
00108 /*  INFO    (output) INTEGER */
00109 /*          = 0:  successful exit; */
00110 /*          < 0:  if INFO = -i, the i-th argument has an illegal value */
00111 
00112 /*  ===================================================================== */
00113 
00114 /*     .. Parameters .. */
00115 /*     .. */
00116 /*     .. Local Scalars .. */
00117 /*     .. */
00118 /*     .. External Subroutines .. */
00119 /*     .. */
00120 /*     .. Intrinsic Functions .. */
00121 /*     .. */
00122 /*     .. External Functions .. */
00123 /*     .. */
00124 /*     .. Executable Statements .. */
00125 
00126 /*     Test the input arguments */
00127 
00128     /* Parameter adjustments */
00129     a_dim1 = *lda;
00130     a_offset = 1 + a_dim1;
00131     a -= a_offset;
00132     --tau;
00133     --work;
00134 
00135     /* Function Body */
00136     *info = 0;
00137     nb = ilaenv_(&c__1, "ZUNGLQ", " ", m, n, k, &c_n1);
00138     lwkopt = max(1,*m) * nb;
00139     work[1].r = (doublereal) lwkopt, work[1].i = 0.;
00140     lquery = *lwork == -1;
00141     if (*m < 0) {
00142         *info = -1;
00143     } else if (*n < *m) {
00144         *info = -2;
00145     } else if (*k < 0 || *k > *m) {
00146         *info = -3;
00147     } else if (*lda < max(1,*m)) {
00148         *info = -5;
00149     } else if (*lwork < max(1,*m) && ! lquery) {
00150         *info = -8;
00151     }
00152     if (*info != 0) {
00153         i__1 = -(*info);
00154         xerbla_("ZUNGLQ", &i__1);
00155         return 0;
00156     } else if (lquery) {
00157         return 0;
00158     }
00159 
00160 /*     Quick return if possible */
00161 
00162     if (*m <= 0) {
00163         work[1].r = 1., work[1].i = 0.;
00164         return 0;
00165     }
00166 
00167     nbmin = 2;
00168     nx = 0;
00169     iws = *m;
00170     if (nb > 1 && nb < *k) {
00171 
00172 /*        Determine when to cross over from blocked to unblocked code. */
00173 
00174 /* Computing MAX */
00175         i__1 = 0, i__2 = ilaenv_(&c__3, "ZUNGLQ", " ", m, n, k, &c_n1);
00176         nx = max(i__1,i__2);
00177         if (nx < *k) {
00178 
00179 /*           Determine if workspace is large enough for blocked code. */
00180 
00181             ldwork = *m;
00182             iws = ldwork * nb;
00183             if (*lwork < iws) {
00184 
00185 /*              Not enough workspace to use optimal NB:  reduce NB and */
00186 /*              determine the minimum value of NB. */
00187 
00188                 nb = *lwork / ldwork;
00189 /* Computing MAX */
00190                 i__1 = 2, i__2 = ilaenv_(&c__2, "ZUNGLQ", " ", m, n, k, &c_n1);
00191                 nbmin = max(i__1,i__2);
00192             }
00193         }
00194     }
00195 
00196     if (nb >= nbmin && nb < *k && nx < *k) {
00197 
00198 /*        Use blocked code after the last block. */
00199 /*        The first kk rows are handled by the block method. */
00200 
00201         ki = (*k - nx - 1) / nb * nb;
00202 /* Computing MIN */
00203         i__1 = *k, i__2 = ki + nb;
00204         kk = min(i__1,i__2);
00205 
00206 /*        Set A(kk+1:m,1:kk) to zero. */
00207 
00208         i__1 = kk;
00209         for (j = 1; j <= i__1; ++j) {
00210             i__2 = *m;
00211             for (i__ = kk + 1; i__ <= i__2; ++i__) {
00212                 i__3 = i__ + j * a_dim1;
00213                 a[i__3].r = 0., a[i__3].i = 0.;
00214 /* L10: */
00215             }
00216 /* L20: */
00217         }
00218     } else {
00219         kk = 0;
00220     }
00221 
00222 /*     Use unblocked code for the last or only block. */
00223 
00224     if (kk < *m) {
00225         i__1 = *m - kk;
00226         i__2 = *n - kk;
00227         i__3 = *k - kk;
00228         zungl2_(&i__1, &i__2, &i__3, &a[kk + 1 + (kk + 1) * a_dim1], lda, &
00229                 tau[kk + 1], &work[1], &iinfo);
00230     }
00231 
00232     if (kk > 0) {
00233 
00234 /*        Use blocked code */
00235 
00236         i__1 = -nb;
00237         for (i__ = ki + 1; i__1 < 0 ? i__ >= 1 : i__ <= 1; i__ += i__1) {
00238 /* Computing MIN */
00239             i__2 = nb, i__3 = *k - i__ + 1;
00240             ib = min(i__2,i__3);
00241             if (i__ + ib <= *m) {
00242 
00243 /*              Form the triangular factor of the block reflector */
00244 /*              H = H(i) H(i+1) . . . H(i+ib-1) */
00245 
00246                 i__2 = *n - i__ + 1;
00247                 zlarft_("Forward", "Rowwise", &i__2, &ib, &a[i__ + i__ * 
00248                         a_dim1], lda, &tau[i__], &work[1], &ldwork);
00249 
00250 /*              Apply H' to A(i+ib:m,i:n) from the right */
00251 
00252                 i__2 = *m - i__ - ib + 1;
00253                 i__3 = *n - i__ + 1;
00254                 zlarfb_("Right", "Conjugate transpose", "Forward", "Rowwise", 
00255                         &i__2, &i__3, &ib, &a[i__ + i__ * a_dim1], lda, &work[
00256                         1], &ldwork, &a[i__ + ib + i__ * a_dim1], lda, &work[
00257                         ib + 1], &ldwork);
00258             }
00259 
00260 /*           Apply H' to columns i:n of current block */
00261 
00262             i__2 = *n - i__ + 1;
00263             zungl2_(&ib, &i__2, &ib, &a[i__ + i__ * a_dim1], lda, &tau[i__], &
00264                     work[1], &iinfo);
00265 
00266 /*           Set columns 1:i-1 of current block to zero */
00267 
00268             i__2 = i__ - 1;
00269             for (j = 1; j <= i__2; ++j) {
00270                 i__3 = i__ + ib - 1;
00271                 for (l = i__; l <= i__3; ++l) {
00272                     i__4 = l + j * a_dim1;
00273                     a[i__4].r = 0., a[i__4].i = 0.;
00274 /* L30: */
00275                 }
00276 /* L40: */
00277             }
00278 /* L50: */
00279         }
00280     }
00281 
00282     work[1].r = (doublereal) iws, work[1].i = 0.;
00283     return 0;
00284 
00285 /*     End of ZUNGLQ */
00286 
00287 } /* zunglq_ */


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