Update to 2.0.0 tree from current Fremantle build
[opencv] / 3rdparty / lapack / sgebd2.c
1 #include "clapack.h"
2
3 /* Table of constant values */
4
5 static integer c__1 = 1;
6
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)
9 {
10     /* System generated locals */
11     integer a_dim1, a_offset, i__1, i__2, i__3;
12
13     /* Local variables */
14     integer i__;
15     extern /* Subroutine */ int slarf_(char *, integer *, integer *, real *, 
16             integer *, real *, real *, integer *, real *), xerbla_(
17             char *, integer *), slarfg_(integer *, real *, real *, 
18             integer *, real *);
19
20
21 /*  -- LAPACK routine (version 3.1) -- */
22 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
23 /*     November 2006 */
24
25 /*     .. Scalar Arguments .. */
26 /*     .. */
27 /*     .. Array Arguments .. */
28 /*     .. */
29
30 /*  Purpose */
31 /*  ======= */
32
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. */
35
36 /*  If m >= n, B is upper bidiagonal; if m < n, B is lower bidiagonal. */
37
38 /*  Arguments */
39 /*  ========= */
40
41 /*  M       (input) INTEGER */
42 /*          The number of rows in the matrix A.  M >= 0. */
43
44 /*  N       (input) INTEGER */
45 /*          The number of columns in the matrix A.  N >= 0. */
46
47 /*  A       (input/output) REAL array, dimension (LDA,N) */
48 /*          On entry, the m by n general matrix to be reduced. */
49 /*          On exit, */
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. */
65
66 /*  LDA     (input) INTEGER */
67 /*          The leading dimension of the array A.  LDA >= max(1,M). */
68
69 /*  D       (output) REAL array, dimension (min(M,N)) */
70 /*          The diagonal elements of the bidiagonal matrix B: */
71 /*          D(i) = A(i,i). */
72
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. */
77
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. */
81
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. */
85
86 /*  WORK    (workspace) REAL array, dimension (max(M,N)) */
87
88 /*  INFO    (output) INTEGER */
89 /*          = 0: successful exit. */
90 /*          < 0: if INFO = -i, the i-th argument had an illegal value. */
91
92 /*  Further Details */
93 /*  =============== */
94
95 /*  The matrices Q and P are represented as products of elementary */
96 /*  reflectors: */
97
98 /*  If m >= n, */
99
100 /*     Q = H(1) H(2) . . . H(n)  and  P = G(1) G(2) . . . G(n-1) */
101
102 /*  Each H(i) and G(i) has the form: */
103
104 /*     H(i) = I - tauq * v * v'  and G(i) = I - taup * u * u' */
105
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). */
110
111 /*  If m < n, */
112
113 /*     Q = H(1) H(2) . . . H(m-1)  and  P = G(1) G(2) . . . G(m) */
114
115 /*  Each H(i) and G(i) has the form: */
116
117 /*     H(i) = I - tauq * v * v'  and G(i) = I - taup * u * u' */
118
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). */
123
124 /*  The contents of A on exit are illustrated by the following examples: */
125
126 /*  m = 6 and n = 5 (m > n):          m = 5 and n = 6 (m < n): */
127
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 ) */
134
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). */
138
139 /*  ===================================================================== */
140
141 /*     .. Parameters .. */
142 /*     .. */
143 /*     .. Local Scalars .. */
144 /*     .. */
145 /*     .. External Subroutines .. */
146 /*     .. */
147 /*     .. Intrinsic Functions .. */
148 /*     .. */
149 /*     .. Executable Statements .. */
150
151 /*     Test the input parameters */
152
153     /* Parameter adjustments */
154     a_dim1 = *lda;
155     a_offset = 1 + a_dim1;
156     a -= a_offset;
157     --d__;
158     --e;
159     --tauq;
160     --taup;
161     --work;
162
163     /* Function Body */
164     *info = 0;
165     if (*m < 0) {
166         *info = -1;
167     } else if (*n < 0) {
168         *info = -2;
169     } else if (*lda < max(1,*m)) {
170         *info = -4;
171     }
172     if (*info < 0) {
173         i__1 = -(*info);
174         xerbla_("SGEBD2", &i__1);
175         return 0;
176     }
177
178     if (*m >= *n) {
179
180 /*        Reduce to upper bidiagonal form */
181
182         i__1 = *n;
183         for (i__ = 1; i__ <= i__1; ++i__) {
184
185 /*           Generate elementary reflector H(i) to annihilate A(i+1:m,i) */
186
187             i__2 = *m - i__ + 1;
188 /* Computing MIN */
189             i__3 = i__ + 1;
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;
194
195 /*           Apply H(i) to A(i:m,i+1:n) from the left */
196
197             if (i__ < *n) {
198                 i__2 = *m - i__ + 1;
199                 i__3 = *n - i__;
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]
202 );
203             }
204             a[i__ + i__ * a_dim1] = d__[i__];
205
206             if (i__ < *n) {
207
208 /*              Generate elementary reflector G(i) to annihilate */
209 /*              A(i,i+2:n) */
210
211                 i__2 = *n - i__;
212 /* Computing MIN */
213                 i__3 = i__ + 2;
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;
218
219 /*              Apply G(i) to A(i+1:m,i+1:n) from the right */
220
221                 i__2 = *m - i__;
222                 i__3 = *n - i__;
223                 slarf_("Right", &i__2, &i__3, &a[i__ + (i__ + 1) * a_dim1], 
224                         lda, &taup[i__], &a[i__ + 1 + (i__ + 1) * a_dim1], 
225                         lda, &work[1]);
226                 a[i__ + (i__ + 1) * a_dim1] = e[i__];
227             } else {
228                 taup[i__] = 0.f;
229             }
230 /* L10: */
231         }
232     } else {
233
234 /*        Reduce to lower bidiagonal form */
235
236         i__1 = *m;
237         for (i__ = 1; i__ <= i__1; ++i__) {
238
239 /*           Generate elementary reflector G(i) to annihilate A(i,i+1:n) */
240
241             i__2 = *n - i__ + 1;
242 /* Computing MIN */
243             i__3 = i__ + 1;
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;
248
249 /*           Apply G(i) to A(i+1:m,i:n) from the right */
250
251             if (i__ < *m) {
252                 i__2 = *m - i__;
253                 i__3 = *n - i__ + 1;
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]);
256             }
257             a[i__ + i__ * a_dim1] = d__[i__];
258
259             if (i__ < *m) {
260
261 /*              Generate elementary reflector H(i) to annihilate */
262 /*              A(i+2:m,i) */
263
264                 i__2 = *m - i__;
265 /* Computing MIN */
266                 i__3 = i__ + 2;
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;
271
272 /*              Apply H(i) to A(i+1:m,i+1:n) from the left */
273
274                 i__2 = *m - i__;
275                 i__3 = *n - i__;
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], 
278                         lda, &work[1]);
279                 a[i__ + 1 + i__ * a_dim1] = e[i__];
280             } else {
281                 tauq[i__] = 0.f;
282             }
283 /* L20: */
284         }
285     }
286     return 0;
287
288 /*     End of SGEBD2 */
289
290 } /* sgebd2_ */