ztzrzf.c
Go to the documentation of this file.
00001 /* ztzrzf.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 ztzrzf_(integer *m, integer *n, doublecomplex *a, 
00024         integer *lda, doublecomplex *tau, doublecomplex *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, i__5;
00029 
00030     /* Local variables */
00031     integer i__, m1, ib, nb, ki, kk, mu, nx, iws, nbmin;
00032     extern /* Subroutine */ int xerbla_(char *, integer *);
00033     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00034             integer *, integer *);
00035     integer ldwork;
00036     extern /* Subroutine */ int zlarzb_(char *, char *, char *, char *, 
00037             integer *, integer *, integer *, integer *, doublecomplex *, 
00038             integer *, doublecomplex *, integer *, doublecomplex *, integer *, 
00039              doublecomplex *, integer *);
00040     integer lwkopt;
00041     logical lquery;
00042     extern /* Subroutine */ int zlarzt_(char *, char *, integer *, integer *, 
00043             doublecomplex *, integer *, doublecomplex *, doublecomplex *, 
00044             integer *), zlatrz_(integer *, integer *, integer 
00045             *, doublecomplex *, integer *, doublecomplex *, doublecomplex *);
00046 
00047 
00048 /*  -- LAPACK routine (version 3.2) -- */
00049 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00050 /*     November 2006 */
00051 
00052 /*     .. Scalar Arguments .. */
00053 /*     .. */
00054 /*     .. Array Arguments .. */
00055 /*     .. */
00056 
00057 /*  Purpose */
00058 /*  ======= */
00059 
00060 /*  ZTZRZF reduces the M-by-N ( M<=N ) complex upper trapezoidal matrix A */
00061 /*  to upper triangular form by means of unitary transformations. */
00062 
00063 /*  The upper trapezoidal matrix A is factored as */
00064 
00065 /*     A = ( R  0 ) * Z, */
00066 
00067 /*  where Z is an N-by-N unitary matrix and R is an M-by-M upper */
00068 /*  triangular matrix. */
00069 
00070 /*  Arguments */
00071 /*  ========= */
00072 
00073 /*  M       (input) INTEGER */
00074 /*          The number of rows of the matrix A.  M >= 0. */
00075 
00076 /*  N       (input) INTEGER */
00077 /*          The number of columns of the matrix A.  N >= M. */
00078 
00079 /*  A       (input/output) COMPLEX*16 array, dimension (LDA,N) */
00080 /*          On entry, the leading M-by-N upper trapezoidal part of the */
00081 /*          array A must contain the matrix to be factorized. */
00082 /*          On exit, the leading M-by-M upper triangular part of A */
00083 /*          contains the upper triangular matrix R, and elements M+1 to */
00084 /*          N of the first M rows of A, with the array TAU, represent the */
00085 /*          unitary matrix Z as a product of M elementary reflectors. */
00086 
00087 /*  LDA     (input) INTEGER */
00088 /*          The leading dimension of the array A.  LDA >= max(1,M). */
00089 
00090 /*  TAU     (output) COMPLEX*16 array, dimension (M) */
00091 /*          The scalar factors of the elementary reflectors. */
00092 
00093 /*  WORK    (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */
00094 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00095 
00096 /*  LWORK   (input) INTEGER */
00097 /*          The dimension of the array WORK.  LWORK >= max(1,M). */
00098 /*          For optimum performance LWORK >= M*NB, where NB is */
00099 /*          the optimal blocksize. */
00100 
00101 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00102 /*          only calculates the optimal size of the WORK array, returns */
00103 /*          this value as the first entry of the WORK array, and no error */
00104 /*          message related to LWORK is issued by XERBLA. */
00105 
00106 /*  INFO    (output) INTEGER */
00107 /*          = 0:  successful exit */
00108 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00109 
00110 /*  Further Details */
00111 /*  =============== */
00112 
00113 /*  Based on contributions by */
00114 /*    A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA */
00115 
00116 /*  The factorization is obtained by Householder's method.  The kth */
00117 /*  transformation matrix, Z( k ), which is used to introduce zeros into */
00118 /*  the ( m - k + 1 )th row of A, is given in the form */
00119 
00120 /*     Z( k ) = ( I     0   ), */
00121 /*              ( 0  T( k ) ) */
00122 
00123 /*  where */
00124 
00125 /*     T( k ) = I - tau*u( k )*u( k )',   u( k ) = (   1    ), */
00126 /*                                                 (   0    ) */
00127 /*                                                 ( z( k ) ) */
00128 
00129 /*  tau is a scalar and z( k ) is an ( n - m ) element vector. */
00130 /*  tau and z( k ) are chosen to annihilate the elements of the kth row */
00131 /*  of X. */
00132 
00133 /*  The scalar tau is returned in the kth element of TAU and the vector */
00134 /*  u( k ) in the kth row of A, such that the elements of z( k ) are */
00135 /*  in  a( k, m + 1 ), ..., a( k, n ). The elements of R are returned in */
00136 /*  the upper triangular part of A. */
00137 
00138 /*  Z is given by */
00139 
00140 /*     Z =  Z( 1 ) * Z( 2 ) * ... * Z( m ). */
00141 
00142 /*  ===================================================================== */
00143 
00144 /*     .. Parameters .. */
00145 /*     .. */
00146 /*     .. Local Scalars .. */
00147 /*     .. */
00148 /*     .. External Subroutines .. */
00149 /*     .. */
00150 /*     .. Intrinsic Functions .. */
00151 /*     .. */
00152 /*     .. External Functions .. */
00153 /*     .. */
00154 /*     .. Executable Statements .. */
00155 
00156 /*     Test the input arguments */
00157 
00158     /* Parameter adjustments */
00159     a_dim1 = *lda;
00160     a_offset = 1 + a_dim1;
00161     a -= a_offset;
00162     --tau;
00163     --work;
00164 
00165     /* Function Body */
00166     *info = 0;
00167     lquery = *lwork == -1;
00168     if (*m < 0) {
00169         *info = -1;
00170     } else if (*n < *m) {
00171         *info = -2;
00172     } else if (*lda < max(1,*m)) {
00173         *info = -4;
00174     }
00175 
00176     if (*info == 0) {
00177         if (*m == 0 || *m == *n) {
00178             lwkopt = 1;
00179         } else {
00180 
00181 /*           Determine the block size. */
00182 
00183             nb = ilaenv_(&c__1, "ZGERQF", " ", m, n, &c_n1, &c_n1);
00184             lwkopt = *m * nb;
00185         }
00186         work[1].r = (doublereal) lwkopt, work[1].i = 0.;
00187 
00188         if (*lwork < max(1,*m) && ! lquery) {
00189             *info = -7;
00190         }
00191     }
00192 
00193     if (*info != 0) {
00194         i__1 = -(*info);
00195         xerbla_("ZTZRZF", &i__1);
00196         return 0;
00197     } else if (lquery) {
00198         return 0;
00199     }
00200 
00201 /*     Quick return if possible */
00202 
00203     if (*m == 0) {
00204         return 0;
00205     } else if (*m == *n) {
00206         i__1 = *n;
00207         for (i__ = 1; i__ <= i__1; ++i__) {
00208             i__2 = i__;
00209             tau[i__2].r = 0., tau[i__2].i = 0.;
00210 /* L10: */
00211         }
00212         return 0;
00213     }
00214 
00215     nbmin = 2;
00216     nx = 1;
00217     iws = *m;
00218     if (nb > 1 && nb < *m) {
00219 
00220 /*        Determine when to cross over from blocked to unblocked code. */
00221 
00222 /* Computing MAX */
00223         i__1 = 0, i__2 = ilaenv_(&c__3, "ZGERQF", " ", m, n, &c_n1, &c_n1);
00224         nx = max(i__1,i__2);
00225         if (nx < *m) {
00226 
00227 /*           Determine if workspace is large enough for blocked code. */
00228 
00229             ldwork = *m;
00230             iws = ldwork * nb;
00231             if (*lwork < iws) {
00232 
00233 /*              Not enough workspace to use optimal NB:  reduce NB and */
00234 /*              determine the minimum value of NB. */
00235 
00236                 nb = *lwork / ldwork;
00237 /* Computing MAX */
00238                 i__1 = 2, i__2 = ilaenv_(&c__2, "ZGERQF", " ", m, n, &c_n1, &
00239                         c_n1);
00240                 nbmin = max(i__1,i__2);
00241             }
00242         }
00243     }
00244 
00245     if (nb >= nbmin && nb < *m && nx < *m) {
00246 
00247 /*        Use blocked code initially. */
00248 /*        The last kk rows are handled by the block method. */
00249 
00250 /* Computing MIN */
00251         i__1 = *m + 1;
00252         m1 = min(i__1,*n);
00253         ki = (*m - nx - 1) / nb * nb;
00254 /* Computing MIN */
00255         i__1 = *m, i__2 = ki + nb;
00256         kk = min(i__1,i__2);
00257 
00258         i__1 = *m - kk + 1;
00259         i__2 = -nb;
00260         for (i__ = *m - kk + ki + 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; 
00261                 i__ += i__2) {
00262 /* Computing MIN */
00263             i__3 = *m - i__ + 1;
00264             ib = min(i__3,nb);
00265 
00266 /*           Compute the TZ factorization of the current block */
00267 /*           A(i:i+ib-1,i:n) */
00268 
00269             i__3 = *n - i__ + 1;
00270             i__4 = *n - *m;
00271             zlatrz_(&ib, &i__3, &i__4, &a[i__ + i__ * a_dim1], lda, &tau[i__], 
00272                      &work[1]);
00273             if (i__ > 1) {
00274 
00275 /*              Form the triangular factor of the block reflector */
00276 /*              H = H(i+ib-1) . . . H(i+1) H(i) */
00277 
00278                 i__3 = *n - *m;
00279                 zlarzt_("Backward", "Rowwise", &i__3, &ib, &a[i__ + m1 * 
00280                         a_dim1], lda, &tau[i__], &work[1], &ldwork);
00281 
00282 /*              Apply H to A(1:i-1,i:n) from the right */
00283 
00284                 i__3 = i__ - 1;
00285                 i__4 = *n - i__ + 1;
00286                 i__5 = *n - *m;
00287                 zlarzb_("Right", "No transpose", "Backward", "Rowwise", &i__3, 
00288                          &i__4, &ib, &i__5, &a[i__ + m1 * a_dim1], lda, &work[
00289                         1], &ldwork, &a[i__ * a_dim1 + 1], lda, &work[ib + 1], 
00290                          &ldwork)
00291                         ;
00292             }
00293 /* L20: */
00294         }
00295         mu = i__ + nb - 1;
00296     } else {
00297         mu = *m;
00298     }
00299 
00300 /*     Use unblocked code to factor the last or only block */
00301 
00302     if (mu > 0) {
00303         i__2 = *n - *m;
00304         zlatrz_(&mu, n, &i__2, &a[a_offset], lda, &tau[1], &work[1]);
00305     }
00306 
00307     work[1].r = (doublereal) lwkopt, work[1].i = 0.;
00308 
00309     return 0;
00310 
00311 /*     End of ZTZRZF */
00312 
00313 } /* ztzrzf_ */


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