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


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