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


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