zgebrd.c
Go to the documentation of this file.
00001 /* zgebrd.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 doublecomplex c_b1 = {1.,0.};
00019 static integer c__1 = 1;
00020 static integer c_n1 = -1;
00021 static integer c__3 = 3;
00022 static integer c__2 = 2;
00023 
00024 /* Subroutine */ int zgebrd_(integer *m, integer *n, doublecomplex *a, 
00025         integer *lda, doublereal *d__, doublereal *e, doublecomplex *tauq, 
00026         doublecomplex *taup, doublecomplex *work, integer *lwork, integer *
00027         info)
00028 {
00029     /* System generated locals */
00030     integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
00031     doublereal d__1;
00032     doublecomplex z__1;
00033 
00034     /* Local variables */
00035     integer i__, j, nb, nx;
00036     doublereal ws;
00037     integer nbmin, iinfo, minmn;
00038     extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *, 
00039             integer *, doublecomplex *, doublecomplex *, integer *, 
00040             doublecomplex *, integer *, doublecomplex *, doublecomplex *, 
00041             integer *), zgebd2_(integer *, integer *, 
00042             doublecomplex *, integer *, doublereal *, doublereal *, 
00043             doublecomplex *, doublecomplex *, doublecomplex *, integer *), 
00044             xerbla_(char *, integer *), zlabrd_(integer *, integer *, 
00045             integer *, doublecomplex *, integer *, doublereal *, doublereal *, 
00046              doublecomplex *, doublecomplex *, doublecomplex *, integer *, 
00047             doublecomplex *, integer *);
00048     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00049             integer *, integer *);
00050     integer ldwrkx, ldwrky, lwkopt;
00051     logical lquery;
00052 
00053 
00054 /*  -- LAPACK routine (version 3.2) -- */
00055 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00056 /*     November 2006 */
00057 
00058 /*     .. Scalar Arguments .. */
00059 /*     .. */
00060 /*     .. Array Arguments .. */
00061 /*     .. */
00062 
00063 /*  Purpose */
00064 /*  ======= */
00065 
00066 /*  ZGEBRD reduces a general complex M-by-N matrix A to upper or lower */
00067 /*  bidiagonal form B by a unitary transformation: Q**H * A * P = B. */
00068 
00069 /*  If m >= n, B is upper bidiagonal; if m < n, B is lower bidiagonal. */
00070 
00071 /*  Arguments */
00072 /*  ========= */
00073 
00074 /*  M       (input) INTEGER */
00075 /*          The number of rows in the matrix A.  M >= 0. */
00076 
00077 /*  N       (input) INTEGER */
00078 /*          The number of columns in the matrix A.  N >= 0. */
00079 
00080 /*  A       (input/output) COMPLEX*16 array, dimension (LDA,N) */
00081 /*          On entry, the M-by-N general matrix to be reduced. */
00082 /*          On exit, */
00083 /*          if m >= n, the diagonal and the first superdiagonal are */
00084 /*            overwritten with the upper bidiagonal matrix B; the */
00085 /*            elements below the diagonal, with the array TAUQ, represent */
00086 /*            the unitary matrix Q as a product of elementary */
00087 /*            reflectors, and the elements above the first superdiagonal, */
00088 /*            with the array TAUP, represent the unitary matrix P as */
00089 /*            a product of elementary reflectors; */
00090 /*          if m < n, the diagonal and the first subdiagonal are */
00091 /*            overwritten with the lower bidiagonal matrix B; the */
00092 /*            elements below the first subdiagonal, with the array TAUQ, */
00093 /*            represent the unitary matrix Q as a product of */
00094 /*            elementary reflectors, and the elements above the diagonal, */
00095 /*            with the array TAUP, represent the unitary matrix P as */
00096 /*            a product of elementary reflectors. */
00097 /*          See Further Details. */
00098 
00099 /*  LDA     (input) INTEGER */
00100 /*          The leading dimension of the array A.  LDA >= max(1,M). */
00101 
00102 /*  D       (output) DOUBLE PRECISION array, dimension (min(M,N)) */
00103 /*          The diagonal elements of the bidiagonal matrix B: */
00104 /*          D(i) = A(i,i). */
00105 
00106 /*  E       (output) DOUBLE PRECISION array, dimension (min(M,N)-1) */
00107 /*          The off-diagonal elements of the bidiagonal matrix B: */
00108 /*          if m >= n, E(i) = A(i,i+1) for i = 1,2,...,n-1; */
00109 /*          if m < n, E(i) = A(i+1,i) for i = 1,2,...,m-1. */
00110 
00111 /*  TAUQ    (output) COMPLEX*16 array dimension (min(M,N)) */
00112 /*          The scalar factors of the elementary reflectors which */
00113 /*          represent the unitary matrix Q. See Further Details. */
00114 
00115 /*  TAUP    (output) COMPLEX*16 array, dimension (min(M,N)) */
00116 /*          The scalar factors of the elementary reflectors which */
00117 /*          represent the unitary matrix P. See Further Details. */
00118 
00119 /*  WORK    (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */
00120 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00121 
00122 /*  LWORK   (input) INTEGER */
00123 /*          The length of the array WORK.  LWORK >= max(1,M,N). */
00124 /*          For optimum performance LWORK >= (M+N)*NB, where NB */
00125 /*          is the optimal blocksize. */
00126 
00127 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00128 /*          only calculates the optimal size of the WORK array, returns */
00129 /*          this value as the first entry of the WORK array, and no error */
00130 /*          message related to LWORK is issued by XERBLA. */
00131 
00132 /*  INFO    (output) INTEGER */
00133 /*          = 0:  successful exit. */
00134 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00135 
00136 /*  Further Details */
00137 /*  =============== */
00138 
00139 /*  The matrices Q and P are represented as products of elementary */
00140 /*  reflectors: */
00141 
00142 /*  If m >= n, */
00143 
00144 /*     Q = H(1) H(2) . . . H(n)  and  P = G(1) G(2) . . . G(n-1) */
00145 
00146 /*  Each H(i) and G(i) has the form: */
00147 
00148 /*     H(i) = I - tauq * v * v'  and G(i) = I - taup * u * u' */
00149 
00150 /*  where tauq and taup are complex scalars, and v and u are complex */
00151 /*  vectors; v(1:i-1) = 0, v(i) = 1, and v(i+1:m) is stored on exit in */
00152 /*  A(i+1:m,i); u(1:i) = 0, u(i+1) = 1, and u(i+2:n) is stored on exit in */
00153 /*  A(i,i+2:n); tauq is stored in TAUQ(i) and taup in TAUP(i). */
00154 
00155 /*  If m < n, */
00156 
00157 /*     Q = H(1) H(2) . . . H(m-1)  and  P = G(1) G(2) . . . G(m) */
00158 
00159 /*  Each H(i) and G(i) has the form: */
00160 
00161 /*     H(i) = I - tauq * v * v'  and G(i) = I - taup * u * u' */
00162 
00163 /*  where tauq and taup are complex scalars, and v and u are complex */
00164 /*  vectors; v(1:i) = 0, v(i+1) = 1, and v(i+2:m) is stored on exit in */
00165 /*  A(i+2:m,i); u(1:i-1) = 0, u(i) = 1, and u(i+1:n) is stored on exit in */
00166 /*  A(i,i+1:n); tauq is stored in TAUQ(i) and taup in TAUP(i). */
00167 
00168 /*  The contents of A on exit are illustrated by the following examples: */
00169 
00170 /*  m = 6 and n = 5 (m > n):          m = 5 and n = 6 (m < n): */
00171 
00172 /*    (  d   e   u1  u1  u1 )           (  d   u1  u1  u1  u1  u1 ) */
00173 /*    (  v1  d   e   u2  u2 )           (  e   d   u2  u2  u2  u2 ) */
00174 /*    (  v1  v2  d   e   u3 )           (  v1  e   d   u3  u3  u3 ) */
00175 /*    (  v1  v2  v3  d   e  )           (  v1  v2  e   d   u4  u4 ) */
00176 /*    (  v1  v2  v3  v4  d  )           (  v1  v2  v3  e   d   u5 ) */
00177 /*    (  v1  v2  v3  v4  v5 ) */
00178 
00179 /*  where d and e denote diagonal and off-diagonal elements of B, vi */
00180 /*  denotes an element of the vector defining H(i), and ui an element of */
00181 /*  the vector defining G(i). */
00182 
00183 /*  ===================================================================== */
00184 
00185 /*     .. Parameters .. */
00186 /*     .. */
00187 /*     .. Local Scalars .. */
00188 /*     .. */
00189 /*     .. External Subroutines .. */
00190 /*     .. */
00191 /*     .. Intrinsic Functions .. */
00192 /*     .. */
00193 /*     .. External Functions .. */
00194 /*     .. */
00195 /*     .. Executable Statements .. */
00196 
00197 /*     Test the input parameters */
00198 
00199     /* Parameter adjustments */
00200     a_dim1 = *lda;
00201     a_offset = 1 + a_dim1;
00202     a -= a_offset;
00203     --d__;
00204     --e;
00205     --tauq;
00206     --taup;
00207     --work;
00208 
00209     /* Function Body */
00210     *info = 0;
00211 /* Computing MAX */
00212     i__1 = 1, i__2 = ilaenv_(&c__1, "ZGEBRD", " ", m, n, &c_n1, &c_n1);
00213     nb = max(i__1,i__2);
00214     lwkopt = (*m + *n) * nb;
00215     d__1 = (doublereal) lwkopt;
00216     work[1].r = d__1, work[1].i = 0.;
00217     lquery = *lwork == -1;
00218     if (*m < 0) {
00219         *info = -1;
00220     } else if (*n < 0) {
00221         *info = -2;
00222     } else if (*lda < max(1,*m)) {
00223         *info = -4;
00224     } else /* if(complicated condition) */ {
00225 /* Computing MAX */
00226         i__1 = max(1,*m);
00227         if (*lwork < max(i__1,*n) && ! lquery) {
00228             *info = -10;
00229         }
00230     }
00231     if (*info < 0) {
00232         i__1 = -(*info);
00233         xerbla_("ZGEBRD", &i__1);
00234         return 0;
00235     } else if (lquery) {
00236         return 0;
00237     }
00238 
00239 /*     Quick return if possible */
00240 
00241     minmn = min(*m,*n);
00242     if (minmn == 0) {
00243         work[1].r = 1., work[1].i = 0.;
00244         return 0;
00245     }
00246 
00247     ws = (doublereal) max(*m,*n);
00248     ldwrkx = *m;
00249     ldwrky = *n;
00250 
00251     if (nb > 1 && nb < minmn) {
00252 
00253 /*        Set the crossover point NX. */
00254 
00255 /* Computing MAX */
00256         i__1 = nb, i__2 = ilaenv_(&c__3, "ZGEBRD", " ", m, n, &c_n1, &c_n1);
00257         nx = max(i__1,i__2);
00258 
00259 /*        Determine when to switch from blocked to unblocked code. */
00260 
00261         if (nx < minmn) {
00262             ws = (doublereal) ((*m + *n) * nb);
00263             if ((doublereal) (*lwork) < ws) {
00264 
00265 /*              Not enough work space for the optimal NB, consider using */
00266 /*              a smaller block size. */
00267 
00268                 nbmin = ilaenv_(&c__2, "ZGEBRD", " ", m, n, &c_n1, &c_n1);
00269                 if (*lwork >= (*m + *n) * nbmin) {
00270                     nb = *lwork / (*m + *n);
00271                 } else {
00272                     nb = 1;
00273                     nx = minmn;
00274                 }
00275             }
00276         }
00277     } else {
00278         nx = minmn;
00279     }
00280 
00281     i__1 = minmn - nx;
00282     i__2 = nb;
00283     for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
00284 
00285 /*        Reduce rows and columns i:i+ib-1 to bidiagonal form and return */
00286 /*        the matrices X and Y which are needed to update the unreduced */
00287 /*        part of the matrix */
00288 
00289         i__3 = *m - i__ + 1;
00290         i__4 = *n - i__ + 1;
00291         zlabrd_(&i__3, &i__4, &nb, &a[i__ + i__ * a_dim1], lda, &d__[i__], &e[
00292                 i__], &tauq[i__], &taup[i__], &work[1], &ldwrkx, &work[ldwrkx 
00293                 * nb + 1], &ldwrky);
00294 
00295 /*        Update the trailing submatrix A(i+ib:m,i+ib:n), using */
00296 /*        an update of the form  A := A - V*Y' - X*U' */
00297 
00298         i__3 = *m - i__ - nb + 1;
00299         i__4 = *n - i__ - nb + 1;
00300         z__1.r = -1., z__1.i = -0.;
00301         zgemm_("No transpose", "Conjugate transpose", &i__3, &i__4, &nb, &
00302                 z__1, &a[i__ + nb + i__ * a_dim1], lda, &work[ldwrkx * nb + 
00303                 nb + 1], &ldwrky, &c_b1, &a[i__ + nb + (i__ + nb) * a_dim1], 
00304                 lda);
00305         i__3 = *m - i__ - nb + 1;
00306         i__4 = *n - i__ - nb + 1;
00307         z__1.r = -1., z__1.i = -0.;
00308         zgemm_("No transpose", "No transpose", &i__3, &i__4, &nb, &z__1, &
00309                 work[nb + 1], &ldwrkx, &a[i__ + (i__ + nb) * a_dim1], lda, &
00310                 c_b1, &a[i__ + nb + (i__ + nb) * a_dim1], lda);
00311 
00312 /*        Copy diagonal and off-diagonal elements of B back into A */
00313 
00314         if (*m >= *n) {
00315             i__3 = i__ + nb - 1;
00316             for (j = i__; j <= i__3; ++j) {
00317                 i__4 = j + j * a_dim1;
00318                 i__5 = j;
00319                 a[i__4].r = d__[i__5], a[i__4].i = 0.;
00320                 i__4 = j + (j + 1) * a_dim1;
00321                 i__5 = j;
00322                 a[i__4].r = e[i__5], a[i__4].i = 0.;
00323 /* L10: */
00324             }
00325         } else {
00326             i__3 = i__ + nb - 1;
00327             for (j = i__; j <= i__3; ++j) {
00328                 i__4 = j + j * a_dim1;
00329                 i__5 = j;
00330                 a[i__4].r = d__[i__5], a[i__4].i = 0.;
00331                 i__4 = j + 1 + j * a_dim1;
00332                 i__5 = j;
00333                 a[i__4].r = e[i__5], a[i__4].i = 0.;
00334 /* L20: */
00335             }
00336         }
00337 /* L30: */
00338     }
00339 
00340 /*     Use unblocked code to reduce the remainder of the matrix */
00341 
00342     i__2 = *m - i__ + 1;
00343     i__1 = *n - i__ + 1;
00344     zgebd2_(&i__2, &i__1, &a[i__ + i__ * a_dim1], lda, &d__[i__], &e[i__], &
00345             tauq[i__], &taup[i__], &work[1], &iinfo);
00346     work[1].r = ws, work[1].i = 0.;
00347     return 0;
00348 
00349 /*     End of ZGEBRD */
00350 
00351 } /* zgebrd_ */


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