3 /* Table of constant values */
5 static integer c__1 = 1;
7 /* Subroutine */ int sgebd2_(integer *m, integer *n, real *a, integer *lda,
8 real *d__, real *e, real *tauq, real *taup, real *work, integer *info)
10 /* System generated locals */
11 integer a_dim1, a_offset, i__1, i__2, i__3;
15 extern /* Subroutine */ int slarf_(char *, integer *, integer *, real *,
16 integer *, real *, real *, integer *, real *), xerbla_(
17 char *, integer *), slarfg_(integer *, real *, real *,
21 /* -- LAPACK routine (version 3.1) -- */
22 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
25 /* .. Scalar Arguments .. */
27 /* .. Array Arguments .. */
33 /* SGEBD2 reduces a real general m by n matrix A to upper or lower */
34 /* bidiagonal form B by an orthogonal transformation: Q' * A * P = B. */
36 /* If m >= n, B is upper bidiagonal; if m < n, B is lower bidiagonal. */
41 /* M (input) INTEGER */
42 /* The number of rows in the matrix A. M >= 0. */
44 /* N (input) INTEGER */
45 /* The number of columns in the matrix A. N >= 0. */
47 /* A (input/output) REAL array, dimension (LDA,N) */
48 /* On entry, the m by n general matrix to be reduced. */
50 /* if m >= n, the diagonal and the first superdiagonal are */
51 /* overwritten with the upper bidiagonal matrix B; the */
52 /* elements below the diagonal, with the array TAUQ, represent */
53 /* the orthogonal matrix Q as a product of elementary */
54 /* reflectors, and the elements above the first superdiagonal, */
55 /* with the array TAUP, represent the orthogonal matrix P as */
56 /* a product of elementary reflectors; */
57 /* if m < n, the diagonal and the first subdiagonal are */
58 /* overwritten with the lower bidiagonal matrix B; the */
59 /* elements below the first subdiagonal, with the array TAUQ, */
60 /* represent the orthogonal matrix Q as a product of */
61 /* elementary reflectors, and the elements above the diagonal, */
62 /* with the array TAUP, represent the orthogonal matrix P as */
63 /* a product of elementary reflectors. */
64 /* See Further Details. */
66 /* LDA (input) INTEGER */
67 /* The leading dimension of the array A. LDA >= max(1,M). */
69 /* D (output) REAL array, dimension (min(M,N)) */
70 /* The diagonal elements of the bidiagonal matrix B: */
73 /* E (output) REAL array, dimension (min(M,N)-1) */
74 /* The off-diagonal elements of the bidiagonal matrix B: */
75 /* if m >= n, E(i) = A(i,i+1) for i = 1,2,...,n-1; */
76 /* if m < n, E(i) = A(i+1,i) for i = 1,2,...,m-1. */
78 /* TAUQ (output) REAL array dimension (min(M,N)) */
79 /* The scalar factors of the elementary reflectors which */
80 /* represent the orthogonal matrix Q. See Further Details. */
82 /* TAUP (output) REAL array, dimension (min(M,N)) */
83 /* The scalar factors of the elementary reflectors which */
84 /* represent the orthogonal matrix P. See Further Details. */
86 /* WORK (workspace) REAL array, dimension (max(M,N)) */
88 /* INFO (output) INTEGER */
89 /* = 0: successful exit. */
90 /* < 0: if INFO = -i, the i-th argument had an illegal value. */
95 /* The matrices Q and P are represented as products of elementary */
100 /* Q = H(1) H(2) . . . H(n) and P = G(1) G(2) . . . G(n-1) */
102 /* Each H(i) and G(i) has the form: */
104 /* H(i) = I - tauq * v * v' and G(i) = I - taup * u * u' */
106 /* where tauq and taup are real scalars, and v and u are real vectors; */
107 /* v(1:i-1) = 0, v(i) = 1, and v(i+1:m) is stored on exit in A(i+1:m,i); */
108 /* u(1:i) = 0, u(i+1) = 1, and u(i+2:n) is stored on exit in A(i,i+2:n); */
109 /* tauq is stored in TAUQ(i) and taup in TAUP(i). */
113 /* Q = H(1) H(2) . . . H(m-1) and P = G(1) G(2) . . . G(m) */
115 /* Each H(i) and G(i) has the form: */
117 /* H(i) = I - tauq * v * v' and G(i) = I - taup * u * u' */
119 /* where tauq and taup are real scalars, and v and u are real vectors; */
120 /* v(1:i) = 0, v(i+1) = 1, and v(i+2:m) is stored on exit in A(i+2:m,i); */
121 /* u(1:i-1) = 0, u(i) = 1, and u(i+1:n) is stored on exit in A(i,i+1:n); */
122 /* tauq is stored in TAUQ(i) and taup in TAUP(i). */
124 /* The contents of A on exit are illustrated by the following examples: */
126 /* m = 6 and n = 5 (m > n): m = 5 and n = 6 (m < n): */
128 /* ( d e u1 u1 u1 ) ( d u1 u1 u1 u1 u1 ) */
129 /* ( v1 d e u2 u2 ) ( e d u2 u2 u2 u2 ) */
130 /* ( v1 v2 d e u3 ) ( v1 e d u3 u3 u3 ) */
131 /* ( v1 v2 v3 d e ) ( v1 v2 e d u4 u4 ) */
132 /* ( v1 v2 v3 v4 d ) ( v1 v2 v3 e d u5 ) */
133 /* ( v1 v2 v3 v4 v5 ) */
135 /* where d and e denote diagonal and off-diagonal elements of B, vi */
136 /* denotes an element of the vector defining H(i), and ui an element of */
137 /* the vector defining G(i). */
139 /* ===================================================================== */
141 /* .. Parameters .. */
143 /* .. Local Scalars .. */
145 /* .. External Subroutines .. */
147 /* .. Intrinsic Functions .. */
149 /* .. Executable Statements .. */
151 /* Test the input parameters */
153 /* Parameter adjustments */
155 a_offset = 1 + a_dim1;
169 } else if (*lda < max(1,*m)) {
174 xerbla_("SGEBD2", &i__1);
180 /* Reduce to upper bidiagonal form */
183 for (i__ = 1; i__ <= i__1; ++i__) {
185 /* Generate elementary reflector H(i) to annihilate A(i+1:m,i) */
190 slarfg_(&i__2, &a[i__ + i__ * a_dim1], &a[min(i__3, *m)+ i__ *
191 a_dim1], &c__1, &tauq[i__]);
192 d__[i__] = a[i__ + i__ * a_dim1];
193 a[i__ + i__ * a_dim1] = 1.f;
195 /* Apply H(i) to A(i:m,i+1:n) from the left */
200 slarf_("Left", &i__2, &i__3, &a[i__ + i__ * a_dim1], &c__1, &
201 tauq[i__], &a[i__ + (i__ + 1) * a_dim1], lda, &work[1]
204 a[i__ + i__ * a_dim1] = d__[i__];
208 /* Generate elementary reflector G(i) to annihilate */
214 slarfg_(&i__2, &a[i__ + (i__ + 1) * a_dim1], &a[i__ + min(
215 i__3, *n)* a_dim1], lda, &taup[i__]);
216 e[i__] = a[i__ + (i__ + 1) * a_dim1];
217 a[i__ + (i__ + 1) * a_dim1] = 1.f;
219 /* Apply G(i) to A(i+1:m,i+1:n) from the right */
223 slarf_("Right", &i__2, &i__3, &a[i__ + (i__ + 1) * a_dim1],
224 lda, &taup[i__], &a[i__ + 1 + (i__ + 1) * a_dim1],
226 a[i__ + (i__ + 1) * a_dim1] = e[i__];
234 /* Reduce to lower bidiagonal form */
237 for (i__ = 1; i__ <= i__1; ++i__) {
239 /* Generate elementary reflector G(i) to annihilate A(i,i+1:n) */
244 slarfg_(&i__2, &a[i__ + i__ * a_dim1], &a[i__ + min(i__3, *n)*
245 a_dim1], lda, &taup[i__]);
246 d__[i__] = a[i__ + i__ * a_dim1];
247 a[i__ + i__ * a_dim1] = 1.f;
249 /* Apply G(i) to A(i+1:m,i:n) from the right */
254 slarf_("Right", &i__2, &i__3, &a[i__ + i__ * a_dim1], lda, &
255 taup[i__], &a[i__ + 1 + i__ * a_dim1], lda, &work[1]);
257 a[i__ + i__ * a_dim1] = d__[i__];
261 /* Generate elementary reflector H(i) to annihilate */
267 slarfg_(&i__2, &a[i__ + 1 + i__ * a_dim1], &a[min(i__3, *m)+
268 i__ * a_dim1], &c__1, &tauq[i__]);
269 e[i__] = a[i__ + 1 + i__ * a_dim1];
270 a[i__ + 1 + i__ * a_dim1] = 1.f;
272 /* Apply H(i) to A(i+1:m,i+1:n) from the left */
276 slarf_("Left", &i__2, &i__3, &a[i__ + 1 + i__ * a_dim1], &
277 c__1, &tauq[i__], &a[i__ + 1 + (i__ + 1) * a_dim1],
279 a[i__ + 1 + i__ * a_dim1] = e[i__];