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


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