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


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