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


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