Update to 2.0.0 tree from current Fremantle build
[opencv] / 3rdparty / lapack / slabrd.c
1 #include "clapack.h"
2
3 /* Table of constant values */
4
5 static real c_b4 = -1.f;
6 static real c_b5 = 1.f;
7 static integer c__1 = 1;
8 static real c_b16 = 0.f;
9
10 /* Subroutine */ int slabrd_(integer *m, integer *n, integer *nb, real *a, 
11         integer *lda, real *d__, real *e, real *tauq, real *taup, real *x, 
12         integer *ldx, real *y, integer *ldy)
13 {
14     /* System generated locals */
15     integer a_dim1, a_offset, x_dim1, x_offset, y_dim1, y_offset, i__1, i__2, 
16             i__3;
17
18     /* Local variables */
19     integer i__;
20     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *), 
21             sgemv_(char *, integer *, integer *, real *, real *, integer *, 
22             real *, integer *, real *, real *, integer *), slarfg_(
23             integer *, real *, real *, integer *, real *);
24
25
26 /*  -- LAPACK auxiliary routine (version 3.1) -- */
27 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
28 /*     November 2006 */
29
30 /*     .. Scalar Arguments .. */
31 /*     .. */
32 /*     .. Array Arguments .. */
33 /*     .. */
34
35 /*  Purpose */
36 /*  ======= */
37
38 /*  SLABRD reduces the first NB rows and columns of a real general */
39 /*  m by n matrix A to upper or lower bidiagonal form by an orthogonal */
40 /*  transformation Q' * A * P, and returns the matrices X and Y which */
41 /*  are needed to apply the transformation to the unreduced part of A. */
42
43 /*  If m >= n, A is reduced to upper bidiagonal form; if m < n, to lower */
44 /*  bidiagonal form. */
45
46 /*  This is an auxiliary routine called by SGEBRD */
47
48 /*  Arguments */
49 /*  ========= */
50
51 /*  M       (input) INTEGER */
52 /*          The number of rows in the matrix A. */
53
54 /*  N       (input) INTEGER */
55 /*          The number of columns in the matrix A. */
56
57 /*  NB      (input) INTEGER */
58 /*          The number of leading rows and columns of A to be reduced. */
59
60 /*  A       (input/output) REAL array, dimension (LDA,N) */
61 /*          On entry, the m by n general matrix to be reduced. */
62 /*          On exit, the first NB rows and columns of the matrix are */
63 /*          overwritten; the rest of the array is unchanged. */
64 /*          If m >= n, elements on and below the diagonal in the first NB */
65 /*            columns, with the array TAUQ, represent the orthogonal */
66 /*            matrix Q as a product of elementary reflectors; and */
67 /*            elements above the diagonal in the first NB rows, with the */
68 /*            array TAUP, represent the orthogonal matrix P as a product */
69 /*            of elementary reflectors. */
70 /*          If m < n, elements below the diagonal in the first NB */
71 /*            columns, with the array TAUQ, represent the orthogonal */
72 /*            matrix Q as a product of elementary reflectors, and */
73 /*            elements on and above the diagonal in the first NB rows, */
74 /*            with the array TAUP, represent the orthogonal matrix P as */
75 /*            a product of elementary reflectors. */
76 /*          See Further Details. */
77
78 /*  LDA     (input) INTEGER */
79 /*          The leading dimension of the array A.  LDA >= max(1,M). */
80
81 /*  D       (output) REAL array, dimension (NB) */
82 /*          The diagonal elements of the first NB rows and columns of */
83 /*          the reduced matrix.  D(i) = A(i,i). */
84
85 /*  E       (output) REAL array, dimension (NB) */
86 /*          The off-diagonal elements of the first NB rows and columns of */
87 /*          the reduced matrix. */
88
89 /*  TAUQ    (output) REAL array dimension (NB) */
90 /*          The scalar factors of the elementary reflectors which */
91 /*          represent the orthogonal matrix Q. See Further Details. */
92
93 /*  TAUP    (output) REAL array, dimension (NB) */
94 /*          The scalar factors of the elementary reflectors which */
95 /*          represent the orthogonal matrix P. See Further Details. */
96
97 /*  X       (output) REAL array, dimension (LDX,NB) */
98 /*          The m-by-nb matrix X required to update the unreduced part */
99 /*          of A. */
100
101 /*  LDX     (input) INTEGER */
102 /*          The leading dimension of the array X. LDX >= M. */
103
104 /*  Y       (output) REAL array, dimension (LDY,NB) */
105 /*          The n-by-nb matrix Y required to update the unreduced part */
106 /*          of A. */
107
108 /*  LDY     (input) INTEGER */
109 /*          The leading dimension of the array Y. LDY >= N. */
110
111 /*  Further Details */
112 /*  =============== */
113
114 /*  The matrices Q and P are represented as products of elementary */
115 /*  reflectors: */
116
117 /*     Q = H(1) H(2) . . . H(nb)  and  P = G(1) G(2) . . . G(nb) */
118
119 /*  Each H(i) and G(i) has the form: */
120
121 /*     H(i) = I - tauq * v * v'  and G(i) = I - taup * u * u' */
122
123 /*  where tauq and taup are real scalars, and v and u are real vectors. */
124
125 /*  If m >= n, v(1:i-1) = 0, v(i) = 1, and v(i:m) is stored on exit in */
126 /*  A(i:m,i); u(1:i) = 0, u(i+1) = 1, and u(i+1:n) is stored on exit in */
127 /*  A(i,i+1:n); tauq is stored in TAUQ(i) and taup in TAUP(i). */
128
129 /*  If m < n, v(1:i) = 0, v(i+1) = 1, and v(i+1:m) is stored on exit in */
130 /*  A(i+2:m,i); u(1:i-1) = 0, u(i) = 1, and u(i:n) is stored on exit in */
131 /*  A(i,i+1:n); tauq is stored in TAUQ(i) and taup in TAUP(i). */
132
133 /*  The elements of the vectors v and u together form the m-by-nb matrix */
134 /*  V and the nb-by-n matrix U' which are needed, with X and Y, to apply */
135 /*  the transformation to the unreduced part of the matrix, using a block */
136 /*  update of the form:  A := A - V*Y' - X*U'. */
137
138 /*  The contents of A on exit are illustrated by the following examples */
139 /*  with nb = 2: */
140
141 /*  m = 6 and n = 5 (m > n):          m = 5 and n = 6 (m < n): */
142
143 /*    (  1   1   u1  u1  u1 )           (  1   u1  u1  u1  u1  u1 ) */
144 /*    (  v1  1   1   u2  u2 )           (  1   1   u2  u2  u2  u2 ) */
145 /*    (  v1  v2  a   a   a  )           (  v1  1   a   a   a   a  ) */
146 /*    (  v1  v2  a   a   a  )           (  v1  v2  a   a   a   a  ) */
147 /*    (  v1  v2  a   a   a  )           (  v1  v2  a   a   a   a  ) */
148 /*    (  v1  v2  a   a   a  ) */
149
150 /*  where a denotes an element of the original matrix which is unchanged, */
151 /*  vi denotes an element of the vector defining H(i), and ui an element */
152 /*  of the vector defining G(i). */
153
154 /*  ===================================================================== */
155
156 /*     .. Parameters .. */
157 /*     .. */
158 /*     .. Local Scalars .. */
159 /*     .. */
160 /*     .. External Subroutines .. */
161 /*     .. */
162 /*     .. Intrinsic Functions .. */
163 /*     .. */
164 /*     .. Executable Statements .. */
165
166 /*     Quick return if possible */
167
168     /* Parameter adjustments */
169     a_dim1 = *lda;
170     a_offset = 1 + a_dim1;
171     a -= a_offset;
172     --d__;
173     --e;
174     --tauq;
175     --taup;
176     x_dim1 = *ldx;
177     x_offset = 1 + x_dim1;
178     x -= x_offset;
179     y_dim1 = *ldy;
180     y_offset = 1 + y_dim1;
181     y -= y_offset;
182
183     /* Function Body */
184     if (*m <= 0 || *n <= 0) {
185         return 0;
186     }
187
188     if (*m >= *n) {
189
190 /*        Reduce to upper bidiagonal form */
191
192         i__1 = *nb;
193         for (i__ = 1; i__ <= i__1; ++i__) {
194
195 /*           Update A(i:m,i) */
196
197             i__2 = *m - i__ + 1;
198             i__3 = i__ - 1;
199             sgemv_("No transpose", &i__2, &i__3, &c_b4, &a[i__ + a_dim1], lda, 
200                      &y[i__ + y_dim1], ldy, &c_b5, &a[i__ + i__ * a_dim1], &
201                     c__1);
202             i__2 = *m - i__ + 1;
203             i__3 = i__ - 1;
204             sgemv_("No transpose", &i__2, &i__3, &c_b4, &x[i__ + x_dim1], ldx, 
205                      &a[i__ * a_dim1 + 1], &c__1, &c_b5, &a[i__ + i__ * 
206                     a_dim1], &c__1);
207
208 /*           Generate reflection Q(i) to annihilate A(i+1:m,i) */
209
210             i__2 = *m - i__ + 1;
211 /* Computing MIN */
212             i__3 = i__ + 1;
213             slarfg_(&i__2, &a[i__ + i__ * a_dim1], &a[min(i__3, *m)+ i__ * 
214                     a_dim1], &c__1, &tauq[i__]);
215             d__[i__] = a[i__ + i__ * a_dim1];
216             if (i__ < *n) {
217                 a[i__ + i__ * a_dim1] = 1.f;
218
219 /*              Compute Y(i+1:n,i) */
220
221                 i__2 = *m - i__ + 1;
222                 i__3 = *n - i__;
223                 sgemv_("Transpose", &i__2, &i__3, &c_b5, &a[i__ + (i__ + 1) * 
224                         a_dim1], lda, &a[i__ + i__ * a_dim1], &c__1, &c_b16, &
225                         y[i__ + 1 + i__ * y_dim1], &c__1);
226                 i__2 = *m - i__ + 1;
227                 i__3 = i__ - 1;
228                 sgemv_("Transpose", &i__2, &i__3, &c_b5, &a[i__ + a_dim1], 
229                         lda, &a[i__ + i__ * a_dim1], &c__1, &c_b16, &y[i__ * 
230                         y_dim1 + 1], &c__1);
231                 i__2 = *n - i__;
232                 i__3 = i__ - 1;
233                 sgemv_("No transpose", &i__2, &i__3, &c_b4, &y[i__ + 1 + 
234                         y_dim1], ldy, &y[i__ * y_dim1 + 1], &c__1, &c_b5, &y[
235                         i__ + 1 + i__ * y_dim1], &c__1);
236                 i__2 = *m - i__ + 1;
237                 i__3 = i__ - 1;
238                 sgemv_("Transpose", &i__2, &i__3, &c_b5, &x[i__ + x_dim1], 
239                         ldx, &a[i__ + i__ * a_dim1], &c__1, &c_b16, &y[i__ * 
240                         y_dim1 + 1], &c__1);
241                 i__2 = i__ - 1;
242                 i__3 = *n - i__;
243                 sgemv_("Transpose", &i__2, &i__3, &c_b4, &a[(i__ + 1) * 
244                         a_dim1 + 1], lda, &y[i__ * y_dim1 + 1], &c__1, &c_b5, 
245                         &y[i__ + 1 + i__ * y_dim1], &c__1);
246                 i__2 = *n - i__;
247                 sscal_(&i__2, &tauq[i__], &y[i__ + 1 + i__ * y_dim1], &c__1);
248
249 /*              Update A(i,i+1:n) */
250
251                 i__2 = *n - i__;
252                 sgemv_("No transpose", &i__2, &i__, &c_b4, &y[i__ + 1 + 
253                         y_dim1], ldy, &a[i__ + a_dim1], lda, &c_b5, &a[i__ + (
254                         i__ + 1) * a_dim1], lda);
255                 i__2 = i__ - 1;
256                 i__3 = *n - i__;
257                 sgemv_("Transpose", &i__2, &i__3, &c_b4, &a[(i__ + 1) * 
258                         a_dim1 + 1], lda, &x[i__ + x_dim1], ldx, &c_b5, &a[
259                         i__ + (i__ + 1) * a_dim1], lda);
260
261 /*              Generate reflection P(i) to annihilate A(i,i+2:n) */
262
263                 i__2 = *n - i__;
264 /* Computing MIN */
265                 i__3 = i__ + 2;
266                 slarfg_(&i__2, &a[i__ + (i__ + 1) * a_dim1], &a[i__ + min(
267                         i__3, *n)* a_dim1], lda, &taup[i__]);
268                 e[i__] = a[i__ + (i__ + 1) * a_dim1];
269                 a[i__ + (i__ + 1) * a_dim1] = 1.f;
270
271 /*              Compute X(i+1:m,i) */
272
273                 i__2 = *m - i__;
274                 i__3 = *n - i__;
275                 sgemv_("No transpose", &i__2, &i__3, &c_b5, &a[i__ + 1 + (i__ 
276                         + 1) * a_dim1], lda, &a[i__ + (i__ + 1) * a_dim1], 
277                         lda, &c_b16, &x[i__ + 1 + i__ * x_dim1], &c__1);
278                 i__2 = *n - i__;
279                 sgemv_("Transpose", &i__2, &i__, &c_b5, &y[i__ + 1 + y_dim1], 
280                         ldy, &a[i__ + (i__ + 1) * a_dim1], lda, &c_b16, &x[
281                         i__ * x_dim1 + 1], &c__1);
282                 i__2 = *m - i__;
283                 sgemv_("No transpose", &i__2, &i__, &c_b4, &a[i__ + 1 + 
284                         a_dim1], lda, &x[i__ * x_dim1 + 1], &c__1, &c_b5, &x[
285                         i__ + 1 + i__ * x_dim1], &c__1);
286                 i__2 = i__ - 1;
287                 i__3 = *n - i__;
288                 sgemv_("No transpose", &i__2, &i__3, &c_b5, &a[(i__ + 1) * 
289                         a_dim1 + 1], lda, &a[i__ + (i__ + 1) * a_dim1], lda, &
290                         c_b16, &x[i__ * x_dim1 + 1], &c__1);
291                 i__2 = *m - i__;
292                 i__3 = i__ - 1;
293                 sgemv_("No transpose", &i__2, &i__3, &c_b4, &x[i__ + 1 + 
294                         x_dim1], ldx, &x[i__ * x_dim1 + 1], &c__1, &c_b5, &x[
295                         i__ + 1 + i__ * x_dim1], &c__1);
296                 i__2 = *m - i__;
297                 sscal_(&i__2, &taup[i__], &x[i__ + 1 + i__ * x_dim1], &c__1);
298             }
299 /* L10: */
300         }
301     } else {
302
303 /*        Reduce to lower bidiagonal form */
304
305         i__1 = *nb;
306         for (i__ = 1; i__ <= i__1; ++i__) {
307
308 /*           Update A(i,i:n) */
309
310             i__2 = *n - i__ + 1;
311             i__3 = i__ - 1;
312             sgemv_("No transpose", &i__2, &i__3, &c_b4, &y[i__ + y_dim1], ldy, 
313                      &a[i__ + a_dim1], lda, &c_b5, &a[i__ + i__ * a_dim1], 
314                     lda);
315             i__2 = i__ - 1;
316             i__3 = *n - i__ + 1;
317             sgemv_("Transpose", &i__2, &i__3, &c_b4, &a[i__ * a_dim1 + 1], 
318                     lda, &x[i__ + x_dim1], ldx, &c_b5, &a[i__ + i__ * a_dim1], 
319                      lda);
320
321 /*           Generate reflection P(i) to annihilate A(i,i+1:n) */
322
323             i__2 = *n - i__ + 1;
324 /* Computing MIN */
325             i__3 = i__ + 1;
326             slarfg_(&i__2, &a[i__ + i__ * a_dim1], &a[i__ + min(i__3, *n)* 
327                     a_dim1], lda, &taup[i__]);
328             d__[i__] = a[i__ + i__ * a_dim1];
329             if (i__ < *m) {
330                 a[i__ + i__ * a_dim1] = 1.f;
331
332 /*              Compute X(i+1:m,i) */
333
334                 i__2 = *m - i__;
335                 i__3 = *n - i__ + 1;
336                 sgemv_("No transpose", &i__2, &i__3, &c_b5, &a[i__ + 1 + i__ *
337                          a_dim1], lda, &a[i__ + i__ * a_dim1], lda, &c_b16, &
338                         x[i__ + 1 + i__ * x_dim1], &c__1);
339                 i__2 = *n - i__ + 1;
340                 i__3 = i__ - 1;
341                 sgemv_("Transpose", &i__2, &i__3, &c_b5, &y[i__ + y_dim1], 
342                         ldy, &a[i__ + i__ * a_dim1], lda, &c_b16, &x[i__ * 
343                         x_dim1 + 1], &c__1);
344                 i__2 = *m - i__;
345                 i__3 = i__ - 1;
346                 sgemv_("No transpose", &i__2, &i__3, &c_b4, &a[i__ + 1 + 
347                         a_dim1], lda, &x[i__ * x_dim1 + 1], &c__1, &c_b5, &x[
348                         i__ + 1 + i__ * x_dim1], &c__1);
349                 i__2 = i__ - 1;
350                 i__3 = *n - i__ + 1;
351                 sgemv_("No transpose", &i__2, &i__3, &c_b5, &a[i__ * a_dim1 + 
352                         1], lda, &a[i__ + i__ * a_dim1], lda, &c_b16, &x[i__ *
353                          x_dim1 + 1], &c__1);
354                 i__2 = *m - i__;
355                 i__3 = i__ - 1;
356                 sgemv_("No transpose", &i__2, &i__3, &c_b4, &x[i__ + 1 + 
357                         x_dim1], ldx, &x[i__ * x_dim1 + 1], &c__1, &c_b5, &x[
358                         i__ + 1 + i__ * x_dim1], &c__1);
359                 i__2 = *m - i__;
360                 sscal_(&i__2, &taup[i__], &x[i__ + 1 + i__ * x_dim1], &c__1);
361
362 /*              Update A(i+1:m,i) */
363
364                 i__2 = *m - i__;
365                 i__3 = i__ - 1;
366                 sgemv_("No transpose", &i__2, &i__3, &c_b4, &a[i__ + 1 + 
367                         a_dim1], lda, &y[i__ + y_dim1], ldy, &c_b5, &a[i__ + 
368                         1 + i__ * a_dim1], &c__1);
369                 i__2 = *m - i__;
370                 sgemv_("No transpose", &i__2, &i__, &c_b4, &x[i__ + 1 + 
371                         x_dim1], ldx, &a[i__ * a_dim1 + 1], &c__1, &c_b5, &a[
372                         i__ + 1 + i__ * a_dim1], &c__1);
373
374 /*              Generate reflection Q(i) to annihilate A(i+2:m,i) */
375
376                 i__2 = *m - i__;
377 /* Computing MIN */
378                 i__3 = i__ + 2;
379                 slarfg_(&i__2, &a[i__ + 1 + i__ * a_dim1], &a[min(i__3, *m)+ 
380                         i__ * a_dim1], &c__1, &tauq[i__]);
381                 e[i__] = a[i__ + 1 + i__ * a_dim1];
382                 a[i__ + 1 + i__ * a_dim1] = 1.f;
383
384 /*              Compute Y(i+1:n,i) */
385
386                 i__2 = *m - i__;
387                 i__3 = *n - i__;
388                 sgemv_("Transpose", &i__2, &i__3, &c_b5, &a[i__ + 1 + (i__ + 
389                         1) * a_dim1], lda, &a[i__ + 1 + i__ * a_dim1], &c__1, 
390                         &c_b16, &y[i__ + 1 + i__ * y_dim1], &c__1);
391                 i__2 = *m - i__;
392                 i__3 = i__ - 1;
393                 sgemv_("Transpose", &i__2, &i__3, &c_b5, &a[i__ + 1 + a_dim1], 
394                          lda, &a[i__ + 1 + i__ * a_dim1], &c__1, &c_b16, &y[
395                         i__ * y_dim1 + 1], &c__1);
396                 i__2 = *n - i__;
397                 i__3 = i__ - 1;
398                 sgemv_("No transpose", &i__2, &i__3, &c_b4, &y[i__ + 1 + 
399                         y_dim1], ldy, &y[i__ * y_dim1 + 1], &c__1, &c_b5, &y[
400                         i__ + 1 + i__ * y_dim1], &c__1);
401                 i__2 = *m - i__;
402                 sgemv_("Transpose", &i__2, &i__, &c_b5, &x[i__ + 1 + x_dim1], 
403                         ldx, &a[i__ + 1 + i__ * a_dim1], &c__1, &c_b16, &y[
404                         i__ * y_dim1 + 1], &c__1);
405                 i__2 = *n - i__;
406                 sgemv_("Transpose", &i__, &i__2, &c_b4, &a[(i__ + 1) * a_dim1 
407                         + 1], lda, &y[i__ * y_dim1 + 1], &c__1, &c_b5, &y[i__ 
408                         + 1 + i__ * y_dim1], &c__1);
409                 i__2 = *n - i__;
410                 sscal_(&i__2, &tauq[i__], &y[i__ + 1 + i__ * y_dim1], &c__1);
411             }
412 /* L20: */
413         }
414     }
415     return 0;
416
417 /*     End of SLABRD */
418
419 } /* slabrd_ */