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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:35