zungrq.c
Go to the documentation of this file.
00001 /* zungrq.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 zungrq_(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, i__5;
00029 
00030     /* Local variables */
00031     integer i__, j, l, ib, nb, ii, kk, nx, iws, nbmin, iinfo;
00032     extern /* Subroutine */ int zungr2_(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 /*  ZUNGRQ generates an M-by-N complex matrix Q with orthonormal rows, */
00062 /*  which is defined as the last M rows of a product of K elementary */
00063 /*  reflectors of order N */
00064 
00065 /*        Q  =  H(1)' H(2)' . . . H(k)' */
00066 
00067 /*  as returned by ZGERQF. */
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 (m-k+i)-th row must contain the vector which */
00084 /*          defines the elementary reflector H(i), for i = 1,2,...,k, as */
00085 /*          returned by ZGERQF in the last k rows of its array argument */
00086 /*          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 ZGERQF. */
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,M). */
00101 /*          For optimum performance LWORK >= M*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     lquery = *lwork == -1;
00139     if (*m < 0) {
00140         *info = -1;
00141     } else if (*n < *m) {
00142         *info = -2;
00143     } else if (*k < 0 || *k > *m) {
00144         *info = -3;
00145     } else if (*lda < max(1,*m)) {
00146         *info = -5;
00147     }
00148 
00149     if (*info == 0) {
00150         if (*m <= 0) {
00151             lwkopt = 1;
00152         } else {
00153             nb = ilaenv_(&c__1, "ZUNGRQ", " ", m, n, k, &c_n1);
00154             lwkopt = *m * nb;
00155         }
00156         work[1].r = (doublereal) lwkopt, work[1].i = 0.;
00157 
00158         if (*lwork < max(1,*m) && ! lquery) {
00159             *info = -8;
00160         }
00161     }
00162 
00163     if (*info != 0) {
00164         i__1 = -(*info);
00165         xerbla_("ZUNGRQ", &i__1);
00166         return 0;
00167     } else if (lquery) {
00168         return 0;
00169     }
00170 
00171 /*     Quick return if possible */
00172 
00173     if (*m <= 0) {
00174         return 0;
00175     }
00176 
00177     nbmin = 2;
00178     nx = 0;
00179     iws = *m;
00180     if (nb > 1 && nb < *k) {
00181 
00182 /*        Determine when to cross over from blocked to unblocked code. */
00183 
00184 /* Computing MAX */
00185         i__1 = 0, i__2 = ilaenv_(&c__3, "ZUNGRQ", " ", m, n, k, &c_n1);
00186         nx = max(i__1,i__2);
00187         if (nx < *k) {
00188 
00189 /*           Determine if workspace is large enough for blocked code. */
00190 
00191             ldwork = *m;
00192             iws = ldwork * nb;
00193             if (*lwork < iws) {
00194 
00195 /*              Not enough workspace to use optimal NB:  reduce NB and */
00196 /*              determine the minimum value of NB. */
00197 
00198                 nb = *lwork / ldwork;
00199 /* Computing MAX */
00200                 i__1 = 2, i__2 = ilaenv_(&c__2, "ZUNGRQ", " ", m, n, k, &c_n1);
00201                 nbmin = max(i__1,i__2);
00202             }
00203         }
00204     }
00205 
00206     if (nb >= nbmin && nb < *k && nx < *k) {
00207 
00208 /*        Use blocked code after the first block. */
00209 /*        The last kk rows are handled by the block method. */
00210 
00211 /* Computing MIN */
00212         i__1 = *k, i__2 = (*k - nx + nb - 1) / nb * nb;
00213         kk = min(i__1,i__2);
00214 
00215 /*        Set A(1:m-kk,n-kk+1:n) to zero. */
00216 
00217         i__1 = *n;
00218         for (j = *n - kk + 1; j <= i__1; ++j) {
00219             i__2 = *m - kk;
00220             for (i__ = 1; i__ <= i__2; ++i__) {
00221                 i__3 = i__ + j * a_dim1;
00222                 a[i__3].r = 0., a[i__3].i = 0.;
00223 /* L10: */
00224             }
00225 /* L20: */
00226         }
00227     } else {
00228         kk = 0;
00229     }
00230 
00231 /*     Use unblocked code for the first or only block. */
00232 
00233     i__1 = *m - kk;
00234     i__2 = *n - kk;
00235     i__3 = *k - kk;
00236     zungr2_(&i__1, &i__2, &i__3, &a[a_offset], lda, &tau[1], &work[1], &iinfo)
00237             ;
00238 
00239     if (kk > 0) {
00240 
00241 /*        Use blocked code */
00242 
00243         i__1 = *k;
00244         i__2 = nb;
00245         for (i__ = *k - kk + 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += 
00246                 i__2) {
00247 /* Computing MIN */
00248             i__3 = nb, i__4 = *k - i__ + 1;
00249             ib = min(i__3,i__4);
00250             ii = *m - *k + i__;
00251             if (ii > 1) {
00252 
00253 /*              Form the triangular factor of the block reflector */
00254 /*              H = H(i+ib-1) . . . H(i+1) H(i) */
00255 
00256                 i__3 = *n - *k + i__ + ib - 1;
00257                 zlarft_("Backward", "Rowwise", &i__3, &ib, &a[ii + a_dim1], 
00258                         lda, &tau[i__], &work[1], &ldwork);
00259 
00260 /*              Apply H' to A(1:m-k+i-1,1:n-k+i+ib-1) from the right */
00261 
00262                 i__3 = ii - 1;
00263                 i__4 = *n - *k + i__ + ib - 1;
00264                 zlarfb_("Right", "Conjugate transpose", "Backward", "Rowwise", 
00265                          &i__3, &i__4, &ib, &a[ii + a_dim1], lda, &work[1], &
00266                         ldwork, &a[a_offset], lda, &work[ib + 1], &ldwork);
00267             }
00268 
00269 /*           Apply H' to columns 1:n-k+i+ib-1 of current block */
00270 
00271             i__3 = *n - *k + i__ + ib - 1;
00272             zungr2_(&ib, &i__3, &ib, &a[ii + a_dim1], lda, &tau[i__], &work[1]
00273 , &iinfo);
00274 
00275 /*           Set columns n-k+i+ib:n of current block to zero */
00276 
00277             i__3 = *n;
00278             for (l = *n - *k + i__ + ib; l <= i__3; ++l) {
00279                 i__4 = ii + ib - 1;
00280                 for (j = ii; j <= i__4; ++j) {
00281                     i__5 = j + l * a_dim1;
00282                     a[i__5].r = 0., a[i__5].i = 0.;
00283 /* L30: */
00284                 }
00285 /* L40: */
00286             }
00287 /* L50: */
00288         }
00289     }
00290 
00291     work[1].r = (doublereal) iws, work[1].i = 0.;
00292     return 0;
00293 
00294 /*     End of ZUNGRQ */
00295 
00296 } /* zungrq_ */


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