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


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