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


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