dorgrq.c
Go to the documentation of this file.
00001 /* dorgrq.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 dorgrq_(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, i__4;
00029 
00030     /* Local variables */
00031     integer i__, j, l, ib, nb, ii, kk, nx, iws, nbmin, iinfo;
00032     extern /* Subroutine */ int dorgr2_(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 /*  DORGRQ generates an M-by-N real matrix Q with orthonormal rows, */
00057 /*  which is defined as the last M rows of a product of K elementary */
00058 /*  reflectors of order N */
00059 
00060 /*        Q  =  H(1) H(2) . . . H(k) */
00061 
00062 /*  as returned by DGERQF. */
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 (m-k+i)-th row must contain the vector which */
00079 /*          defines the elementary reflector H(i), for i = 1,2,...,k, as */
00080 /*          returned by DGERQF in the last k rows of its array argument */
00081 /*          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 DGERQF. */
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,M). */
00096 /*          For optimum performance LWORK >= M*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     lquery = *lwork == -1;
00134     if (*m < 0) {
00135         *info = -1;
00136     } else if (*n < *m) {
00137         *info = -2;
00138     } else if (*k < 0 || *k > *m) {
00139         *info = -3;
00140     } else if (*lda < max(1,*m)) {
00141         *info = -5;
00142     }
00143 
00144     if (*info == 0) {
00145         if (*m <= 0) {
00146             lwkopt = 1;
00147         } else {
00148             nb = ilaenv_(&c__1, "DORGRQ", " ", m, n, k, &c_n1);
00149             lwkopt = *m * nb;
00150         }
00151         work[1] = (doublereal) lwkopt;
00152 
00153         if (*lwork < max(1,*m) && ! lquery) {
00154             *info = -8;
00155         }
00156     }
00157 
00158     if (*info != 0) {
00159         i__1 = -(*info);
00160         xerbla_("DORGRQ", &i__1);
00161         return 0;
00162     } else if (lquery) {
00163         return 0;
00164     }
00165 
00166 /*     Quick return if possible */
00167 
00168     if (*m <= 0) {
00169         return 0;
00170     }
00171 
00172     nbmin = 2;
00173     nx = 0;
00174     iws = *m;
00175     if (nb > 1 && nb < *k) {
00176 
00177 /*        Determine when to cross over from blocked to unblocked code. */
00178 
00179 /* Computing MAX */
00180         i__1 = 0, i__2 = ilaenv_(&c__3, "DORGRQ", " ", m, n, k, &c_n1);
00181         nx = max(i__1,i__2);
00182         if (nx < *k) {
00183 
00184 /*           Determine if workspace is large enough for blocked code. */
00185 
00186             ldwork = *m;
00187             iws = ldwork * nb;
00188             if (*lwork < iws) {
00189 
00190 /*              Not enough workspace to use optimal NB:  reduce NB and */
00191 /*              determine the minimum value of NB. */
00192 
00193                 nb = *lwork / ldwork;
00194 /* Computing MAX */
00195                 i__1 = 2, i__2 = ilaenv_(&c__2, "DORGRQ", " ", m, n, k, &c_n1);
00196                 nbmin = max(i__1,i__2);
00197             }
00198         }
00199     }
00200 
00201     if (nb >= nbmin && nb < *k && nx < *k) {
00202 
00203 /*        Use blocked code after the first block. */
00204 /*        The last kk rows are handled by the block method. */
00205 
00206 /* Computing MIN */
00207         i__1 = *k, i__2 = (*k - nx + nb - 1) / nb * nb;
00208         kk = min(i__1,i__2);
00209 
00210 /*        Set A(1:m-kk,n-kk+1:n) to zero. */
00211 
00212         i__1 = *n;
00213         for (j = *n - kk + 1; j <= i__1; ++j) {
00214             i__2 = *m - kk;
00215             for (i__ = 1; i__ <= i__2; ++i__) {
00216                 a[i__ + j * a_dim1] = 0.;
00217 /* L10: */
00218             }
00219 /* L20: */
00220         }
00221     } else {
00222         kk = 0;
00223     }
00224 
00225 /*     Use unblocked code for the first or only block. */
00226 
00227     i__1 = *m - kk;
00228     i__2 = *n - kk;
00229     i__3 = *k - kk;
00230     dorgr2_(&i__1, &i__2, &i__3, &a[a_offset], lda, &tau[1], &work[1], &iinfo)
00231             ;
00232 
00233     if (kk > 0) {
00234 
00235 /*        Use blocked code */
00236 
00237         i__1 = *k;
00238         i__2 = nb;
00239         for (i__ = *k - kk + 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += 
00240                 i__2) {
00241 /* Computing MIN */
00242             i__3 = nb, i__4 = *k - i__ + 1;
00243             ib = min(i__3,i__4);
00244             ii = *m - *k + i__;
00245             if (ii > 1) {
00246 
00247 /*              Form the triangular factor of the block reflector */
00248 /*              H = H(i+ib-1) . . . H(i+1) H(i) */
00249 
00250                 i__3 = *n - *k + i__ + ib - 1;
00251                 dlarft_("Backward", "Rowwise", &i__3, &ib, &a[ii + a_dim1], 
00252                         lda, &tau[i__], &work[1], &ldwork);
00253 
00254 /*              Apply H' to A(1:m-k+i-1,1:n-k+i+ib-1) from the right */
00255 
00256                 i__3 = ii - 1;
00257                 i__4 = *n - *k + i__ + ib - 1;
00258                 dlarfb_("Right", "Transpose", "Backward", "Rowwise", &i__3, &
00259                         i__4, &ib, &a[ii + a_dim1], lda, &work[1], &ldwork, &
00260                         a[a_offset], lda, &work[ib + 1], &ldwork);
00261             }
00262 
00263 /*           Apply H' to columns 1:n-k+i+ib-1 of current block */
00264 
00265             i__3 = *n - *k + i__ + ib - 1;
00266             dorgr2_(&ib, &i__3, &ib, &a[ii + a_dim1], lda, &tau[i__], &work[1]
00267 , &iinfo);
00268 
00269 /*           Set columns n-k+i+ib:n of current block to zero */
00270 
00271             i__3 = *n;
00272             for (l = *n - *k + i__ + ib; l <= i__3; ++l) {
00273                 i__4 = ii + ib - 1;
00274                 for (j = ii; j <= i__4; ++j) {
00275                     a[j + l * a_dim1] = 0.;
00276 /* L30: */
00277                 }
00278 /* L40: */
00279             }
00280 /* L50: */
00281         }
00282     }
00283 
00284     work[1] = (doublereal) iws;
00285     return 0;
00286 
00287 /*     End of DORGRQ */
00288 
00289 } /* dorgrq_ */


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