C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / sgesvdx.c
1 #include <math.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <complex.h>
6 #ifdef complex
7 #undef complex
8 #endif
9 #ifdef I
10 #undef I
11 #endif
12
13 #if defined(_WIN64)
14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
16 #else
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
19 #endif
20
21 #ifdef LAPACK_ILP64
22 typedef BLASLONG blasint;
23 #if defined(_WIN64)
24 #define blasabs(x) llabs(x)
25 #else
26 #define blasabs(x) labs(x)
27 #endif
28 #else
29 typedef int blasint;
30 #define blasabs(x) abs(x)
31 #endif
32
33 typedef blasint integer;
34
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
38 typedef float real;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
42 #ifdef _MSC_VER
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
47 #else
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
52 #endif
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
55 typedef int logical;
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
59
60 #define TRUE_ (1)
61 #define FALSE_ (0)
62
63 /* Extern is for use with -E */
64 #ifndef Extern
65 #define Extern extern
66 #endif
67
68 /* I/O stuff */
69
70 typedef int flag;
71 typedef int ftnlen;
72 typedef int ftnint;
73
74 /*external read, write*/
75 typedef struct
76 {       flag cierr;
77         ftnint ciunit;
78         flag ciend;
79         char *cifmt;
80         ftnint cirec;
81 } cilist;
82
83 /*internal read, write*/
84 typedef struct
85 {       flag icierr;
86         char *iciunit;
87         flag iciend;
88         char *icifmt;
89         ftnint icirlen;
90         ftnint icirnum;
91 } icilist;
92
93 /*open*/
94 typedef struct
95 {       flag oerr;
96         ftnint ounit;
97         char *ofnm;
98         ftnlen ofnmlen;
99         char *osta;
100         char *oacc;
101         char *ofm;
102         ftnint orl;
103         char *oblnk;
104 } olist;
105
106 /*close*/
107 typedef struct
108 {       flag cerr;
109         ftnint cunit;
110         char *csta;
111 } cllist;
112
113 /*rewind, backspace, endfile*/
114 typedef struct
115 {       flag aerr;
116         ftnint aunit;
117 } alist;
118
119 /* inquire */
120 typedef struct
121 {       flag inerr;
122         ftnint inunit;
123         char *infile;
124         ftnlen infilen;
125         ftnint  *inex;  /*parameters in standard's order*/
126         ftnint  *inopen;
127         ftnint  *innum;
128         ftnint  *innamed;
129         char    *inname;
130         ftnlen  innamlen;
131         char    *inacc;
132         ftnlen  inacclen;
133         char    *inseq;
134         ftnlen  inseqlen;
135         char    *indir;
136         ftnlen  indirlen;
137         char    *infmt;
138         ftnlen  infmtlen;
139         char    *inform;
140         ftnint  informlen;
141         char    *inunf;
142         ftnlen  inunflen;
143         ftnint  *inrecl;
144         ftnint  *innrec;
145         char    *inblank;
146         ftnlen  inblanklen;
147 } inlist;
148
149 #define VOID void
150
151 union Multitype {       /* for multiple entry points */
152         integer1 g;
153         shortint h;
154         integer i;
155         /* longint j; */
156         real r;
157         doublereal d;
158         complex c;
159         doublecomplex z;
160         };
161
162 typedef union Multitype Multitype;
163
164 struct Vardesc {        /* for Namelist */
165         char *name;
166         char *addr;
167         ftnlen *dims;
168         int  type;
169         };
170 typedef struct Vardesc Vardesc;
171
172 struct Namelist {
173         char *name;
174         Vardesc **vars;
175         int nvars;
176         };
177 typedef struct Namelist Namelist;
178
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b)   ((a) >> (b) & 1)
186 #define bit_clear(a,b)  ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b)    ((a) |  ((uinteger)1 << (b)))
188
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
192 #ifdef _MSC_VER
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
195 #else
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
198 #endif
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) {         ftnlen i, nc, ll; char *f__rp, *lp;     ll = (llp); lp = (lpp);         for(i=0; i < (int)*(np); ++i) {                 nc = ll;                if((rnp)[i] < nc) nc = (rnp)[i];                ll -= nc;               f__rp = (rpp)[i];               while(--nc >= 0) *lp++ = *(f__rp)++;         }  while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
260
261 /* procedure parameter types for -A and -C++ */
262
263 #define F2C_proc_par_types 1
264 #ifdef __cplusplus
265 typedef logical (*L_fp)(...);
266 #else
267 typedef logical (*L_fp)();
268 #endif
269
270 static float spow_ui(float x, integer n) {
271         float pow=1.0; unsigned long int u;
272         if(n != 0) {
273                 if(n < 0) n = -n, x = 1/x;
274                 for(u = n; ; ) {
275                         if(u & 01) pow *= x;
276                         if(u >>= 1) x *= x;
277                         else break;
278                 }
279         }
280         return pow;
281 }
282 static double dpow_ui(double x, integer n) {
283         double pow=1.0; unsigned long int u;
284         if(n != 0) {
285                 if(n < 0) n = -n, x = 1/x;
286                 for(u = n; ; ) {
287                         if(u & 01) pow *= x;
288                         if(u >>= 1) x *= x;
289                         else break;
290                 }
291         }
292         return pow;
293 }
294 #ifdef _MSC_VER
295 static _Fcomplex cpow_ui(complex x, integer n) {
296         complex pow={1.0,0.0}; unsigned long int u;
297                 if(n != 0) {
298                 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
299                 for(u = n; ; ) {
300                         if(u & 01) pow.r *= x.r, pow.i *= x.i;
301                         if(u >>= 1) x.r *= x.r, x.i *= x.i;
302                         else break;
303                 }
304         }
305         _Fcomplex p={pow.r, pow.i};
306         return p;
307 }
308 #else
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310         _Complex float pow=1.0; unsigned long int u;
311         if(n != 0) {
312                 if(n < 0) n = -n, x = 1/x;
313                 for(u = n; ; ) {
314                         if(u & 01) pow *= x;
315                         if(u >>= 1) x *= x;
316                         else break;
317                 }
318         }
319         return pow;
320 }
321 #endif
322 #ifdef _MSC_VER
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324         _Dcomplex pow={1.0,0.0}; unsigned long int u;
325         if(n != 0) {
326                 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
327                 for(u = n; ; ) {
328                         if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329                         if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
330                         else break;
331                 }
332         }
333         _Dcomplex p = {pow._Val[0], pow._Val[1]};
334         return p;
335 }
336 #else
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338         _Complex double pow=1.0; unsigned long int u;
339         if(n != 0) {
340                 if(n < 0) n = -n, x = 1/x;
341                 for(u = n; ; ) {
342                         if(u & 01) pow *= x;
343                         if(u >>= 1) x *= x;
344                         else break;
345                 }
346         }
347         return pow;
348 }
349 #endif
350 static integer pow_ii(integer x, integer n) {
351         integer pow; unsigned long int u;
352         if (n <= 0) {
353                 if (n == 0 || x == 1) pow = 1;
354                 else if (x != -1) pow = x == 0 ? 1/x : 0;
355                 else n = -n;
356         }
357         if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
358                 u = n;
359                 for(pow = 1; ; ) {
360                         if(u & 01) pow *= x;
361                         if(u >>= 1) x *= x;
362                         else break;
363                 }
364         }
365         return pow;
366 }
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
368 {
369         double m; integer i, mi;
370         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371                 if (w[i-1]>m) mi=i ,m=w[i-1];
372         return mi-s+1;
373 }
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
375 {
376         float m; integer i, mi;
377         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378                 if (w[i-1]>m) mi=i ,m=w[i-1];
379         return mi-s+1;
380 }
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382         integer n = *n_, incx = *incx_, incy = *incy_, i;
383 #ifdef _MSC_VER
384         _Fcomplex zdotc = {0.0, 0.0};
385         if (incx == 1 && incy == 1) {
386                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387                         zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388                         zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
389                 }
390         } else {
391                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392                         zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393                         zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
394                 }
395         }
396         pCf(z) = zdotc;
397 }
398 #else
399         _Complex float zdotc = 0.0;
400         if (incx == 1 && incy == 1) {
401                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402                         zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
403                 }
404         } else {
405                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406                         zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
407                 }
408         }
409         pCf(z) = zdotc;
410 }
411 #endif
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413         integer n = *n_, incx = *incx_, incy = *incy_, i;
414 #ifdef _MSC_VER
415         _Dcomplex zdotc = {0.0, 0.0};
416         if (incx == 1 && incy == 1) {
417                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418                         zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419                         zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
420                 }
421         } else {
422                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423                         zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424                         zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
425                 }
426         }
427         pCd(z) = zdotc;
428 }
429 #else
430         _Complex double zdotc = 0.0;
431         if (incx == 1 && incy == 1) {
432                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433                         zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
434                 }
435         } else {
436                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437                         zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
438                 }
439         }
440         pCd(z) = zdotc;
441 }
442 #endif  
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444         integer n = *n_, incx = *incx_, incy = *incy_, i;
445 #ifdef _MSC_VER
446         _Fcomplex zdotc = {0.0, 0.0};
447         if (incx == 1 && incy == 1) {
448                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449                         zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450                         zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
451                 }
452         } else {
453                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454                         zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455                         zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
456                 }
457         }
458         pCf(z) = zdotc;
459 }
460 #else
461         _Complex float zdotc = 0.0;
462         if (incx == 1 && incy == 1) {
463                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464                         zdotc += Cf(&x[i]) * Cf(&y[i]);
465                 }
466         } else {
467                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468                         zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
469                 }
470         }
471         pCf(z) = zdotc;
472 }
473 #endif
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475         integer n = *n_, incx = *incx_, incy = *incy_, i;
476 #ifdef _MSC_VER
477         _Dcomplex zdotc = {0.0, 0.0};
478         if (incx == 1 && incy == 1) {
479                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480                         zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481                         zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
482                 }
483         } else {
484                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485                         zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486                         zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
487                 }
488         }
489         pCd(z) = zdotc;
490 }
491 #else
492         _Complex double zdotc = 0.0;
493         if (incx == 1 && incy == 1) {
494                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495                         zdotc += Cd(&x[i]) * Cd(&y[i]);
496                 }
497         } else {
498                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499                         zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
500                 }
501         }
502         pCd(z) = zdotc;
503 }
504 #endif
505 /*  -- translated by f2c (version 20000121).
506    You must link the resulting object file with the libraries:
507         -lf2c -lm   (in that order)
508 */
509
510
511
512
513 /* Table of constant values */
514
515 static integer c__6 = 6;
516 static integer c__0 = 0;
517 static integer c__2 = 2;
518 static integer c__1 = 1;
519 static integer c_n1 = -1;
520 static real c_b109 = 0.f;
521
522 /* > \brief <b> SGESVDX computes the singular value decomposition (SVD) for GE matrices</b> */
523
524 /*  =========== DOCUMENTATION =========== */
525
526 /* Online html documentation available at */
527 /*            http://www.netlib.org/lapack/explore-html/ */
528
529 /* > \htmlonly */
530 /* > Download SGESVDX + dependencies */
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgesvdx
532 .f"> */
533 /* > [TGZ]</a> */
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgesvdx
535 .f"> */
536 /* > [ZIP]</a> */
537 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgesvdx
538 .f"> */
539 /* > [TXT]</a> */
540 /* > \endhtmlonly */
541
542 /*  Definition: */
543 /*  =========== */
544
545 /*     SUBROUTINE SGESVDX( JOBU, JOBVT, RANGE, M, N, A, LDA, VL, VU, */
546 /*    $                    IL, IU, NS, S, U, LDU, VT, LDVT, WORK, */
547 /*    $                    LWORK, IWORK, INFO ) */
548
549
550 /*      CHARACTER          JOBU, JOBVT, RANGE */
551 /*      INTEGER            IL, INFO, IU, LDA, LDU, LDVT, LWORK, M, N, NS */
552 /*      REAL               VL, VU */
553 /*     INTEGER            IWORK( * ) */
554 /*     REAL               A( LDA, * ), S( * ), U( LDU, * ), */
555 /*    $                   VT( LDVT, * ), WORK( * ) */
556
557
558 /* > \par Purpose: */
559 /*  ============= */
560 /* > */
561 /* > \verbatim */
562 /* > */
563 /* >  SGESVDX computes the singular value decomposition (SVD) of a real */
564 /* >  M-by-N matrix A, optionally computing the left and/or right singular */
565 /* >  vectors. The SVD is written */
566 /* > */
567 /* >      A = U * SIGMA * transpose(V) */
568 /* > */
569 /* >  where SIGMA is an M-by-N matrix which is zero except for its */
570 /* >  f2cmin(m,n) diagonal elements, U is an M-by-M orthogonal matrix, and */
571 /* >  V is an N-by-N orthogonal matrix.  The diagonal elements of SIGMA */
572 /* >  are the singular values of A; they are real and non-negative, and */
573 /* >  are returned in descending order.  The first f2cmin(m,n) columns of */
574 /* >  U and V are the left and right singular vectors of A. */
575 /* > */
576 /* >  SGESVDX uses an eigenvalue problem for obtaining the SVD, which */
577 /* >  allows for the computation of a subset of singular values and */
578 /* >  vectors. See SBDSVDX for details. */
579 /* > */
580 /* >  Note that the routine returns V**T, not V. */
581 /* > \endverbatim */
582
583 /*  Arguments: */
584 /*  ========== */
585
586 /* > \param[in] JOBU */
587 /* > \verbatim */
588 /* >          JOBU is CHARACTER*1 */
589 /* >          Specifies options for computing all or part of the matrix U: */
590 /* >          = 'V':  the first f2cmin(m,n) columns of U (the left singular */
591 /* >                  vectors) or as specified by RANGE are returned in */
592 /* >                  the array U; */
593 /* >          = 'N':  no columns of U (no left singular vectors) are */
594 /* >                  computed. */
595 /* > \endverbatim */
596 /* > */
597 /* > \param[in] JOBVT */
598 /* > \verbatim */
599 /* >          JOBVT is CHARACTER*1 */
600 /* >           Specifies options for computing all or part of the matrix */
601 /* >           V**T: */
602 /* >           = 'V':  the first f2cmin(m,n) rows of V**T (the right singular */
603 /* >                   vectors) or as specified by RANGE are returned in */
604 /* >                   the array VT; */
605 /* >           = 'N':  no rows of V**T (no right singular vectors) are */
606 /* >                   computed. */
607 /* > \endverbatim */
608 /* > */
609 /* > \param[in] RANGE */
610 /* > \verbatim */
611 /* >          RANGE is CHARACTER*1 */
612 /* >          = 'A': all singular values will be found. */
613 /* >          = 'V': all singular values in the half-open interval (VL,VU] */
614 /* >                 will be found. */
615 /* >          = 'I': the IL-th through IU-th singular values will be found. */
616 /* > \endverbatim */
617 /* > */
618 /* > \param[in] M */
619 /* > \verbatim */
620 /* >          M is INTEGER */
621 /* >          The number of rows of the input matrix A.  M >= 0. */
622 /* > \endverbatim */
623 /* > */
624 /* > \param[in] N */
625 /* > \verbatim */
626 /* >          N is INTEGER */
627 /* >          The number of columns of the input matrix A.  N >= 0. */
628 /* > \endverbatim */
629 /* > */
630 /* > \param[in,out] A */
631 /* > \verbatim */
632 /* >          A is REAL array, dimension (LDA,N) */
633 /* >          On entry, the M-by-N matrix A. */
634 /* >          On exit, the contents of A are destroyed. */
635 /* > \endverbatim */
636 /* > */
637 /* > \param[in] LDA */
638 /* > \verbatim */
639 /* >          LDA is INTEGER */
640 /* >          The leading dimension of the array A.  LDA >= f2cmax(1,M). */
641 /* > \endverbatim */
642 /* > */
643 /* > \param[in] VL */
644 /* > \verbatim */
645 /* >          VL is REAL */
646 /* >          If RANGE='V', the lower bound of the interval to */
647 /* >          be searched for singular values. VU > VL. */
648 /* >          Not referenced if RANGE = 'A' or 'I'. */
649 /* > \endverbatim */
650 /* > */
651 /* > \param[in] VU */
652 /* > \verbatim */
653 /* >          VU is REAL */
654 /* >          If RANGE='V', the upper bound of the interval to */
655 /* >          be searched for singular values. VU > VL. */
656 /* >          Not referenced if RANGE = 'A' or 'I'. */
657 /* > \endverbatim */
658 /* > */
659 /* > \param[in] IL */
660 /* > \verbatim */
661 /* >          IL is INTEGER */
662 /* >          If RANGE='I', the index of the */
663 /* >          smallest singular value to be returned. */
664 /* >          1 <= IL <= IU <= f2cmin(M,N), if f2cmin(M,N) > 0. */
665 /* >          Not referenced if RANGE = 'A' or 'V'. */
666 /* > \endverbatim */
667 /* > */
668 /* > \param[in] IU */
669 /* > \verbatim */
670 /* >          IU is INTEGER */
671 /* >          If RANGE='I', the index of the */
672 /* >          largest singular value to be returned. */
673 /* >          1 <= IL <= IU <= f2cmin(M,N), if f2cmin(M,N) > 0. */
674 /* >          Not referenced if RANGE = 'A' or 'V'. */
675 /* > \endverbatim */
676 /* > */
677 /* > \param[out] NS */
678 /* > \verbatim */
679 /* >          NS is INTEGER */
680 /* >          The total number of singular values found, */
681 /* >          0 <= NS <= f2cmin(M,N). */
682 /* >          If RANGE = 'A', NS = f2cmin(M,N); if RANGE = 'I', NS = IU-IL+1. */
683 /* > \endverbatim */
684 /* > */
685 /* > \param[out] S */
686 /* > \verbatim */
687 /* >          S is REAL array, dimension (f2cmin(M,N)) */
688 /* >          The singular values of A, sorted so that S(i) >= S(i+1). */
689 /* > \endverbatim */
690 /* > */
691 /* > \param[out] U */
692 /* > \verbatim */
693 /* >          U is REAL array, dimension (LDU,UCOL) */
694 /* >          If JOBU = 'V', U contains columns of U (the left singular */
695 /* >          vectors, stored columnwise) as specified by RANGE; if */
696 /* >          JOBU = 'N', U is not referenced. */
697 /* >          Note: The user must ensure that UCOL >= NS; if RANGE = 'V', */
698 /* >          the exact value of NS is not known in advance and an upper */
699 /* >          bound must be used. */
700 /* > \endverbatim */
701 /* > */
702 /* > \param[in] LDU */
703 /* > \verbatim */
704 /* >          LDU is INTEGER */
705 /* >          The leading dimension of the array U.  LDU >= 1; if */
706 /* >          JOBU = 'V', LDU >= M. */
707 /* > \endverbatim */
708 /* > */
709 /* > \param[out] VT */
710 /* > \verbatim */
711 /* >          VT is REAL array, dimension (LDVT,N) */
712 /* >          If JOBVT = 'V', VT contains the rows of V**T (the right singular */
713 /* >          vectors, stored rowwise) as specified by RANGE; if JOBVT = 'N', */
714 /* >          VT is not referenced. */
715 /* >          Note: The user must ensure that LDVT >= NS; if RANGE = 'V', */
716 /* >          the exact value of NS is not known in advance and an upper */
717 /* >          bound must be used. */
718 /* > \endverbatim */
719 /* > */
720 /* > \param[in] LDVT */
721 /* > \verbatim */
722 /* >          LDVT is INTEGER */
723 /* >          The leading dimension of the array VT.  LDVT >= 1; if */
724 /* >          JOBVT = 'V', LDVT >= NS (see above). */
725 /* > \endverbatim */
726 /* > */
727 /* > \param[out] WORK */
728 /* > \verbatim */
729 /* >          WORK is REAL array, dimension (MAX(1,LWORK)) */
730 /* >          On exit, if INFO = 0, WORK(1) returns the optimal LWORK; */
731 /* > \endverbatim */
732 /* > */
733 /* > \param[in] LWORK */
734 /* > \verbatim */
735 /* >          LWORK is INTEGER */
736 /* >          The dimension of the array WORK. */
737 /* >          LWORK >= MAX(1,MIN(M,N)*(MIN(M,N)+4)) for the paths (see */
738 /* >          comments inside the code): */
739 /* >             - PATH 1  (M much larger than N) */
740 /* >             - PATH 1t (N much larger than M) */
741 /* >          LWORK >= MAX(1,MIN(M,N)*2+MAX(M,N)) for the other paths. */
742 /* >          For good performance, LWORK should generally be larger. */
743 /* > */
744 /* >          If LWORK = -1, then a workspace query is assumed; the routine */
745 /* >          only calculates the optimal size of the WORK array, returns */
746 /* >          this value as the first entry of the WORK array, and no error */
747 /* >          message related to LWORK is issued by XERBLA. */
748 /* > \endverbatim */
749 /* > */
750 /* > \param[out] IWORK */
751 /* > \verbatim */
752 /* >          IWORK is INTEGER array, dimension (12*MIN(M,N)) */
753 /* >          If INFO = 0, the first NS elements of IWORK are zero. If INFO > 0, */
754 /* >          then IWORK contains the indices of the eigenvectors that failed */
755 /* >          to converge in SBDSVDX/SSTEVX. */
756 /* > \endverbatim */
757 /* > */
758 /* > \param[out] INFO */
759 /* > \verbatim */
760 /* >     INFO is INTEGER */
761 /* >           = 0:  successful exit */
762 /* >           < 0:  if INFO = -i, the i-th argument had an illegal value */
763 /* >           > 0:  if INFO = i, then i eigenvectors failed to converge */
764 /* >                 in SBDSVDX/SSTEVX. */
765 /* >                 if INFO = N*2 + 1, an internal error occurred in */
766 /* >                 SBDSVDX */
767 /* > \endverbatim */
768
769 /*  Authors: */
770 /*  ======== */
771
772 /* > \author Univ. of Tennessee */
773 /* > \author Univ. of California Berkeley */
774 /* > \author Univ. of Colorado Denver */
775 /* > \author NAG Ltd. */
776
777 /* > \date June 2016 */
778
779 /* > \ingroup realGEsing */
780
781 /*  ===================================================================== */
782 /* Subroutine */ int sgesvdx_(char *jobu, char *jobvt, char *range, integer *
783         m, integer *n, real *a, integer *lda, real *vl, real *vu, integer *il,
784          integer *iu, integer *ns, real *s, real *u, integer *ldu, real *vt, 
785         integer *ldvt, real *work, integer *lwork, integer *iwork, integer *
786         info)
787 {
788     /* System generated locals */
789     address a__1[2];
790     integer a_dim1, a_offset, u_dim1, u_offset, vt_dim1, vt_offset, i__1[2], 
791             i__2, i__3;
792     char ch__1[2];
793
794     /* Local variables */
795     integer iscl;
796     logical alls, inds;
797     integer ilqf;
798     real anrm;
799     integer ierr, iqrf, itau;
800     char jobz[1];
801     logical vals;
802     integer i__, j;
803     extern logical lsame_(char *, char *);
804     integer iltgk, itemp, minmn, itaup, itauq, iutgk, itgkz, mnthr;
805     extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 
806             integer *);
807     logical wantu;
808     integer id, ie;
809     extern /* Subroutine */ int sgebrd_(integer *, integer *, real *, integer 
810             *, real *, real *, real *, real *, real *, integer *, integer *);
811     extern real slamch_(char *), slange_(char *, integer *, integer *,
812              real *, integer *, real *);
813     extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
814     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
815             integer *, integer *, ftnlen, ftnlen);
816     real bignum;
817     extern /* Subroutine */ int sgelqf_(integer *, integer *, real *, integer 
818             *, real *, real *, integer *, integer *), slascl_(char *, integer 
819             *, integer *, real *, real *, integer *, integer *, real *, 
820             integer *, integer *);
821     real abstol;
822     extern /* Subroutine */ int sgeqrf_(integer *, integer *, real *, integer 
823             *, real *, real *, integer *, integer *), slacpy_(char *, integer 
824             *, integer *, real *, integer *, real *, integer *);
825     char rngtgk[1];
826     extern /* Subroutine */ int slaset_(char *, integer *, integer *, real *, 
827             real *, real *, integer *), sormbr_(char *, char *, char *
828             , integer *, integer *, integer *, real *, integer *, real *, 
829             real *, integer *, real *, integer *, integer *);
830     integer minwrk, maxwrk;
831     real smlnum;
832     extern /* Subroutine */ int sormlq_(char *, char *, integer *, integer *, 
833             integer *, real *, integer *, real *, real *, integer *, real *, 
834             integer *, integer *);
835     logical lquery, wantvt;
836     extern /* Subroutine */ int sormqr_(char *, char *, integer *, integer *, 
837             integer *, real *, integer *, real *, real *, integer *, real *, 
838             integer *, integer *);
839     real dum[1], eps;
840     extern /* Subroutine */ int sbdsvdx_(char *, char *, char *, integer *, 
841             real *, real *, real *, real *, integer *, integer *, integer *, 
842             real *, real *, integer *, real *, integer *, integer *);
843
844
845 /*  -- LAPACK driver routine (version 3.8.0) -- */
846 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
847 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
848 /*     June 2016 */
849
850
851 /*  ===================================================================== */
852
853
854 /*     Test the input arguments. */
855
856     /* Parameter adjustments */
857     a_dim1 = *lda;
858     a_offset = 1 + a_dim1 * 1;
859     a -= a_offset;
860     --s;
861     u_dim1 = *ldu;
862     u_offset = 1 + u_dim1 * 1;
863     u -= u_offset;
864     vt_dim1 = *ldvt;
865     vt_offset = 1 + vt_dim1 * 1;
866     vt -= vt_offset;
867     --work;
868     --iwork;
869
870     /* Function Body */
871     *ns = 0;
872     *info = 0;
873     abstol = slamch_("S") * 2;
874     lquery = *lwork == -1;
875     minmn = f2cmin(*m,*n);
876     wantu = lsame_(jobu, "V");
877     wantvt = lsame_(jobvt, "V");
878     if (wantu || wantvt) {
879         *(unsigned char *)jobz = 'V';
880     } else {
881         *(unsigned char *)jobz = 'N';
882     }
883     alls = lsame_(range, "A");
884     vals = lsame_(range, "V");
885     inds = lsame_(range, "I");
886
887     *info = 0;
888     if (! lsame_(jobu, "V") && ! lsame_(jobu, "N")) {
889         *info = -1;
890     } else if (! lsame_(jobvt, "V") && ! lsame_(jobvt, 
891             "N")) {
892         *info = -2;
893     } else if (! (alls || vals || inds)) {
894         *info = -3;
895     } else if (*m < 0) {
896         *info = -4;
897     } else if (*n < 0) {
898         *info = -5;
899     } else if (*m > *lda) {
900         *info = -7;
901     } else if (minmn > 0) {
902         if (vals) {
903             if (*vl < 0.f) {
904                 *info = -8;
905             } else if (*vu <= *vl) {
906                 *info = -9;
907             }
908         } else if (inds) {
909             if (*il < 1 || *il > f2cmax(1,minmn)) {
910                 *info = -10;
911             } else if (*iu < f2cmin(minmn,*il) || *iu > minmn) {
912                 *info = -11;
913             }
914         }
915         if (*info == 0) {
916             if (wantu && *ldu < *m) {
917                 *info = -15;
918             } else if (wantvt) {
919                 if (inds) {
920                     if (*ldvt < *iu - *il + 1) {
921                         *info = -17;
922                     }
923                 } else if (*ldvt < minmn) {
924                     *info = -17;
925                 }
926             }
927         }
928     }
929
930 /*     Compute workspace */
931 /*     (Note: Comments in the code beginning "Workspace:" describe the */
932 /*     minimal amount of workspace needed at that point in the code, */
933 /*     as well as the preferred amount for good performance. */
934 /*     NB refers to the optimal block size for the immediately */
935 /*     following subroutine, as returned by ILAENV.) */
936
937     if (*info == 0) {
938         minwrk = 1;
939         maxwrk = 1;
940         if (minmn > 0) {
941             if (*m >= *n) {
942 /* Writing concatenation */
943                 i__1[0] = 1, a__1[0] = jobu;
944                 i__1[1] = 1, a__1[1] = jobvt;
945                 s_cat(ch__1, a__1, i__1, &c__2, (ftnlen)2);
946                 mnthr = ilaenv_(&c__6, "SGESVD", ch__1, m, n, &c__0, &c__0, (
947                         ftnlen)6, (ftnlen)2);
948                 if (*m >= mnthr) {
949
950 /*                 Path 1 (M much larger than N) */
951
952                     maxwrk = *n + *n * ilaenv_(&c__1, "SGEQRF", " ", m, n, &
953                             c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
954 /* Computing MAX */
955                     i__2 = maxwrk, i__3 = *n * (*n + 5) + (*n << 1) * ilaenv_(
956                             &c__1, "SGEBRD", " ", n, n, &c_n1, &c_n1, (ftnlen)
957                             6, (ftnlen)1);
958                     maxwrk = f2cmax(i__2,i__3);
959                     if (wantu) {
960 /* Computing MAX */
961                         i__2 = maxwrk, i__3 = *n * (*n * 3 + 6) + *n * 
962                                 ilaenv_(&c__1, "SORMQR", " ", n, n, &c_n1, &
963                                 c_n1, (ftnlen)6, (ftnlen)1);
964                         maxwrk = f2cmax(i__2,i__3);
965                     }
966                     if (wantvt) {
967 /* Computing MAX */
968                         i__2 = maxwrk, i__3 = *n * (*n * 3 + 6) + *n * 
969                                 ilaenv_(&c__1, "SORMLQ", " ", n, n, &c_n1, &
970                                 c_n1, (ftnlen)6, (ftnlen)1);
971                         maxwrk = f2cmax(i__2,i__3);
972                     }
973                     minwrk = *n * (*n * 3 + 20);
974                 } else {
975
976 /*                 Path 2 (M at least N, but not much larger) */
977
978                     maxwrk = (*n << 2) + (*m + *n) * ilaenv_(&c__1, "SGEBRD", 
979                             " ", m, n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
980                     if (wantu) {
981 /* Computing MAX */
982                         i__2 = maxwrk, i__3 = *n * ((*n << 1) + 5) + *n * 
983                                 ilaenv_(&c__1, "SORMQR", " ", n, n, &c_n1, &
984                                 c_n1, (ftnlen)6, (ftnlen)1);
985                         maxwrk = f2cmax(i__2,i__3);
986                     }
987                     if (wantvt) {
988 /* Computing MAX */
989                         i__2 = maxwrk, i__3 = *n * ((*n << 1) + 5) + *n * 
990                                 ilaenv_(&c__1, "SORMLQ", " ", n, n, &c_n1, &
991                                 c_n1, (ftnlen)6, (ftnlen)1);
992                         maxwrk = f2cmax(i__2,i__3);
993                     }
994 /* Computing MAX */
995                     i__2 = *n * ((*n << 1) + 19), i__3 = (*n << 2) + *m;
996                     minwrk = f2cmax(i__2,i__3);
997                 }
998             } else {
999 /* Writing concatenation */
1000                 i__1[0] = 1, a__1[0] = jobu;
1001                 i__1[1] = 1, a__1[1] = jobvt;
1002                 s_cat(ch__1, a__1, i__1, &c__2, (ftnlen)2);
1003                 mnthr = ilaenv_(&c__6, "SGESVD", ch__1, m, n, &c__0, &c__0, (
1004                         ftnlen)6, (ftnlen)2);
1005                 if (*n >= mnthr) {
1006
1007 /*                 Path 1t (N much larger than M) */
1008
1009                     maxwrk = *m + *m * ilaenv_(&c__1, "SGELQF", " ", m, n, &
1010                             c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
1011 /* Computing MAX */
1012                     i__2 = maxwrk, i__3 = *m * (*m + 5) + (*m << 1) * ilaenv_(
1013                             &c__1, "SGEBRD", " ", m, m, &c_n1, &c_n1, (ftnlen)
1014                             6, (ftnlen)1);
1015                     maxwrk = f2cmax(i__2,i__3);
1016                     if (wantu) {
1017 /* Computing MAX */
1018                         i__2 = maxwrk, i__3 = *m * (*m * 3 + 6) + *m * 
1019                                 ilaenv_(&c__1, "SORMQR", " ", m, m, &c_n1, &
1020                                 c_n1, (ftnlen)6, (ftnlen)1);
1021                         maxwrk = f2cmax(i__2,i__3);
1022                     }
1023                     if (wantvt) {
1024 /* Computing MAX */
1025                         i__2 = maxwrk, i__3 = *m * (*m * 3 + 6) + *m * 
1026                                 ilaenv_(&c__1, "SORMLQ", " ", m, m, &c_n1, &
1027                                 c_n1, (ftnlen)6, (ftnlen)1);
1028                         maxwrk = f2cmax(i__2,i__3);
1029                     }
1030                     minwrk = *m * (*m * 3 + 20);
1031                 } else {
1032
1033 /*                 Path 2t (N at least M, but not much larger) */
1034
1035                     maxwrk = (*m << 2) + (*m + *n) * ilaenv_(&c__1, "SGEBRD", 
1036                             " ", m, n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
1037                     if (wantu) {
1038 /* Computing MAX */
1039                         i__2 = maxwrk, i__3 = *m * ((*m << 1) + 5) + *m * 
1040                                 ilaenv_(&c__1, "SORMQR", " ", m, m, &c_n1, &
1041                                 c_n1, (ftnlen)6, (ftnlen)1);
1042                         maxwrk = f2cmax(i__2,i__3);
1043                     }
1044                     if (wantvt) {
1045 /* Computing MAX */
1046                         i__2 = maxwrk, i__3 = *m * ((*m << 1) + 5) + *m * 
1047                                 ilaenv_(&c__1, "SORMLQ", " ", m, m, &c_n1, &
1048                                 c_n1, (ftnlen)6, (ftnlen)1);
1049                         maxwrk = f2cmax(i__2,i__3);
1050                     }
1051 /* Computing MAX */
1052                     i__2 = *m * ((*m << 1) + 19), i__3 = (*m << 2) + *n;
1053                     minwrk = f2cmax(i__2,i__3);
1054                 }
1055             }
1056         }
1057         maxwrk = f2cmax(maxwrk,minwrk);
1058         work[1] = (real) maxwrk;
1059
1060         if (*lwork < minwrk && ! lquery) {
1061             *info = -19;
1062         }
1063     }
1064
1065     if (*info != 0) {
1066         i__2 = -(*info);
1067         xerbla_("SGESVDX", &i__2, (ftnlen)7);
1068         return 0;
1069     } else if (lquery) {
1070         return 0;
1071     }
1072
1073 /*     Quick return if possible */
1074
1075     if (*m == 0 || *n == 0) {
1076         return 0;
1077     }
1078
1079 /*     Set singular values indices accord to RANGE. */
1080
1081     if (alls) {
1082         *(unsigned char *)rngtgk = 'I';
1083         iltgk = 1;
1084         iutgk = f2cmin(*m,*n);
1085     } else if (inds) {
1086         *(unsigned char *)rngtgk = 'I';
1087         iltgk = *il;
1088         iutgk = *iu;
1089     } else {
1090         *(unsigned char *)rngtgk = 'V';
1091         iltgk = 0;
1092         iutgk = 0;
1093     }
1094
1095 /*     Get machine constants */
1096
1097     eps = slamch_("P");
1098     smlnum = sqrt(slamch_("S")) / eps;
1099     bignum = 1.f / smlnum;
1100
1101 /*     Scale A if f2cmax element outside range [SMLNUM,BIGNUM] */
1102
1103     anrm = slange_("M", m, n, &a[a_offset], lda, dum);
1104     iscl = 0;
1105     if (anrm > 0.f && anrm < smlnum) {
1106         iscl = 1;
1107         slascl_("G", &c__0, &c__0, &anrm, &smlnum, m, n, &a[a_offset], lda, 
1108                 info);
1109     } else if (anrm > bignum) {
1110         iscl = 1;
1111         slascl_("G", &c__0, &c__0, &anrm, &bignum, m, n, &a[a_offset], lda, 
1112                 info);
1113     }
1114
1115     if (*m >= *n) {
1116
1117 /*        A has at least as many rows as columns. If A has sufficiently */
1118 /*        more rows than columns, first reduce A using the QR */
1119 /*        decomposition. */
1120
1121         if (*m >= mnthr) {
1122
1123 /*           Path 1 (M much larger than N): */
1124 /*           A = Q * R = Q * ( QB * B * PB**T ) */
1125 /*                     = Q * ( QB * ( UB * S * VB**T ) * PB**T ) */
1126 /*           U = Q * QB * UB; V**T = VB**T * PB**T */
1127
1128 /*           Compute A=Q*R */
1129 /*           (Workspace: need 2*N, prefer N+N*NB) */
1130
1131             itau = 1;
1132             itemp = itau + *n;
1133             i__2 = *lwork - itemp + 1;
1134             sgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[itemp], &i__2,
1135                      info);
1136
1137 /*           Copy R into WORK and bidiagonalize it: */
1138 /*           (Workspace: need N*N+5*N, prefer N*N+4*N+2*N*NB) */
1139
1140             iqrf = itemp;
1141             id = iqrf + *n * *n;
1142             ie = id + *n;
1143             itauq = ie + *n;
1144             itaup = itauq + *n;
1145             itemp = itaup + *n;
1146             slacpy_("U", n, n, &a[a_offset], lda, &work[iqrf], n);
1147             i__2 = *n - 1;
1148             i__3 = *n - 1;
1149             slaset_("L", &i__2, &i__3, &c_b109, &c_b109, &work[iqrf + 1], n);
1150             i__2 = *lwork - itemp + 1;
1151             sgebrd_(n, n, &work[iqrf], n, &work[id], &work[ie], &work[itauq], 
1152                     &work[itaup], &work[itemp], &i__2, info);
1153
1154 /*           Solve eigenvalue problem TGK*Z=Z*S. */
1155 /*           (Workspace: need 14*N + 2*N*(N+1)) */
1156
1157             itgkz = itemp;
1158             itemp = itgkz + *n * ((*n << 1) + 1);
1159             i__2 = *n << 1;
1160             sbdsvdx_("U", jobz, rngtgk, n, &work[id], &work[ie], vl, vu, &
1161                     iltgk, &iutgk, ns, &s[1], &work[itgkz], &i__2, &work[
1162                     itemp], &iwork[1], info);
1163
1164 /*           If needed, compute left singular vectors. */
1165
1166             if (wantu) {
1167                 j = itgkz;
1168                 i__2 = *ns;
1169                 for (i__ = 1; i__ <= i__2; ++i__) {
1170                     scopy_(n, &work[j], &c__1, &u[i__ * u_dim1 + 1], &c__1);
1171                     j += *n << 1;
1172                 }
1173                 i__2 = *m - *n;
1174                 slaset_("A", &i__2, ns, &c_b109, &c_b109, &u[*n + 1 + u_dim1],
1175                          ldu);
1176
1177 /*              Call SORMBR to compute QB*UB. */
1178 /*              (Workspace in WORK( ITEMP ): need N, prefer N*NB) */
1179
1180                 i__2 = *lwork - itemp + 1;
1181                 sormbr_("Q", "L", "N", n, ns, n, &work[iqrf], n, &work[itauq],
1182                          &u[u_offset], ldu, &work[itemp], &i__2, info);
1183
1184 /*              Call SORMQR to compute Q*(QB*UB). */
1185 /*              (Workspace in WORK( ITEMP ): need N, prefer N*NB) */
1186
1187                 i__2 = *lwork - itemp + 1;
1188                 sormqr_("L", "N", m, ns, n, &a[a_offset], lda, &work[itau], &
1189                         u[u_offset], ldu, &work[itemp], &i__2, info);
1190             }
1191
1192 /*           If needed, compute right singular vectors. */
1193
1194             if (wantvt) {
1195                 j = itgkz + *n;
1196                 i__2 = *ns;
1197                 for (i__ = 1; i__ <= i__2; ++i__) {
1198                     scopy_(n, &work[j], &c__1, &vt[i__ + vt_dim1], ldvt);
1199                     j += *n << 1;
1200                 }
1201
1202 /*              Call SORMBR to compute VB**T * PB**T */
1203 /*              (Workspace in WORK( ITEMP ): need N, prefer N*NB) */
1204
1205                 i__2 = *lwork - itemp + 1;
1206                 sormbr_("P", "R", "T", ns, n, n, &work[iqrf], n, &work[itaup],
1207                          &vt[vt_offset], ldvt, &work[itemp], &i__2, info);
1208             }
1209         } else {
1210
1211 /*           Path 2 (M at least N, but not much larger) */
1212 /*           Reduce A to bidiagonal form without QR decomposition */
1213 /*           A = QB * B * PB**T = QB * ( UB * S * VB**T ) * PB**T */
1214 /*           U = QB * UB; V**T = VB**T * PB**T */
1215
1216 /*           Bidiagonalize A */
1217 /*           (Workspace: need 4*N+M, prefer 4*N+(M+N)*NB) */
1218
1219             id = 1;
1220             ie = id + *n;
1221             itauq = ie + *n;
1222             itaup = itauq + *n;
1223             itemp = itaup + *n;
1224             i__2 = *lwork - itemp + 1;
1225             sgebrd_(m, n, &a[a_offset], lda, &work[id], &work[ie], &work[
1226                     itauq], &work[itaup], &work[itemp], &i__2, info);
1227
1228 /*           Solve eigenvalue problem TGK*Z=Z*S. */
1229 /*           (Workspace: need 14*N + 2*N*(N+1)) */
1230
1231             itgkz = itemp;
1232             itemp = itgkz + *n * ((*n << 1) + 1);
1233             i__2 = *n << 1;
1234             sbdsvdx_("U", jobz, rngtgk, n, &work[id], &work[ie], vl, vu, &
1235                     iltgk, &iutgk, ns, &s[1], &work[itgkz], &i__2, &work[
1236                     itemp], &iwork[1], info);
1237
1238 /*           If needed, compute left singular vectors. */
1239
1240             if (wantu) {
1241                 j = itgkz;
1242                 i__2 = *ns;
1243                 for (i__ = 1; i__ <= i__2; ++i__) {
1244                     scopy_(n, &work[j], &c__1, &u[i__ * u_dim1 + 1], &c__1);
1245                     j += *n << 1;
1246                 }
1247                 i__2 = *m - *n;
1248                 slaset_("A", &i__2, ns, &c_b109, &c_b109, &u[*n + 1 + u_dim1],
1249                          ldu);
1250
1251 /*              Call SORMBR to compute QB*UB. */
1252 /*              (Workspace in WORK( ITEMP ): need N, prefer N*NB) */
1253
1254                 i__2 = *lwork - itemp + 1;
1255                 sormbr_("Q", "L", "N", m, ns, n, &a[a_offset], lda, &work[
1256                         itauq], &u[u_offset], ldu, &work[itemp], &i__2, &ierr);
1257             }
1258
1259 /*           If needed, compute right singular vectors. */
1260
1261             if (wantvt) {
1262                 j = itgkz + *n;
1263                 i__2 = *ns;
1264                 for (i__ = 1; i__ <= i__2; ++i__) {
1265                     scopy_(n, &work[j], &c__1, &vt[i__ + vt_dim1], ldvt);
1266                     j += *n << 1;
1267                 }
1268
1269 /*              Call SORMBR to compute VB**T * PB**T */
1270 /*              (Workspace in WORK( ITEMP ): need N, prefer N*NB) */
1271
1272                 i__2 = *lwork - itemp + 1;
1273                 sormbr_("P", "R", "T", ns, n, n, &a[a_offset], lda, &work[
1274                         itaup], &vt[vt_offset], ldvt, &work[itemp], &i__2, &
1275                         ierr);
1276             }
1277         }
1278     } else {
1279
1280 /*        A has more columns than rows. If A has sufficiently more */
1281 /*        columns than rows, first reduce A using the LQ decomposition. */
1282
1283         if (*n >= mnthr) {
1284
1285 /*           Path 1t (N much larger than M): */
1286 /*           A = L * Q = ( QB * B * PB**T ) * Q */
1287 /*                     = ( QB * ( UB * S * VB**T ) * PB**T ) * Q */
1288 /*           U = QB * UB ; V**T = VB**T * PB**T * Q */
1289
1290 /*           Compute A=L*Q */
1291 /*           (Workspace: need 2*M, prefer M+M*NB) */
1292
1293             itau = 1;
1294             itemp = itau + *m;
1295             i__2 = *lwork - itemp + 1;
1296             sgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[itemp], &i__2,
1297                      info);
1298 /*           Copy L into WORK and bidiagonalize it: */
1299 /*           (Workspace in WORK( ITEMP ): need M*M+5*N, prefer M*M+4*M+2*M*NB) */
1300
1301             ilqf = itemp;
1302             id = ilqf + *m * *m;
1303             ie = id + *m;
1304             itauq = ie + *m;
1305             itaup = itauq + *m;
1306             itemp = itaup + *m;
1307             slacpy_("L", m, m, &a[a_offset], lda, &work[ilqf], m);
1308             i__2 = *m - 1;
1309             i__3 = *m - 1;
1310             slaset_("U", &i__2, &i__3, &c_b109, &c_b109, &work[ilqf + *m], m);
1311             i__2 = *lwork - itemp + 1;
1312             sgebrd_(m, m, &work[ilqf], m, &work[id], &work[ie], &work[itauq], 
1313                     &work[itaup], &work[itemp], &i__2, info);
1314
1315 /*           Solve eigenvalue problem TGK*Z=Z*S. */
1316 /*           (Workspace: need 2*M*M+14*M) */
1317
1318             itgkz = itemp;
1319             itemp = itgkz + *m * ((*m << 1) + 1);
1320             i__2 = *m << 1;
1321             sbdsvdx_("U", jobz, rngtgk, m, &work[id], &work[ie], vl, vu, &
1322                     iltgk, &iutgk, ns, &s[1], &work[itgkz], &i__2, &work[
1323                     itemp], &iwork[1], info);
1324
1325 /*           If needed, compute left singular vectors. */
1326
1327             if (wantu) {
1328                 j = itgkz;
1329                 i__2 = *ns;
1330                 for (i__ = 1; i__ <= i__2; ++i__) {
1331                     scopy_(m, &work[j], &c__1, &u[i__ * u_dim1 + 1], &c__1);
1332                     j += *m << 1;
1333                 }
1334
1335 /*              Call SORMBR to compute QB*UB. */
1336 /*              (Workspace in WORK( ITEMP ): need M, prefer M*NB) */
1337
1338                 i__2 = *lwork - itemp + 1;
1339                 sormbr_("Q", "L", "N", m, ns, m, &work[ilqf], m, &work[itauq],
1340                          &u[u_offset], ldu, &work[itemp], &i__2, info);
1341             }
1342
1343 /*           If needed, compute right singular vectors. */
1344
1345             if (wantvt) {
1346                 j = itgkz + *m;
1347                 i__2 = *ns;
1348                 for (i__ = 1; i__ <= i__2; ++i__) {
1349                     scopy_(m, &work[j], &c__1, &vt[i__ + vt_dim1], ldvt);
1350                     j += *m << 1;
1351                 }
1352                 i__2 = *n - *m;
1353                 slaset_("A", ns, &i__2, &c_b109, &c_b109, &vt[(*m + 1) * 
1354                         vt_dim1 + 1], ldvt);
1355
1356 /*              Call SORMBR to compute (VB**T)*(PB**T) */
1357 /*              (Workspace in WORK( ITEMP ): need M, prefer M*NB) */
1358
1359                 i__2 = *lwork - itemp + 1;
1360                 sormbr_("P", "R", "T", ns, m, m, &work[ilqf], m, &work[itaup],
1361                          &vt[vt_offset], ldvt, &work[itemp], &i__2, info);
1362
1363 /*              Call SORMLQ to compute ((VB**T)*(PB**T))*Q. */
1364 /*              (Workspace in WORK( ITEMP ): need M, prefer M*NB) */
1365
1366                 i__2 = *lwork - itemp + 1;
1367                 sormlq_("R", "N", ns, n, m, &a[a_offset], lda, &work[itau], &
1368                         vt[vt_offset], ldvt, &work[itemp], &i__2, info);
1369             }
1370         } else {
1371
1372 /*           Path 2t (N greater than M, but not much larger) */
1373 /*           Reduce to bidiagonal form without LQ decomposition */
1374 /*           A = QB * B * PB**T = QB * ( UB * S * VB**T ) * PB**T */
1375 /*           U = QB * UB; V**T = VB**T * PB**T */
1376
1377 /*           Bidiagonalize A */
1378 /*           (Workspace: need 4*M+N, prefer 4*M+(M+N)*NB) */
1379
1380             id = 1;
1381             ie = id + *m;
1382             itauq = ie + *m;
1383             itaup = itauq + *m;
1384             itemp = itaup + *m;
1385             i__2 = *lwork - itemp + 1;
1386             sgebrd_(m, n, &a[a_offset], lda, &work[id], &work[ie], &work[
1387                     itauq], &work[itaup], &work[itemp], &i__2, info);
1388
1389 /*           Solve eigenvalue problem TGK*Z=Z*S. */
1390 /*           (Workspace: need 2*M*M+14*M) */
1391
1392             itgkz = itemp;
1393             itemp = itgkz + *m * ((*m << 1) + 1);
1394             i__2 = *m << 1;
1395             sbdsvdx_("L", jobz, rngtgk, m, &work[id], &work[ie], vl, vu, &
1396                     iltgk, &iutgk, ns, &s[1], &work[itgkz], &i__2, &work[
1397                     itemp], &iwork[1], info);
1398
1399 /*           If needed, compute left singular vectors. */
1400
1401             if (wantu) {
1402                 j = itgkz;
1403                 i__2 = *ns;
1404                 for (i__ = 1; i__ <= i__2; ++i__) {
1405                     scopy_(m, &work[j], &c__1, &u[i__ * u_dim1 + 1], &c__1);
1406                     j += *m << 1;
1407                 }
1408
1409 /*              Call SORMBR to compute QB*UB. */
1410 /*              (Workspace in WORK( ITEMP ): need M, prefer M*NB) */
1411
1412                 i__2 = *lwork - itemp + 1;
1413                 sormbr_("Q", "L", "N", m, ns, n, &a[a_offset], lda, &work[
1414                         itauq], &u[u_offset], ldu, &work[itemp], &i__2, info);
1415             }
1416
1417 /*           If needed, compute right singular vectors. */
1418
1419             if (wantvt) {
1420                 j = itgkz + *m;
1421                 i__2 = *ns;
1422                 for (i__ = 1; i__ <= i__2; ++i__) {
1423                     scopy_(m, &work[j], &c__1, &vt[i__ + vt_dim1], ldvt);
1424                     j += *m << 1;
1425                 }
1426                 i__2 = *n - *m;
1427                 slaset_("A", ns, &i__2, &c_b109, &c_b109, &vt[(*m + 1) * 
1428                         vt_dim1 + 1], ldvt);
1429
1430 /*              Call SORMBR to compute VB**T * PB**T */
1431 /*              (Workspace in WORK( ITEMP ): need M, prefer M*NB) */
1432
1433                 i__2 = *lwork - itemp + 1;
1434                 sormbr_("P", "R", "T", ns, n, m, &a[a_offset], lda, &work[
1435                         itaup], &vt[vt_offset], ldvt, &work[itemp], &i__2, 
1436                         info);
1437             }
1438         }
1439     }
1440
1441 /*     Undo scaling if necessary */
1442
1443     if (iscl == 1) {
1444         if (anrm > bignum) {
1445             slascl_("G", &c__0, &c__0, &bignum, &anrm, &minmn, &c__1, &s[1], &
1446                     minmn, info);
1447         }
1448         if (anrm < smlnum) {
1449             slascl_("G", &c__0, &c__0, &smlnum, &anrm, &minmn, &c__1, &s[1], &
1450                     minmn, info);
1451         }
1452     }
1453
1454 /*     Return optimal workspace in WORK(1) */
1455
1456     work[1] = (real) maxwrk;
1457
1458     return 0;
1459
1460 /*     End of SGESVDX */
1461
1462 } /* sgesvdx_ */
1463