Update to 2.0.0 tree from current Fremantle build
[opencv] / 3rdparty / lapack / sormlq.c
1 #include "clapack.h"
2
3 /* Table of constant values */
4
5 static integer c__1 = 1;
6 static integer c_n1 = -1;
7 static integer c__2 = 2;
8 static integer c__65 = 65;
9
10 /* Subroutine */ int sormlq_(char *side, char *trans, integer *m, integer *n, 
11         integer *k, real *a, integer *lda, real *tau, real *c__, integer *ldc, 
12          real *work, integer *lwork, integer *info)
13 {
14     /* System generated locals */
15     address a__1[2];
16     integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3[2], i__4, 
17             i__5;
18     char ch__1[2];
19
20     /* Builtin functions */
21     /* Subroutine */ int s_cat(char *, char **, integer *, integer *, ftnlen);
22
23     /* Local variables */
24     integer i__;
25     real t[4160]        /* was [65][64] */;
26     integer i1, i2, i3, ib, ic, jc, nb, mi, ni, nq, nw, iws;
27     logical left;
28     extern logical lsame_(char *, char *);
29     integer nbmin, iinfo;
30     extern /* Subroutine */ int sorml2_(char *, char *, integer *, integer *, 
31             integer *, real *, integer *, real *, real *, integer *, real *, 
32             integer *), slarfb_(char *, char *, char *, char *
33 , integer *, integer *, integer *, real *, integer *, real *, 
34             integer *, real *, integer *, real *, integer *), xerbla_(char *, integer *);
35     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
36             integer *, integer *);
37     extern /* Subroutine */ int slarft_(char *, char *, integer *, integer *, 
38             real *, integer *, real *, real *, integer *);
39     logical notran;
40     integer ldwork;
41     char transt[1];
42     integer lwkopt;
43     logical lquery;
44
45
46 /*  -- LAPACK routine (version 3.1) -- */
47 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
48 /*     November 2006 */
49
50 /*     .. Scalar Arguments .. */
51 /*     .. */
52 /*     .. Array Arguments .. */
53 /*     .. */
54
55 /*  Purpose */
56 /*  ======= */
57
58 /*  SORMLQ overwrites the general real M-by-N matrix C with */
59
60 /*                  SIDE = 'L'     SIDE = 'R' */
61 /*  TRANS = 'N':      Q * C          C * Q */
62 /*  TRANS = 'T':      Q**T * C       C * Q**T */
63
64 /*  where Q is a real orthogonal matrix defined as the product of k */
65 /*  elementary reflectors */
66
67 /*        Q = H(k) . . . H(2) H(1) */
68
69 /*  as returned by SGELQF. Q is of order M if SIDE = 'L' and of order N */
70 /*  if SIDE = 'R'. */
71
72 /*  Arguments */
73 /*  ========= */
74
75 /*  SIDE    (input) CHARACTER*1 */
76 /*          = 'L': apply Q or Q**T from the Left; */
77 /*          = 'R': apply Q or Q**T from the Right. */
78
79 /*  TRANS   (input) CHARACTER*1 */
80 /*          = 'N':  No transpose, apply Q; */
81 /*          = 'T':  Transpose, apply Q**T. */
82
83 /*  M       (input) INTEGER */
84 /*          The number of rows of the matrix C. M >= 0. */
85
86 /*  N       (input) INTEGER */
87 /*          The number of columns of the matrix C. N >= 0. */
88
89 /*  K       (input) INTEGER */
90 /*          The number of elementary reflectors whose product defines */
91 /*          the matrix Q. */
92 /*          If SIDE = 'L', M >= K >= 0; */
93 /*          if SIDE = 'R', N >= K >= 0. */
94
95 /*  A       (input) REAL array, dimension */
96 /*                               (LDA,M) if SIDE = 'L', */
97 /*                               (LDA,N) if SIDE = 'R' */
98 /*          The i-th row must contain the vector which defines the */
99 /*          elementary reflector H(i), for i = 1,2,...,k, as returned by */
100 /*          SGELQF in the first k rows of its array argument A. */
101 /*          A is modified by the routine but restored on exit. */
102
103 /*  LDA     (input) INTEGER */
104 /*          The leading dimension of the array A. LDA >= max(1,K). */
105
106 /*  TAU     (input) REAL array, dimension (K) */
107 /*          TAU(i) must contain the scalar factor of the elementary */
108 /*          reflector H(i), as returned by SGELQF. */
109
110 /*  C       (input/output) REAL array, dimension (LDC,N) */
111 /*          On entry, the M-by-N matrix C. */
112 /*          On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q. */
113
114 /*  LDC     (input) INTEGER */
115 /*          The leading dimension of the array C. LDC >= max(1,M). */
116
117 /*  WORK    (workspace/output) REAL array, dimension (MAX(1,LWORK)) */
118 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
119
120 /*  LWORK   (input) INTEGER */
121 /*          The dimension of the array WORK. */
122 /*          If SIDE = 'L', LWORK >= max(1,N); */
123 /*          if SIDE = 'R', LWORK >= max(1,M). */
124 /*          For optimum performance LWORK >= N*NB if SIDE = 'L', and */
125 /*          LWORK >= M*NB if SIDE = 'R', where NB is the optimal */
126 /*          blocksize. */
127
128 /*          If LWORK = -1, then a workspace query is assumed; the routine */
129 /*          only calculates the optimal size of the WORK array, returns */
130 /*          this value as the first entry of the WORK array, and no error */
131 /*          message related to LWORK is issued by XERBLA. */
132
133 /*  INFO    (output) INTEGER */
134 /*          = 0:  successful exit */
135 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
136
137 /*  ===================================================================== */
138
139 /*     .. Parameters .. */
140 /*     .. */
141 /*     .. Local Scalars .. */
142 /*     .. */
143 /*     .. Local Arrays .. */
144 /*     .. */
145 /*     .. External Functions .. */
146 /*     .. */
147 /*     .. External Subroutines .. */
148 /*     .. */
149 /*     .. Intrinsic Functions .. */
150 /*     .. */
151 /*     .. Executable Statements .. */
152
153 /*     Test the input arguments */
154
155     /* Parameter adjustments */
156     a_dim1 = *lda;
157     a_offset = 1 + a_dim1;
158     a -= a_offset;
159     --tau;
160     c_dim1 = *ldc;
161     c_offset = 1 + c_dim1;
162     c__ -= c_offset;
163     --work;
164
165     /* Function Body */
166     *info = 0;
167     left = lsame_(side, "L");
168     notran = lsame_(trans, "N");
169     lquery = *lwork == -1;
170
171 /*     NQ is the order of Q and NW is the minimum dimension of WORK */
172
173     if (left) {
174         nq = *m;
175         nw = *n;
176     } else {
177         nq = *n;
178         nw = *m;
179     }
180     if (! left && ! lsame_(side, "R")) {
181         *info = -1;
182     } else if (! notran && ! lsame_(trans, "T")) {
183         *info = -2;
184     } else if (*m < 0) {
185         *info = -3;
186     } else if (*n < 0) {
187         *info = -4;
188     } else if (*k < 0 || *k > nq) {
189         *info = -5;
190     } else if (*lda < max(1,*k)) {
191         *info = -7;
192     } else if (*ldc < max(1,*m)) {
193         *info = -10;
194     } else if (*lwork < max(1,nw) && ! lquery) {
195         *info = -12;
196     }
197
198     if (*info == 0) {
199
200 /*        Determine the block size.  NB may be at most NBMAX, where NBMAX */
201 /*        is used to define the local array T. */
202
203 /* Computing MIN */
204 /* Writing concatenation */
205         i__3[0] = 1, a__1[0] = side;
206         i__3[1] = 1, a__1[1] = trans;
207         s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
208         i__1 = 64, i__2 = ilaenv_(&c__1, "SORMLQ", ch__1, m, n, k, &c_n1);
209         nb = min(i__1,i__2);
210         lwkopt = max(1,nw) * nb;
211         work[1] = (real) lwkopt;
212     }
213
214     if (*info != 0) {
215         i__1 = -(*info);
216         xerbla_("SORMLQ", &i__1);
217         return 0;
218     } else if (lquery) {
219         return 0;
220     }
221
222 /*     Quick return if possible */
223
224     if (*m == 0 || *n == 0 || *k == 0) {
225         work[1] = 1.f;
226         return 0;
227     }
228
229     nbmin = 2;
230     ldwork = nw;
231     if (nb > 1 && nb < *k) {
232         iws = nw * nb;
233         if (*lwork < iws) {
234             nb = *lwork / ldwork;
235 /* Computing MAX */
236 /* Writing concatenation */
237             i__3[0] = 1, a__1[0] = side;
238             i__3[1] = 1, a__1[1] = trans;
239             s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
240             i__1 = 2, i__2 = ilaenv_(&c__2, "SORMLQ", ch__1, m, n, k, &c_n1);
241             nbmin = max(i__1,i__2);
242         }
243     } else {
244         iws = nw;
245     }
246
247     if (nb < nbmin || nb >= *k) {
248
249 /*        Use unblocked code */
250
251         sorml2_(side, trans, m, n, k, &a[a_offset], lda, &tau[1], &c__[
252                 c_offset], ldc, &work[1], &iinfo);
253     } else {
254
255 /*        Use blocked code */
256
257         if (left && notran || ! left && ! notran) {
258             i1 = 1;
259             i2 = *k;
260             i3 = nb;
261         } else {
262             i1 = (*k - 1) / nb * nb + 1;
263             i2 = 1;
264             i3 = -nb;
265         }
266
267         if (left) {
268             ni = *n;
269             jc = 1;
270         } else {
271             mi = *m;
272             ic = 1;
273         }
274
275         if (notran) {
276             *(unsigned char *)transt = 'T';
277         } else {
278             *(unsigned char *)transt = 'N';
279         }
280
281         i__1 = i2;
282         i__2 = i3;
283         for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
284 /* Computing MIN */
285             i__4 = nb, i__5 = *k - i__ + 1;
286             ib = min(i__4,i__5);
287
288 /*           Form the triangular factor of the block reflector */
289 /*           H = H(i) H(i+1) . . . H(i+ib-1) */
290
291             i__4 = nq - i__ + 1;
292             slarft_("Forward", "Rowwise", &i__4, &ib, &a[i__ + i__ * a_dim1], 
293                     lda, &tau[i__], t, &c__65);
294             if (left) {
295
296 /*              H or H' is applied to C(i:m,1:n) */
297
298                 mi = *m - i__ + 1;
299                 ic = i__;
300             } else {
301
302 /*              H or H' is applied to C(1:m,i:n) */
303
304                 ni = *n - i__ + 1;
305                 jc = i__;
306             }
307
308 /*           Apply H or H' */
309
310             slarfb_(side, transt, "Forward", "Rowwise", &mi, &ni, &ib, &a[i__ 
311                     + i__ * a_dim1], lda, t, &c__65, &c__[ic + jc * c_dim1], 
312                     ldc, &work[1], &ldwork);
313 /* L10: */
314         }
315     }
316     work[1] = (real) lwkopt;
317     return 0;
318
319 /*     End of SORMLQ */
320
321 } /* sormlq_ */