cgerqf.c
Go to the documentation of this file.
00001 /* cgerqf.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 cgerqf_(integer *m, integer *n, complex *a, integer *lda, 
00024          complex *tau, complex *work, integer *lwork, integer *info)
00025 {
00026     /* System generated locals */
00027     integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
00028 
00029     /* Local variables */
00030     integer i__, k, ib, nb, ki, kk, mu, nu, nx, iws, nbmin, iinfo;
00031     extern /* Subroutine */ int cgerq2_(integer *, integer *, complex *, 
00032             integer *, complex *, complex *, integer *), clarfb_(char *, char 
00033             *, char *, char *, integer *, integer *, integer *, complex *, 
00034             integer *, complex *, integer *, complex *, integer *, complex *, 
00035             integer *), clarft_(char *, char *
00036 , integer *, integer *, complex *, integer *, complex *, complex *
00037 , integer *), xerbla_(char *, integer *);
00038     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00039             integer *, integer *);
00040     integer ldwork, lwkopt;
00041     logical lquery;
00042 
00043 
00044 /*  -- LAPACK routine (version 3.2) -- */
00045 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00046 /*     November 2006 */
00047 
00048 /*     .. Scalar Arguments .. */
00049 /*     .. */
00050 /*     .. Array Arguments .. */
00051 /*     .. */
00052 
00053 /*  Purpose */
00054 /*  ======= */
00055 
00056 /*  CGERQF computes an RQ factorization of a complex M-by-N matrix A: */
00057 /*  A = R * Q. */
00058 
00059 /*  Arguments */
00060 /*  ========= */
00061 
00062 /*  M       (input) INTEGER */
00063 /*          The number of rows of the matrix A.  M >= 0. */
00064 
00065 /*  N       (input) INTEGER */
00066 /*          The number of columns of the matrix A.  N >= 0. */
00067 
00068 /*  A       (input/output) COMPLEX array, dimension (LDA,N) */
00069 /*          On entry, the M-by-N matrix A. */
00070 /*          On exit, */
00071 /*          if m <= n, the upper triangle of the subarray */
00072 /*          A(1:m,n-m+1:n) contains the M-by-M upper triangular matrix R; */
00073 /*          if m >= n, the elements on and above the (m-n)-th subdiagonal */
00074 /*          contain the M-by-N upper trapezoidal matrix R; */
00075 /*          the remaining elements, with the array TAU, represent the */
00076 /*          unitary matrix Q as a product of min(m,n) elementary */
00077 /*          reflectors (see Further Details). */
00078 
00079 /*  LDA     (input) INTEGER */
00080 /*          The leading dimension of the array A.  LDA >= max(1,M). */
00081 
00082 /*  TAU     (output) COMPLEX array, dimension (min(M,N)) */
00083 /*          The scalar factors of the elementary reflectors (see Further */
00084 /*          Details). */
00085 
00086 /*  WORK    (workspace/output) COMPLEX array, dimension (MAX(1,LWORK)) */
00087 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00088 
00089 /*  LWORK   (input) INTEGER */
00090 /*          The dimension of the array WORK.  LWORK >= max(1,M). */
00091 /*          For optimum performance LWORK >= M*NB, where NB is */
00092 /*          the optimal blocksize. */
00093 
00094 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00095 /*          only calculates the optimal size of the WORK array, returns */
00096 /*          this value as the first entry of the WORK array, and no error */
00097 /*          message related to LWORK is issued by XERBLA. */
00098 
00099 /*  INFO    (output) INTEGER */
00100 /*          = 0:  successful exit */
00101 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00102 
00103 /*  Further Details */
00104 /*  =============== */
00105 
00106 /*  The matrix Q is represented as a product of elementary reflectors */
00107 
00108 /*     Q = H(1)' H(2)' . . . H(k)', where k = min(m,n). */
00109 
00110 /*  Each H(i) has the form */
00111 
00112 /*     H(i) = I - tau * v * v' */
00113 
00114 /*  where tau is a complex scalar, and v is a complex vector with */
00115 /*  v(n-k+i+1:n) = 0 and v(n-k+i) = 1; conjg(v(1:n-k+i-1)) is stored on */
00116 /*  exit in A(m-k+i,1:n-k+i-1), and tau in TAU(i). */
00117 
00118 /*  ===================================================================== */
00119 
00120 /*     .. Local Scalars .. */
00121 /*     .. */
00122 /*     .. External Subroutines .. */
00123 /*     .. */
00124 /*     .. Intrinsic Functions .. */
00125 /*     .. */
00126 /*     .. External Functions .. */
00127 /*     .. */
00128 /*     .. Executable Statements .. */
00129 
00130 /*     Test the input arguments */
00131 
00132     /* Parameter adjustments */
00133     a_dim1 = *lda;
00134     a_offset = 1 + a_dim1;
00135     a -= a_offset;
00136     --tau;
00137     --work;
00138 
00139     /* Function Body */
00140     *info = 0;
00141     lquery = *lwork == -1;
00142     if (*m < 0) {
00143         *info = -1;
00144     } else if (*n < 0) {
00145         *info = -2;
00146     } else if (*lda < max(1,*m)) {
00147         *info = -4;
00148     }
00149 
00150     if (*info == 0) {
00151         k = min(*m,*n);
00152         if (k == 0) {
00153             lwkopt = 1;
00154         } else {
00155             nb = ilaenv_(&c__1, "CGERQF", " ", m, n, &c_n1, &c_n1);
00156             lwkopt = *m * nb;
00157         }
00158         work[1].r = (real) lwkopt, work[1].i = 0.f;
00159 
00160         if (*lwork < max(1,*m) && ! lquery) {
00161             *info = -7;
00162         }
00163     }
00164 
00165     if (*info != 0) {
00166         i__1 = -(*info);
00167         xerbla_("CGERQF", &i__1);
00168         return 0;
00169     } else if (lquery) {
00170         return 0;
00171     }
00172 
00173 /*     Quick return if possible */
00174 
00175     if (k == 0) {
00176         return 0;
00177     }
00178 
00179     nbmin = 2;
00180     nx = 1;
00181     iws = *m;
00182     if (nb > 1 && nb < k) {
00183 
00184 /*        Determine when to cross over from blocked to unblocked code. */
00185 
00186 /* Computing MAX */
00187         i__1 = 0, i__2 = ilaenv_(&c__3, "CGERQF", " ", m, n, &c_n1, &c_n1);
00188         nx = max(i__1,i__2);
00189         if (nx < k) {
00190 
00191 /*           Determine if workspace is large enough for blocked code. */
00192 
00193             ldwork = *m;
00194             iws = ldwork * nb;
00195             if (*lwork < iws) {
00196 
00197 /*              Not enough workspace to use optimal NB:  reduce NB and */
00198 /*              determine the minimum value of NB. */
00199 
00200                 nb = *lwork / ldwork;
00201 /* Computing MAX */
00202                 i__1 = 2, i__2 = ilaenv_(&c__2, "CGERQF", " ", m, n, &c_n1, &
00203                         c_n1);
00204                 nbmin = max(i__1,i__2);
00205             }
00206         }
00207     }
00208 
00209     if (nb >= nbmin && nb < k && nx < k) {
00210 
00211 /*        Use blocked code initially. */
00212 /*        The last kk rows are handled by the block method. */
00213 
00214         ki = (k - nx - 1) / nb * nb;
00215 /* Computing MIN */
00216         i__1 = k, i__2 = ki + nb;
00217         kk = min(i__1,i__2);
00218 
00219         i__1 = k - kk + 1;
00220         i__2 = -nb;
00221         for (i__ = k - kk + ki + 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ 
00222                 += i__2) {
00223 /* Computing MIN */
00224             i__3 = k - i__ + 1;
00225             ib = min(i__3,nb);
00226 
00227 /*           Compute the RQ factorization of the current block */
00228 /*           A(m-k+i:m-k+i+ib-1,1:n-k+i+ib-1) */
00229 
00230             i__3 = *n - k + i__ + ib - 1;
00231             cgerq2_(&ib, &i__3, &a[*m - k + i__ + a_dim1], lda, &tau[i__], &
00232                     work[1], &iinfo);
00233             if (*m - k + i__ > 1) {
00234 
00235 /*              Form the triangular factor of the block reflector */
00236 /*              H = H(i+ib-1) . . . H(i+1) H(i) */
00237 
00238                 i__3 = *n - k + i__ + ib - 1;
00239                 clarft_("Backward", "Rowwise", &i__3, &ib, &a[*m - k + i__ + 
00240                         a_dim1], lda, &tau[i__], &work[1], &ldwork);
00241 
00242 /*              Apply H to A(1:m-k+i-1,1:n-k+i+ib-1) from the right */
00243 
00244                 i__3 = *m - k + i__ - 1;
00245                 i__4 = *n - k + i__ + ib - 1;
00246                 clarfb_("Right", "No transpose", "Backward", "Rowwise", &i__3, 
00247                          &i__4, &ib, &a[*m - k + i__ + a_dim1], lda, &work[1], 
00248                          &ldwork, &a[a_offset], lda, &work[ib + 1], &ldwork);
00249             }
00250 /* L10: */
00251         }
00252         mu = *m - k + i__ + nb - 1;
00253         nu = *n - k + i__ + nb - 1;
00254     } else {
00255         mu = *m;
00256         nu = *n;
00257     }
00258 
00259 /*     Use unblocked code to factor the last or only block */
00260 
00261     if (mu > 0 && nu > 0) {
00262         cgerq2_(&mu, &nu, &a[a_offset], lda, &tau[1], &work[1], &iinfo);
00263     }
00264 
00265     work[1].r = (real) iws, work[1].i = 0.f;
00266     return 0;
00267 
00268 /*     End of CGERQF */
00269 
00270 } /* cgerqf_ */


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