00001 /* dgebrd.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 static doublereal c_b21 = -1.; 00023 static doublereal c_b22 = 1.; 00024 00025 /* Subroutine */ int dgebrd_(integer *m, integer *n, doublereal *a, integer * 00026 lda, doublereal *d__, doublereal *e, doublereal *tauq, doublereal * 00027 taup, doublereal *work, integer *lwork, integer *info) 00028 { 00029 /* System generated locals */ 00030 integer a_dim1, a_offset, i__1, i__2, i__3, i__4; 00031 00032 /* Local variables */ 00033 integer i__, j, nb, nx; 00034 doublereal ws; 00035 extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *, 00036 integer *, doublereal *, doublereal *, integer *, doublereal *, 00037 integer *, doublereal *, doublereal *, integer *); 00038 integer nbmin, iinfo, minmn; 00039 extern /* Subroutine */ int dgebd2_(integer *, integer *, doublereal *, 00040 integer *, doublereal *, doublereal *, doublereal *, doublereal *, 00041 doublereal *, integer *), dlabrd_(integer *, integer *, integer * 00042 , doublereal *, integer *, doublereal *, doublereal *, doublereal 00043 *, doublereal *, doublereal *, integer *, doublereal *, integer *) 00044 , 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 /* DGEBRD reduces a general real M-by-N matrix A to upper or lower */ 00064 /* bidiagonal form B by an orthogonal transformation: Q**T * 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) DOUBLE PRECISION 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 orthogonal matrix Q as a product of elementary */ 00084 /* reflectors, and the elements above the first superdiagonal, */ 00085 /* with the array TAUP, represent the orthogonal 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 orthogonal matrix Q as a product of */ 00091 /* elementary reflectors, and the elements above the diagonal, */ 00092 /* with the array TAUP, represent the orthogonal 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) DOUBLE PRECISION array, dimension (min(M,N)) */ 00100 /* The diagonal elements of the bidiagonal matrix B: */ 00101 /* D(i) = A(i,i). */ 00102 00103 /* E (output) DOUBLE PRECISION 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) DOUBLE PRECISION array dimension (min(M,N)) */ 00109 /* The scalar factors of the elementary reflectors which */ 00110 /* represent the orthogonal matrix Q. See Further Details. */ 00111 00112 /* TAUP (output) DOUBLE PRECISION array, dimension (min(M,N)) */ 00113 /* The scalar factors of the elementary reflectors which */ 00114 /* represent the orthogonal matrix P. See Further Details. */ 00115 00116 /* WORK (workspace/output) DOUBLE PRECISION 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 real scalars, and v and u are real vectors; */ 00148 /* v(1:i-1) = 0, v(i) = 1, and v(i+1:m) is stored on exit in A(i+1:m,i); */ 00149 /* u(1:i) = 0, u(i+1) = 1, and u(i+2:n) is stored on exit in A(i,i+2:n); */ 00150 /* 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 real scalars, and v and u are real vectors; */ 00161 /* v(1:i) = 0, v(i+1) = 1, and v(i+2:m) is stored on exit in A(i+2:m,i); */ 00162 /* u(1:i-1) = 0, u(i) = 1, and u(i+1:n) is stored on exit in A(i,i+1:n); */ 00163 /* 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, "DGEBRD", " ", m, n, &c_n1, &c_n1); 00210 nb = max(i__1,i__2); 00211 lwkopt = (*m + *n) * nb; 00212 work[1] = (doublereal) lwkopt; 00213 lquery = *lwork == -1; 00214 if (*m < 0) { 00215 *info = -1; 00216 } else if (*n < 0) { 00217 *info = -2; 00218 } else if (*lda < max(1,*m)) { 00219 *info = -4; 00220 } else /* if(complicated condition) */ { 00221 /* Computing MAX */ 00222 i__1 = max(1,*m); 00223 if (*lwork < max(i__1,*n) && ! lquery) { 00224 *info = -10; 00225 } 00226 } 00227 if (*info < 0) { 00228 i__1 = -(*info); 00229 xerbla_("DGEBRD", &i__1); 00230 return 0; 00231 } else if (lquery) { 00232 return 0; 00233 } 00234 00235 /* Quick return if possible */ 00236 00237 minmn = min(*m,*n); 00238 if (minmn == 0) { 00239 work[1] = 1.; 00240 return 0; 00241 } 00242 00243 ws = (doublereal) max(*m,*n); 00244 ldwrkx = *m; 00245 ldwrky = *n; 00246 00247 if (nb > 1 && nb < minmn) { 00248 00249 /* Set the crossover point NX. */ 00250 00251 /* Computing MAX */ 00252 i__1 = nb, i__2 = ilaenv_(&c__3, "DGEBRD", " ", m, n, &c_n1, &c_n1); 00253 nx = max(i__1,i__2); 00254 00255 /* Determine when to switch from blocked to unblocked code. */ 00256 00257 if (nx < minmn) { 00258 ws = (doublereal) ((*m + *n) * nb); 00259 if ((doublereal) (*lwork) < ws) { 00260 00261 /* Not enough work space for the optimal NB, consider using */ 00262 /* a smaller block size. */ 00263 00264 nbmin = ilaenv_(&c__2, "DGEBRD", " ", m, n, &c_n1, &c_n1); 00265 if (*lwork >= (*m + *n) * nbmin) { 00266 nb = *lwork / (*m + *n); 00267 } else { 00268 nb = 1; 00269 nx = minmn; 00270 } 00271 } 00272 } 00273 } else { 00274 nx = minmn; 00275 } 00276 00277 i__1 = minmn - nx; 00278 i__2 = nb; 00279 for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) { 00280 00281 /* Reduce rows and columns i:i+nb-1 to bidiagonal form and return */ 00282 /* the matrices X and Y which are needed to update the unreduced */ 00283 /* part of the matrix */ 00284 00285 i__3 = *m - i__ + 1; 00286 i__4 = *n - i__ + 1; 00287 dlabrd_(&i__3, &i__4, &nb, &a[i__ + i__ * a_dim1], lda, &d__[i__], &e[ 00288 i__], &tauq[i__], &taup[i__], &work[1], &ldwrkx, &work[ldwrkx 00289 * nb + 1], &ldwrky); 00290 00291 /* Update the trailing submatrix A(i+nb:m,i+nb:n), using an update */ 00292 /* of the form A := A - V*Y' - X*U' */ 00293 00294 i__3 = *m - i__ - nb + 1; 00295 i__4 = *n - i__ - nb + 1; 00296 dgemm_("No transpose", "Transpose", &i__3, &i__4, &nb, &c_b21, &a[i__ 00297 + nb + i__ * a_dim1], lda, &work[ldwrkx * nb + nb + 1], & 00298 ldwrky, &c_b22, &a[i__ + nb + (i__ + nb) * a_dim1], lda); 00299 i__3 = *m - i__ - nb + 1; 00300 i__4 = *n - i__ - nb + 1; 00301 dgemm_("No transpose", "No transpose", &i__3, &i__4, &nb, &c_b21, & 00302 work[nb + 1], &ldwrkx, &a[i__ + (i__ + nb) * a_dim1], lda, & 00303 c_b22, &a[i__ + nb + (i__ + nb) * a_dim1], lda); 00304 00305 /* Copy diagonal and off-diagonal elements of B back into A */ 00306 00307 if (*m >= *n) { 00308 i__3 = i__ + nb - 1; 00309 for (j = i__; j <= i__3; ++j) { 00310 a[j + j * a_dim1] = d__[j]; 00311 a[j + (j + 1) * a_dim1] = e[j]; 00312 /* L10: */ 00313 } 00314 } else { 00315 i__3 = i__ + nb - 1; 00316 for (j = i__; j <= i__3; ++j) { 00317 a[j + j * a_dim1] = d__[j]; 00318 a[j + 1 + j * a_dim1] = e[j]; 00319 /* L20: */ 00320 } 00321 } 00322 /* L30: */ 00323 } 00324 00325 /* Use unblocked code to reduce the remainder of the matrix */ 00326 00327 i__2 = *m - i__ + 1; 00328 i__1 = *n - i__ + 1; 00329 dgebd2_(&i__2, &i__1, &a[i__ + i__ * a_dim1], lda, &d__[i__], &e[i__], & 00330 tauq[i__], &taup[i__], &work[1], &iinfo); 00331 work[1] = ws; 00332 return 0; 00333 00334 /* End of DGEBRD */ 00335 00336 } /* dgebrd_ */