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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:26