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


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