sgerqf.c
Go to the documentation of this file.
00001 /* sgerqf.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 sgerqf_(integer *m, integer *n, real *a, integer *lda, 
00024         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__, k, ib, nb, ki, kk, mu, nu, nx, iws, nbmin, iinfo;
00031     extern /* Subroutine */ int sgerq2_(integer *, integer *, real *, integer 
00032             *, real *, real *, integer *), slarfb_(char *, char *, char *, 
00033             char *, integer *, integer *, integer *, real *, integer *, real *
00034 , 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 /*  SGERQF computes an RQ factorization of a real M-by-N matrix A: */
00056 /*  A = R * Q. */
00057 
00058 /*  Arguments */
00059 /*  ========= */
00060 
00061 /*  M       (input) INTEGER */
00062 /*          The number of rows of the matrix A.  M >= 0. */
00063 
00064 /*  N       (input) INTEGER */
00065 /*          The number of columns of the matrix A.  N >= 0. */
00066 
00067 /*  A       (input/output) REAL array, dimension (LDA,N) */
00068 /*          On entry, the M-by-N matrix A. */
00069 /*          On exit, */
00070 /*          if m <= n, the upper triangle of the subarray */
00071 /*          A(1:m,n-m+1:n) contains the M-by-M upper triangular matrix R; */
00072 /*          if m >= n, the elements on and above the (m-n)-th subdiagonal */
00073 /*          contain the M-by-N upper trapezoidal matrix R; */
00074 /*          the remaining elements, with the array TAU, represent the */
00075 /*          orthogonal matrix Q as a product of min(m,n) elementary */
00076 /*          reflectors (see Further Details). */
00077 
00078 /*  LDA     (input) INTEGER */
00079 /*          The leading dimension of the array A.  LDA >= max(1,M). */
00080 
00081 /*  TAU     (output) REAL array, dimension (min(M,N)) */
00082 /*          The scalar factors of the elementary reflectors (see Further */
00083 /*          Details). */
00084 
00085 /*  WORK    (workspace/output) REAL array, dimension (MAX(1,LWORK)) */
00086 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00087 
00088 /*  LWORK   (input) INTEGER */
00089 /*          The dimension of the array WORK.  LWORK >= max(1,M). */
00090 /*          For optimum performance LWORK >= M*NB, where NB is */
00091 /*          the optimal blocksize. */
00092 
00093 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00094 /*          only calculates the optimal size of the WORK array, returns */
00095 /*          this value as the first entry of the WORK array, and no error */
00096 /*          message related to LWORK is issued by XERBLA. */
00097 
00098 /*  INFO    (output) INTEGER */
00099 /*          = 0:  successful exit */
00100 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00101 
00102 /*  Further Details */
00103 /*  =============== */
00104 
00105 /*  The matrix Q is represented as a product of elementary reflectors */
00106 
00107 /*     Q = H(1) H(2) . . . H(k), where k = min(m,n). */
00108 
00109 /*  Each H(i) has the form */
00110 
00111 /*     H(i) = I - tau * v * v' */
00112 
00113 /*  where tau is a real scalar, and v is a real vector with */
00114 /*  v(n-k+i+1:n) = 0 and v(n-k+i) = 1; v(1:n-k+i-1) is stored on exit in */
00115 /*  A(m-k+i,1:n-k+i-1), and tau in TAU(i). */
00116 
00117 /*  ===================================================================== */
00118 
00119 /*     .. Local Scalars .. */
00120 /*     .. */
00121 /*     .. External Subroutines .. */
00122 /*     .. */
00123 /*     .. Intrinsic Functions .. */
00124 /*     .. */
00125 /*     .. External Functions .. */
00126 /*     .. */
00127 /*     .. Executable Statements .. */
00128 
00129 /*     Test the input arguments */
00130 
00131     /* Parameter adjustments */
00132     a_dim1 = *lda;
00133     a_offset = 1 + a_dim1;
00134     a -= a_offset;
00135     --tau;
00136     --work;
00137 
00138     /* Function Body */
00139     *info = 0;
00140     lquery = *lwork == -1;
00141     if (*m < 0) {
00142         *info = -1;
00143     } else if (*n < 0) {
00144         *info = -2;
00145     } else if (*lda < max(1,*m)) {
00146         *info = -4;
00147     } else if (*lwork < max(1,*m) && ! lquery) {
00148         *info = -7;
00149     }
00150 
00151     if (*info == 0) {
00152         k = min(*m,*n);
00153         if (k == 0) {
00154             lwkopt = 1;
00155         } else {
00156             nb = ilaenv_(&c__1, "SGERQF", " ", m, n, &c_n1, &c_n1);
00157             lwkopt = *m * nb;
00158             work[1] = (real) lwkopt;
00159         }
00160         work[1] = (real) lwkopt;
00161 
00162         if (*lwork < max(1,*m) && ! lquery) {
00163             *info = -7;
00164         }
00165     }
00166 
00167     if (*info != 0) {
00168         i__1 = -(*info);
00169         xerbla_("SGERQF", &i__1);
00170         return 0;
00171     } else if (lquery) {
00172         return 0;
00173     }
00174 
00175 /*     Quick return if possible */
00176 
00177     if (k == 0) {
00178         return 0;
00179     }
00180 
00181     nbmin = 2;
00182     nx = 1;
00183     iws = *m;
00184     if (nb > 1 && nb < k) {
00185 
00186 /*        Determine when to cross over from blocked to unblocked code. */
00187 
00188 /* Computing MAX */
00189         i__1 = 0, i__2 = ilaenv_(&c__3, "SGERQF", " ", m, n, &c_n1, &c_n1);
00190         nx = max(i__1,i__2);
00191         if (nx < k) {
00192 
00193 /*           Determine if workspace is large enough for blocked code. */
00194 
00195             ldwork = *m;
00196             iws = ldwork * nb;
00197             if (*lwork < iws) {
00198 
00199 /*              Not enough workspace to use optimal NB:  reduce NB and */
00200 /*              determine the minimum value of NB. */
00201 
00202                 nb = *lwork / ldwork;
00203 /* Computing MAX */
00204                 i__1 = 2, i__2 = ilaenv_(&c__2, "SGERQF", " ", m, n, &c_n1, &
00205                         c_n1);
00206                 nbmin = max(i__1,i__2);
00207             }
00208         }
00209     }
00210 
00211     if (nb >= nbmin && nb < k && nx < k) {
00212 
00213 /*        Use blocked code initially. */
00214 /*        The last kk rows are handled by the block method. */
00215 
00216         ki = (k - nx - 1) / nb * nb;
00217 /* Computing MIN */
00218         i__1 = k, i__2 = ki + nb;
00219         kk = min(i__1,i__2);
00220 
00221         i__1 = k - kk + 1;
00222         i__2 = -nb;
00223         for (i__ = k - kk + ki + 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ 
00224                 += i__2) {
00225 /* Computing MIN */
00226             i__3 = k - i__ + 1;
00227             ib = min(i__3,nb);
00228 
00229 /*           Compute the RQ factorization of the current block */
00230 /*           A(m-k+i:m-k+i+ib-1,1:n-k+i+ib-1) */
00231 
00232             i__3 = *n - k + i__ + ib - 1;
00233             sgerq2_(&ib, &i__3, &a[*m - k + i__ + a_dim1], lda, &tau[i__], &
00234                     work[1], &iinfo);
00235             if (*m - k + i__ > 1) {
00236 
00237 /*              Form the triangular factor of the block reflector */
00238 /*              H = H(i+ib-1) . . . H(i+1) H(i) */
00239 
00240                 i__3 = *n - k + i__ + ib - 1;
00241                 slarft_("Backward", "Rowwise", &i__3, &ib, &a[*m - k + i__ + 
00242                         a_dim1], lda, &tau[i__], &work[1], &ldwork);
00243 
00244 /*              Apply H to A(1:m-k+i-1,1:n-k+i+ib-1) from the right */
00245 
00246                 i__3 = *m - k + i__ - 1;
00247                 i__4 = *n - k + i__ + ib - 1;
00248                 slarfb_("Right", "No transpose", "Backward", "Rowwise", &i__3, 
00249                          &i__4, &ib, &a[*m - k + i__ + a_dim1], lda, &work[1], 
00250                          &ldwork, &a[a_offset], lda, &work[ib + 1], &ldwork);
00251             }
00252 /* L10: */
00253         }
00254         mu = *m - k + i__ + nb - 1;
00255         nu = *n - k + i__ + nb - 1;
00256     } else {
00257         mu = *m;
00258         nu = *n;
00259     }
00260 
00261 /*     Use unblocked code to factor the last or only block */
00262 
00263     if (mu > 0 && nu > 0) {
00264         sgerq2_(&mu, &nu, &a[a_offset], lda, &tau[1], &work[1], &iinfo);
00265     }
00266 
00267     work[1] = (real) iws;
00268     return 0;
00269 
00270 /*     End of SGERQF */
00271 
00272 } /* sgerqf_ */


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