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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:12