/root/doris/contrib/openblas/lapack-netlib/SRC/dbdsqr.c
Line | Count | Source |
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 | 0 | static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;} |
49 | 0 | static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;} |
50 | 0 | static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;} |
51 | 0 | 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 blasint logical; |
56 | | |
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 | 0 | #define abs(x) ((x) >= 0 ? (x) : -(x)) |
180 | | #define dabs(x) (fabs(x)) |
181 | 0 | #define f2cmin(a,b) ((a) <= (b) ? (a) : (b)) |
182 | 0 | #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 | 0 | #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a))) |
226 | 0 | #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 | 0 | #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 | | |
264 | | #ifdef __cplusplus |
265 | | typedef logical (*L_fp)(...); |
266 | | #else |
267 | | typedef logical (*L_fp)(); |
268 | | #endif |
269 | | |
270 | 0 | static float spow_ui(float x, integer n) { |
271 | 0 | float pow=1.0; unsigned long int u; |
272 | 0 | if(n != 0) { |
273 | 0 | if(n < 0) n = -n, x = 1/x; |
274 | 0 | for(u = n; ; ) { |
275 | 0 | if(u & 01) pow *= x; |
276 | 0 | if(u >>= 1) x *= x; |
277 | 0 | else break; |
278 | 0 | } |
279 | 0 | } |
280 | 0 | return pow; |
281 | 0 | } |
282 | 0 | static double dpow_ui(double x, integer n) { |
283 | 0 | double pow=1.0; unsigned long int u; |
284 | 0 | if(n != 0) { |
285 | 0 | if(n < 0) n = -n, x = 1/x; |
286 | 0 | for(u = n; ; ) { |
287 | 0 | if(u & 01) pow *= x; |
288 | 0 | if(u >>= 1) x *= x; |
289 | 0 | else break; |
290 | 0 | } |
291 | 0 | } |
292 | 0 | return pow; |
293 | 0 | } |
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 | 0 | static _Complex float cpow_ui(_Complex float x, integer n) { |
310 | 0 | _Complex float pow=1.0; unsigned long int u; |
311 | 0 | if(n != 0) { |
312 | 0 | if(n < 0) n = -n, x = 1/x; |
313 | 0 | for(u = n; ; ) { |
314 | 0 | if(u & 01) pow *= x; |
315 | 0 | if(u >>= 1) x *= x; |
316 | 0 | else break; |
317 | 0 | } |
318 | 0 | } |
319 | 0 | return pow; |
320 | 0 | } |
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 | 0 | static _Complex double zpow_ui(_Complex double x, integer n) { |
338 | 0 | _Complex double pow=1.0; unsigned long int u; |
339 | 0 | if(n != 0) { |
340 | 0 | if(n < 0) n = -n, x = 1/x; |
341 | 0 | for(u = n; ; ) { |
342 | 0 | if(u & 01) pow *= x; |
343 | 0 | if(u >>= 1) x *= x; |
344 | 0 | else break; |
345 | 0 | } |
346 | 0 | } |
347 | 0 | return pow; |
348 | 0 | } |
349 | | #endif |
350 | 0 | static integer pow_ii(integer x, integer n) { |
351 | 0 | integer pow; unsigned long int u; |
352 | 0 | if (n <= 0) { |
353 | 0 | if (n == 0 || x == 1) pow = 1; |
354 | 0 | else if (x != -1) pow = x == 0 ? 1/x : 0; |
355 | 0 | else n = -n; |
356 | 0 | } |
357 | 0 | if ((n > 0) || !(n == 0 || x == 1 || x != -1)) { |
358 | 0 | u = n; |
359 | 0 | for(pow = 1; ; ) { |
360 | 0 | if(u & 01) pow *= x; |
361 | 0 | if(u >>= 1) x *= x; |
362 | 0 | else break; |
363 | 0 | } |
364 | 0 | } |
365 | 0 | return pow; |
366 | 0 | } |
367 | | static integer dmaxloc_(double *w, integer s, integer e, integer *n) |
368 | 0 | { |
369 | 0 | double m; integer i, mi; |
370 | 0 | for(m=w[s-1], mi=s, i=s+1; i<=e; i++) |
371 | 0 | if (w[i-1]>m) mi=i ,m=w[i-1]; |
372 | 0 | return mi-s+1; |
373 | 0 | } |
374 | | static integer smaxloc_(float *w, integer s, integer e, integer *n) |
375 | 0 | { |
376 | 0 | float m; integer i, mi; |
377 | 0 | for(m=w[s-1], mi=s, i=s+1; i<=e; i++) |
378 | 0 | if (w[i-1]>m) mi=i ,m=w[i-1]; |
379 | 0 | return mi-s+1; |
380 | 0 | } |
381 | 0 | static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { |
382 | 0 | integer n = *n_, incx = *incx_, incy = *incy_, i; |
383 | 0 | #ifdef _MSC_VER |
384 | 0 | _Fcomplex zdotc = {0.0, 0.0}; |
385 | 0 | if (incx == 1 && incy == 1) { |
386 | 0 | for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ |
387 | 0 | zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0]; |
388 | 0 | zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1]; |
389 | 0 | } |
390 | 0 | } else { |
391 | 0 | for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ |
392 | 0 | zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0]; |
393 | 0 | zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1]; |
394 | 0 | } |
395 | 0 | } |
396 | 0 | pCf(z) = zdotc; |
397 | 0 | } |
398 | 0 | #else |
399 | 0 | _Complex float zdotc = 0.0; |
400 | 0 | if (incx == 1 && incy == 1) { |
401 | 0 | for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ |
402 | 0 | zdotc += conjf(Cf(&x[i])) * Cf(&y[i]); |
403 | 0 | } |
404 | 0 | } else { |
405 | 0 | for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ |
406 | 0 | zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]); |
407 | 0 | } |
408 | 0 | } |
409 | 0 | pCf(z) = zdotc; |
410 | 0 | } |
411 | | #endif |
412 | 0 | static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { |
413 | 0 | integer n = *n_, incx = *incx_, incy = *incy_, i; |
414 | 0 | #ifdef _MSC_VER |
415 | 0 | _Dcomplex zdotc = {0.0, 0.0}; |
416 | 0 | if (incx == 1 && incy == 1) { |
417 | 0 | for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ |
418 | 0 | zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0]; |
419 | 0 | zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1]; |
420 | 0 | } |
421 | 0 | } else { |
422 | 0 | for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ |
423 | 0 | zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0]; |
424 | 0 | zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1]; |
425 | 0 | } |
426 | 0 | } |
427 | 0 | pCd(z) = zdotc; |
428 | 0 | } |
429 | 0 | #else |
430 | 0 | _Complex double zdotc = 0.0; |
431 | 0 | if (incx == 1 && incy == 1) { |
432 | 0 | for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ |
433 | 0 | zdotc += conj(Cd(&x[i])) * Cd(&y[i]); |
434 | 0 | } |
435 | 0 | } else { |
436 | 0 | for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ |
437 | 0 | zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]); |
438 | 0 | } |
439 | 0 | } |
440 | 0 | pCd(z) = zdotc; |
441 | 0 | } |
442 | | #endif |
443 | 0 | static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { |
444 | 0 | integer n = *n_, incx = *incx_, incy = *incy_, i; |
445 | 0 | #ifdef _MSC_VER |
446 | 0 | _Fcomplex zdotc = {0.0, 0.0}; |
447 | 0 | if (incx == 1 && incy == 1) { |
448 | 0 | for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ |
449 | 0 | zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0]; |
450 | 0 | zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1]; |
451 | 0 | } |
452 | 0 | } else { |
453 | 0 | for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ |
454 | 0 | zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0]; |
455 | 0 | zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1]; |
456 | 0 | } |
457 | 0 | } |
458 | 0 | pCf(z) = zdotc; |
459 | 0 | } |
460 | 0 | #else |
461 | 0 | _Complex float zdotc = 0.0; |
462 | 0 | if (incx == 1 && incy == 1) { |
463 | 0 | for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ |
464 | 0 | zdotc += Cf(&x[i]) * Cf(&y[i]); |
465 | 0 | } |
466 | 0 | } else { |
467 | 0 | for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ |
468 | 0 | zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]); |
469 | 0 | } |
470 | 0 | } |
471 | 0 | pCf(z) = zdotc; |
472 | 0 | } |
473 | | #endif |
474 | 0 | static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { |
475 | 0 | integer n = *n_, incx = *incx_, incy = *incy_, i; |
476 | 0 | #ifdef _MSC_VER |
477 | 0 | _Dcomplex zdotc = {0.0, 0.0}; |
478 | 0 | if (incx == 1 && incy == 1) { |
479 | 0 | for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ |
480 | 0 | zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0]; |
481 | 0 | zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1]; |
482 | 0 | } |
483 | 0 | } else { |
484 | 0 | for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ |
485 | 0 | zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0]; |
486 | 0 | zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1]; |
487 | 0 | } |
488 | 0 | } |
489 | 0 | pCd(z) = zdotc; |
490 | 0 | } |
491 | 0 | #else |
492 | 0 | _Complex double zdotc = 0.0; |
493 | 0 | if (incx == 1 && incy == 1) { |
494 | 0 | for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ |
495 | 0 | zdotc += Cd(&x[i]) * Cd(&y[i]); |
496 | 0 | } |
497 | 0 | } else { |
498 | 0 | for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ |
499 | 0 | zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]); |
500 | 0 | } |
501 | 0 | } |
502 | 0 | pCd(z) = zdotc; |
503 | 0 | } |
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 doublereal c_b15 = -.125; |
516 | | static integer c__1 = 1; |
517 | | static doublereal c_b49 = 1.; |
518 | | static doublereal c_b72 = -1.; |
519 | | |
520 | | /* > \brief \b DBDSQR */ |
521 | | |
522 | | /* =========== DOCUMENTATION =========== */ |
523 | | |
524 | | /* Online html documentation available at */ |
525 | | /* http://www.netlib.org/lapack/explore-html/ */ |
526 | | |
527 | | /* > \htmlonly */ |
528 | | /* > Download DBDSQR + dependencies */ |
529 | | /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dbdsqr. |
530 | | f"> */ |
531 | | /* > [TGZ]</a> */ |
532 | | /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dbdsqr. |
533 | | f"> */ |
534 | | /* > [ZIP]</a> */ |
535 | | /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dbdsqr. |
536 | | f"> */ |
537 | | /* > [TXT]</a> */ |
538 | | /* > \endhtmlonly */ |
539 | | |
540 | | /* Definition: */ |
541 | | /* =========== */ |
542 | | |
543 | | /* SUBROUTINE DBDSQR( UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U, */ |
544 | | /* LDU, C, LDC, WORK, INFO ) */ |
545 | | |
546 | | /* CHARACTER UPLO */ |
547 | | /* INTEGER INFO, LDC, LDU, LDVT, N, NCC, NCVT, NRU */ |
548 | | /* DOUBLE PRECISION C( LDC, * ), D( * ), E( * ), U( LDU, * ), */ |
549 | | /* $ VT( LDVT, * ), WORK( * ) */ |
550 | | |
551 | | |
552 | | /* > \par Purpose: */ |
553 | | /* ============= */ |
554 | | /* > */ |
555 | | /* > \verbatim */ |
556 | | /* > */ |
557 | | /* > DBDSQR computes the singular values and, optionally, the right and/or */ |
558 | | /* > left singular vectors from the singular value decomposition (SVD) of */ |
559 | | /* > a real N-by-N (upper or lower) bidiagonal matrix B using the implicit */ |
560 | | /* > zero-shift QR algorithm. The SVD of B has the form */ |
561 | | /* > */ |
562 | | /* > B = Q * S * P**T */ |
563 | | /* > */ |
564 | | /* > where S is the diagonal matrix of singular values, Q is an orthogonal */ |
565 | | /* > matrix of left singular vectors, and P is an orthogonal matrix of */ |
566 | | /* > right singular vectors. If left singular vectors are requested, this */ |
567 | | /* > subroutine actually returns U*Q instead of Q, and, if right singular */ |
568 | | /* > vectors are requested, this subroutine returns P**T*VT instead of */ |
569 | | /* > P**T, for given real input matrices U and VT. When U and VT are the */ |
570 | | /* > orthogonal matrices that reduce a general matrix A to bidiagonal */ |
571 | | /* > form: A = U*B*VT, as computed by DGEBRD, then */ |
572 | | /* > */ |
573 | | /* > A = (U*Q) * S * (P**T*VT) */ |
574 | | /* > */ |
575 | | /* > is the SVD of A. Optionally, the subroutine may also compute Q**T*C */ |
576 | | /* > for a given real input matrix C. */ |
577 | | /* > */ |
578 | | /* > See "Computing Small Singular Values of Bidiagonal Matrices With */ |
579 | | /* > Guaranteed High Relative Accuracy," by J. Demmel and W. Kahan, */ |
580 | | /* > LAPACK Working Note #3 (or SIAM J. Sci. Statist. Comput. vol. 11, */ |
581 | | /* > no. 5, pp. 873-912, Sept 1990) and */ |
582 | | /* > "Accurate singular values and differential qd algorithms," by */ |
583 | | /* > B. Parlett and V. Fernando, Technical Report CPAM-554, Mathematics */ |
584 | | /* > Department, University of California at Berkeley, July 1992 */ |
585 | | /* > for a detailed description of the algorithm. */ |
586 | | /* > \endverbatim */ |
587 | | |
588 | | /* Arguments: */ |
589 | | /* ========== */ |
590 | | |
591 | | /* > \param[in] UPLO */ |
592 | | /* > \verbatim */ |
593 | | /* > UPLO is CHARACTER*1 */ |
594 | | /* > = 'U': B is upper bidiagonal; */ |
595 | | /* > = 'L': B is lower bidiagonal. */ |
596 | | /* > \endverbatim */ |
597 | | /* > */ |
598 | | /* > \param[in] N */ |
599 | | /* > \verbatim */ |
600 | | /* > N is INTEGER */ |
601 | | /* > The order of the matrix B. N >= 0. */ |
602 | | /* > \endverbatim */ |
603 | | /* > */ |
604 | | /* > \param[in] NCVT */ |
605 | | /* > \verbatim */ |
606 | | /* > NCVT is INTEGER */ |
607 | | /* > The number of columns of the matrix VT. NCVT >= 0. */ |
608 | | /* > \endverbatim */ |
609 | | /* > */ |
610 | | /* > \param[in] NRU */ |
611 | | /* > \verbatim */ |
612 | | /* > NRU is INTEGER */ |
613 | | /* > The number of rows of the matrix U. NRU >= 0. */ |
614 | | /* > \endverbatim */ |
615 | | /* > */ |
616 | | /* > \param[in] NCC */ |
617 | | /* > \verbatim */ |
618 | | /* > NCC is INTEGER */ |
619 | | /* > The number of columns of the matrix C. NCC >= 0. */ |
620 | | /* > \endverbatim */ |
621 | | /* > */ |
622 | | /* > \param[in,out] D */ |
623 | | /* > \verbatim */ |
624 | | /* > D is DOUBLE PRECISION array, dimension (N) */ |
625 | | /* > On entry, the n diagonal elements of the bidiagonal matrix B. */ |
626 | | /* > On exit, if INFO=0, the singular values of B in decreasing */ |
627 | | /* > order. */ |
628 | | /* > \endverbatim */ |
629 | | /* > */ |
630 | | /* > \param[in,out] E */ |
631 | | /* > \verbatim */ |
632 | | /* > E is DOUBLE PRECISION array, dimension (N-1) */ |
633 | | /* > On entry, the N-1 offdiagonal elements of the bidiagonal */ |
634 | | /* > matrix B. */ |
635 | | /* > On exit, if INFO = 0, E is destroyed; if INFO > 0, D and E */ |
636 | | /* > will contain the diagonal and superdiagonal elements of a */ |
637 | | /* > bidiagonal matrix orthogonally equivalent to the one given */ |
638 | | /* > as input. */ |
639 | | /* > \endverbatim */ |
640 | | /* > */ |
641 | | /* > \param[in,out] VT */ |
642 | | /* > \verbatim */ |
643 | | /* > VT is DOUBLE PRECISION array, dimension (LDVT, NCVT) */ |
644 | | /* > On entry, an N-by-NCVT matrix VT. */ |
645 | | /* > On exit, VT is overwritten by P**T * VT. */ |
646 | | /* > Not referenced if NCVT = 0. */ |
647 | | /* > \endverbatim */ |
648 | | /* > */ |
649 | | /* > \param[in] LDVT */ |
650 | | /* > \verbatim */ |
651 | | /* > LDVT is INTEGER */ |
652 | | /* > The leading dimension of the array VT. */ |
653 | | /* > LDVT >= f2cmax(1,N) if NCVT > 0; LDVT >= 1 if NCVT = 0. */ |
654 | | /* > \endverbatim */ |
655 | | /* > */ |
656 | | /* > \param[in,out] U */ |
657 | | /* > \verbatim */ |
658 | | /* > U is DOUBLE PRECISION array, dimension (LDU, N) */ |
659 | | /* > On entry, an NRU-by-N matrix U. */ |
660 | | /* > On exit, U is overwritten by U * Q. */ |
661 | | /* > Not referenced if NRU = 0. */ |
662 | | /* > \endverbatim */ |
663 | | /* > */ |
664 | | /* > \param[in] LDU */ |
665 | | /* > \verbatim */ |
666 | | /* > LDU is INTEGER */ |
667 | | /* > The leading dimension of the array U. LDU >= f2cmax(1,NRU). */ |
668 | | /* > \endverbatim */ |
669 | | /* > */ |
670 | | /* > \param[in,out] C */ |
671 | | /* > \verbatim */ |
672 | | /* > C is DOUBLE PRECISION array, dimension (LDC, NCC) */ |
673 | | /* > On entry, an N-by-NCC matrix C. */ |
674 | | /* > On exit, C is overwritten by Q**T * C. */ |
675 | | /* > Not referenced if NCC = 0. */ |
676 | | /* > \endverbatim */ |
677 | | /* > */ |
678 | | /* > \param[in] LDC */ |
679 | | /* > \verbatim */ |
680 | | /* > LDC is INTEGER */ |
681 | | /* > The leading dimension of the array C. */ |
682 | | /* > LDC >= f2cmax(1,N) if NCC > 0; LDC >=1 if NCC = 0. */ |
683 | | /* > \endverbatim */ |
684 | | /* > */ |
685 | | /* > \param[out] WORK */ |
686 | | /* > \verbatim */ |
687 | | /* > WORK is DOUBLE PRECISION array, dimension (4*(N-1)) */ |
688 | | /* > \endverbatim */ |
689 | | /* > */ |
690 | | /* > \param[out] INFO */ |
691 | | /* > \verbatim */ |
692 | | /* > INFO is INTEGER */ |
693 | | /* > = 0: successful exit */ |
694 | | /* > < 0: If INFO = -i, the i-th argument had an illegal value */ |
695 | | /* > > 0: */ |
696 | | /* > if NCVT = NRU = NCC = 0, */ |
697 | | /* > = 1, a split was marked by a positive value in E */ |
698 | | /* > = 2, current block of Z not diagonalized after 30*N */ |
699 | | /* > iterations (in inner while loop) */ |
700 | | /* > = 3, termination criterion of outer while loop not met */ |
701 | | /* > (program created more than N unreduced blocks) */ |
702 | | /* > else NCVT = NRU = NCC = 0, */ |
703 | | /* > the algorithm did not converge; D and E contain the */ |
704 | | /* > elements of a bidiagonal matrix which is orthogonally */ |
705 | | /* > similar to the input matrix B; if INFO = i, i */ |
706 | | /* > elements of E have not converged to zero. */ |
707 | | /* > \endverbatim */ |
708 | | |
709 | | /* > \par Internal Parameters: */ |
710 | | /* ========================= */ |
711 | | /* > */ |
712 | | /* > \verbatim */ |
713 | | /* > TOLMUL DOUBLE PRECISION, default = f2cmax(10,f2cmin(100,EPS**(-1/8))) */ |
714 | | /* > TOLMUL controls the convergence criterion of the QR loop. */ |
715 | | /* > If it is positive, TOLMUL*EPS is the desired relative */ |
716 | | /* > precision in the computed singular values. */ |
717 | | /* > If it is negative, abs(TOLMUL*EPS*sigma_max) is the */ |
718 | | /* > desired absolute accuracy in the computed singular */ |
719 | | /* > values (corresponds to relative accuracy */ |
720 | | /* > abs(TOLMUL*EPS) in the largest singular value. */ |
721 | | /* > abs(TOLMUL) should be between 1 and 1/EPS, and preferably */ |
722 | | /* > between 10 (for fast convergence) and .1/EPS */ |
723 | | /* > (for there to be some accuracy in the results). */ |
724 | | /* > Default is to lose at either one eighth or 2 of the */ |
725 | | /* > available decimal digits in each computed singular value */ |
726 | | /* > (whichever is smaller). */ |
727 | | /* > */ |
728 | | /* > MAXITR INTEGER, default = 6 */ |
729 | | /* > MAXITR controls the maximum number of passes of the */ |
730 | | /* > algorithm through its inner loop. The algorithms stops */ |
731 | | /* > (and so fails to converge) if the number of passes */ |
732 | | /* > through the inner loop exceeds MAXITR*N**2. */ |
733 | | /* > */ |
734 | | /* > \endverbatim */ |
735 | | |
736 | | /* > \par Note: */ |
737 | | /* =========== */ |
738 | | /* > */ |
739 | | /* > \verbatim */ |
740 | | /* > Bug report from Cezary Dendek. */ |
741 | | /* > On March 23rd 2017, the INTEGER variable MAXIT = MAXITR*N**2 is */ |
742 | | /* > removed since it can overflow pretty easily (for N larger or equal */ |
743 | | /* > than 18,919). We instead use MAXITDIVN = MAXITR*N. */ |
744 | | /* > \endverbatim */ |
745 | | |
746 | | /* Authors: */ |
747 | | /* ======== */ |
748 | | |
749 | | /* > \author Univ. of Tennessee */ |
750 | | /* > \author Univ. of California Berkeley */ |
751 | | /* > \author Univ. of Colorado Denver */ |
752 | | /* > \author NAG Ltd. */ |
753 | | |
754 | | /* > \date June 2017 */ |
755 | | |
756 | | /* > \ingroup auxOTHERcomputational */ |
757 | | |
758 | | /* ===================================================================== */ |
759 | | /* Subroutine */ void dbdsqr_(char *uplo, integer *n, integer *ncvt, integer * |
760 | | nru, integer *ncc, doublereal *d__, doublereal *e, doublereal *vt, |
761 | | integer *ldvt, doublereal *u, integer *ldu, doublereal *c__, integer * |
762 | | ldc, doublereal *work, integer *info) |
763 | 0 | { |
764 | | /* System generated locals */ |
765 | 0 | integer c_dim1, c_offset, u_dim1, u_offset, vt_dim1, vt_offset, i__1, |
766 | 0 | i__2; |
767 | 0 | doublereal d__1, d__2, d__3, d__4; |
768 | | |
769 | | /* Local variables */ |
770 | 0 | doublereal abse; |
771 | 0 | integer idir; |
772 | 0 | doublereal abss; |
773 | 0 | integer oldm; |
774 | 0 | doublereal cosl; |
775 | 0 | integer isub, iter; |
776 | 0 | doublereal unfl, sinl, cosr, smin, smax, sinr; |
777 | 0 | extern /* Subroutine */ void drot_(integer *, doublereal *, integer *, |
778 | 0 | doublereal *, integer *, doublereal *, doublereal *); |
779 | 0 | integer iterdivn; |
780 | 0 | extern /* Subroutine */ void dlas2_(doublereal *, doublereal *, doublereal |
781 | 0 | *, doublereal *, doublereal *); |
782 | 0 | doublereal f, g, h__; |
783 | 0 | integer i__, j, m; |
784 | 0 | doublereal r__; |
785 | 0 | extern /* Subroutine */ void dscal_(integer *, doublereal *, doublereal *, |
786 | 0 | integer *); |
787 | 0 | extern logical lsame_(char *, char *); |
788 | 0 | doublereal oldcs; |
789 | 0 | extern /* Subroutine */ void dlasr_(char *, char *, char *, integer *, |
790 | 0 | integer *, doublereal *, doublereal *, doublereal *, integer *); |
791 | 0 | integer oldll; |
792 | 0 | doublereal shift, sigmn, oldsn; |
793 | 0 | extern /* Subroutine */ void dswap_(integer *, doublereal *, integer *, |
794 | 0 | doublereal *, integer *); |
795 | 0 | doublereal sminl, sigmx; |
796 | 0 | logical lower; |
797 | 0 | integer maxitdivn; |
798 | 0 | extern /* Subroutine */ void dlasq1_(integer *, doublereal *, doublereal *, |
799 | 0 | doublereal *, integer *), dlasv2_(doublereal *, doublereal *, |
800 | 0 | doublereal *, doublereal *, doublereal *, doublereal *, |
801 | 0 | doublereal *, doublereal *, doublereal *); |
802 | 0 | doublereal cs; |
803 | 0 | integer ll; |
804 | 0 | extern doublereal dlamch_(char *); |
805 | 0 | doublereal sn, mu; |
806 | 0 | extern /* Subroutine */ void dlartg_(doublereal *, doublereal *, |
807 | 0 | doublereal *, doublereal *, doublereal *); |
808 | 0 | extern int xerbla_(char *, integer *, ftnlen); |
809 | 0 | doublereal sminoa, thresh; |
810 | 0 | logical rotate; |
811 | 0 | integer nm1; |
812 | 0 | doublereal tolmul; |
813 | 0 | integer nm12, nm13, lll; |
814 | 0 | doublereal eps, sll, tol; |
815 | | |
816 | | |
817 | | /* -- LAPACK computational routine (version 3.7.1) -- */ |
818 | | /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ |
819 | | /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ |
820 | | /* June 2017 */ |
821 | | |
822 | | |
823 | | /* ===================================================================== */ |
824 | | |
825 | | |
826 | | /* Test the input parameters. */ |
827 | | |
828 | | /* Parameter adjustments */ |
829 | 0 | --d__; |
830 | 0 | --e; |
831 | 0 | vt_dim1 = *ldvt; |
832 | 0 | vt_offset = 1 + vt_dim1 * 1; |
833 | 0 | vt -= vt_offset; |
834 | 0 | u_dim1 = *ldu; |
835 | 0 | u_offset = 1 + u_dim1 * 1; |
836 | 0 | u -= u_offset; |
837 | 0 | c_dim1 = *ldc; |
838 | 0 | c_offset = 1 + c_dim1 * 1; |
839 | 0 | c__ -= c_offset; |
840 | 0 | --work; |
841 | | |
842 | | /* Function Body */ |
843 | 0 | *info = 0; |
844 | 0 | lower = lsame_(uplo, "L"); |
845 | 0 | if (! lsame_(uplo, "U") && ! lower) { |
846 | 0 | *info = -1; |
847 | 0 | } else if (*n < 0) { |
848 | 0 | *info = -2; |
849 | 0 | } else if (*ncvt < 0) { |
850 | 0 | *info = -3; |
851 | 0 | } else if (*nru < 0) { |
852 | 0 | *info = -4; |
853 | 0 | } else if (*ncc < 0) { |
854 | 0 | *info = -5; |
855 | 0 | } else if (*ncvt == 0 && *ldvt < 1 || *ncvt > 0 && *ldvt < f2cmax(1,*n)) { |
856 | 0 | *info = -9; |
857 | 0 | } else if (*ldu < f2cmax(1,*nru)) { |
858 | 0 | *info = -11; |
859 | 0 | } else if (*ncc == 0 && *ldc < 1 || *ncc > 0 && *ldc < f2cmax(1,*n)) { |
860 | 0 | *info = -13; |
861 | 0 | } |
862 | 0 | if (*info != 0) { |
863 | 0 | i__1 = -(*info); |
864 | 0 | xerbla_("DBDSQR", &i__1, (ftnlen)6); |
865 | 0 | return; |
866 | 0 | } |
867 | 0 | if (*n == 0) { |
868 | 0 | return; |
869 | 0 | } |
870 | 0 | if (*n == 1) { |
871 | 0 | goto L160; |
872 | 0 | } |
873 | | |
874 | | /* ROTATE is true if any singular vectors desired, false otherwise */ |
875 | | |
876 | 0 | rotate = *ncvt > 0 || *nru > 0 || *ncc > 0; |
877 | | |
878 | | /* If no singular vectors desired, use qd algorithm */ |
879 | |
|
880 | 0 | if (! rotate) { |
881 | 0 | dlasq1_(n, &d__[1], &e[1], &work[1], info); |
882 | | |
883 | | /* If INFO equals 2, dqds didn't finish, try to finish */ |
884 | |
|
885 | 0 | if (*info != 2) { |
886 | 0 | return; |
887 | 0 | } |
888 | 0 | *info = 0; |
889 | 0 | } |
890 | | |
891 | 0 | nm1 = *n - 1; |
892 | 0 | nm12 = nm1 + nm1; |
893 | 0 | nm13 = nm12 + nm1; |
894 | 0 | idir = 0; |
895 | | |
896 | | /* Get machine constants */ |
897 | |
|
898 | 0 | eps = dlamch_("Epsilon"); |
899 | 0 | unfl = dlamch_("Safe minimum"); |
900 | | |
901 | | /* If matrix lower bidiagonal, rotate to be upper bidiagonal */ |
902 | | /* by applying Givens rotations on the left */ |
903 | |
|
904 | 0 | if (lower) { |
905 | 0 | i__1 = *n - 1; |
906 | 0 | for (i__ = 1; i__ <= i__1; ++i__) { |
907 | 0 | dlartg_(&d__[i__], &e[i__], &cs, &sn, &r__); |
908 | 0 | d__[i__] = r__; |
909 | 0 | e[i__] = sn * d__[i__ + 1]; |
910 | 0 | d__[i__ + 1] = cs * d__[i__ + 1]; |
911 | 0 | work[i__] = cs; |
912 | 0 | work[nm1 + i__] = sn; |
913 | | /* L10: */ |
914 | 0 | } |
915 | | |
916 | | /* Update singular vectors if desired */ |
917 | |
|
918 | 0 | if (*nru > 0) { |
919 | 0 | dlasr_("R", "V", "F", nru, n, &work[1], &work[*n], &u[u_offset], |
920 | 0 | ldu); |
921 | 0 | } |
922 | 0 | if (*ncc > 0) { |
923 | 0 | dlasr_("L", "V", "F", n, ncc, &work[1], &work[*n], &c__[c_offset], |
924 | 0 | ldc); |
925 | 0 | } |
926 | 0 | } |
927 | | |
928 | | /* Compute singular values to relative accuracy TOL */ |
929 | | /* (By setting TOL to be negative, algorithm will compute */ |
930 | | /* singular values to absolute accuracy ABS(TOL)*norm(input matrix)) */ |
931 | | |
932 | | /* Computing MAX */ |
933 | | /* Computing MIN */ |
934 | 0 | d__3 = 100., d__4 = pow_dd(&eps, &c_b15); |
935 | 0 | d__1 = 10., d__2 = f2cmin(d__3,d__4); |
936 | 0 | tolmul = f2cmax(d__1,d__2); |
937 | 0 | tol = tolmul * eps; |
938 | | |
939 | | /* Compute approximate maximum, minimum singular values */ |
940 | |
|
941 | 0 | smax = 0.; |
942 | 0 | i__1 = *n; |
943 | 0 | for (i__ = 1; i__ <= i__1; ++i__) { |
944 | | /* Computing MAX */ |
945 | 0 | d__2 = smax, d__3 = (d__1 = d__[i__], abs(d__1)); |
946 | 0 | smax = f2cmax(d__2,d__3); |
947 | | /* L20: */ |
948 | 0 | } |
949 | 0 | i__1 = *n - 1; |
950 | 0 | for (i__ = 1; i__ <= i__1; ++i__) { |
951 | | /* Computing MAX */ |
952 | 0 | d__2 = smax, d__3 = (d__1 = e[i__], abs(d__1)); |
953 | 0 | smax = f2cmax(d__2,d__3); |
954 | | /* L30: */ |
955 | 0 | } |
956 | 0 | sminl = 0.; |
957 | 0 | if (tol >= 0.) { |
958 | | |
959 | | /* Relative accuracy desired */ |
960 | |
|
961 | 0 | sminoa = abs(d__[1]); |
962 | 0 | if (sminoa == 0.) { |
963 | 0 | goto L50; |
964 | 0 | } |
965 | 0 | mu = sminoa; |
966 | 0 | i__1 = *n; |
967 | 0 | for (i__ = 2; i__ <= i__1; ++i__) { |
968 | 0 | mu = (d__2 = d__[i__], abs(d__2)) * (mu / (mu + (d__1 = e[i__ - 1] |
969 | 0 | , abs(d__1)))); |
970 | 0 | sminoa = f2cmin(sminoa,mu); |
971 | 0 | if (sminoa == 0.) { |
972 | 0 | goto L50; |
973 | 0 | } |
974 | | /* L40: */ |
975 | 0 | } |
976 | 0 | L50: |
977 | 0 | sminoa /= sqrt((doublereal) (*n)); |
978 | | /* Computing MAX */ |
979 | 0 | d__1 = tol * sminoa, d__2 = *n * (*n * unfl) * 6; |
980 | 0 | thresh = f2cmax(d__1,d__2); |
981 | 0 | } else { |
982 | | |
983 | | /* Absolute accuracy desired */ |
984 | | |
985 | | /* Computing MAX */ |
986 | 0 | d__1 = abs(tol) * smax, d__2 = *n * (*n * unfl) * 6; |
987 | 0 | thresh = f2cmax(d__1,d__2); |
988 | 0 | } |
989 | | |
990 | | /* Prepare for main iteration loop for the singular values */ |
991 | | /* (MAXIT is the maximum number of passes through the inner */ |
992 | | /* loop permitted before nonconvergence signalled.) */ |
993 | | |
994 | 0 | maxitdivn = *n * 6; |
995 | 0 | iterdivn = 0; |
996 | 0 | iter = -1; |
997 | 0 | oldll = -1; |
998 | 0 | oldm = -1; |
999 | | |
1000 | | /* M points to last element of unconverged part of matrix */ |
1001 | |
|
1002 | 0 | m = *n; |
1003 | | |
1004 | | /* Begin main iteration loop */ |
1005 | |
|
1006 | 0 | L60: |
1007 | | |
1008 | | /* Check for convergence or exceeding iteration count */ |
1009 | |
|
1010 | 0 | if (m <= 1) { |
1011 | 0 | goto L160; |
1012 | 0 | } |
1013 | | |
1014 | 0 | if (iter >= *n) { |
1015 | 0 | iter -= *n; |
1016 | 0 | ++iterdivn; |
1017 | 0 | if (iterdivn >= maxitdivn) { |
1018 | 0 | goto L200; |
1019 | 0 | } |
1020 | 0 | } |
1021 | | |
1022 | | /* Find diagonal block of matrix to work on */ |
1023 | | |
1024 | 0 | if (tol < 0. && (d__1 = d__[m], abs(d__1)) <= thresh) { |
1025 | 0 | d__[m] = 0.; |
1026 | 0 | } |
1027 | 0 | smax = (d__1 = d__[m], abs(d__1)); |
1028 | 0 | smin = smax; |
1029 | 0 | i__1 = m - 1; |
1030 | 0 | for (lll = 1; lll <= i__1; ++lll) { |
1031 | 0 | ll = m - lll; |
1032 | 0 | abss = (d__1 = d__[ll], abs(d__1)); |
1033 | 0 | abse = (d__1 = e[ll], abs(d__1)); |
1034 | 0 | if (tol < 0. && abss <= thresh) { |
1035 | 0 | d__[ll] = 0.; |
1036 | 0 | } |
1037 | 0 | if (abse <= thresh) { |
1038 | 0 | goto L80; |
1039 | 0 | } |
1040 | 0 | smin = f2cmin(smin,abss); |
1041 | | /* Computing MAX */ |
1042 | 0 | d__1 = f2cmax(smax,abss); |
1043 | 0 | smax = f2cmax(d__1,abse); |
1044 | | /* L70: */ |
1045 | 0 | } |
1046 | 0 | ll = 0; |
1047 | 0 | goto L90; |
1048 | 0 | L80: |
1049 | 0 | e[ll] = 0.; |
1050 | | |
1051 | | /* Matrix splits since E(LL) = 0 */ |
1052 | |
|
1053 | 0 | if (ll == m - 1) { |
1054 | | |
1055 | | /* Convergence of bottom singular value, return to top of loop */ |
1056 | |
|
1057 | 0 | --m; |
1058 | 0 | goto L60; |
1059 | 0 | } |
1060 | 0 | L90: |
1061 | 0 | ++ll; |
1062 | | |
1063 | | /* E(LL) through E(M-1) are nonzero, E(LL-1) is zero */ |
1064 | |
|
1065 | 0 | if (ll == m - 1) { |
1066 | | |
1067 | | /* 2 by 2 block, handle separately */ |
1068 | |
|
1069 | 0 | dlasv2_(&d__[m - 1], &e[m - 1], &d__[m], &sigmn, &sigmx, &sinr, &cosr, |
1070 | 0 | &sinl, &cosl); |
1071 | 0 | d__[m - 1] = sigmx; |
1072 | 0 | e[m - 1] = 0.; |
1073 | 0 | d__[m] = sigmn; |
1074 | | |
1075 | | /* Compute singular vectors, if desired */ |
1076 | |
|
1077 | 0 | if (*ncvt > 0) { |
1078 | 0 | drot_(ncvt, &vt[m - 1 + vt_dim1], ldvt, &vt[m + vt_dim1], ldvt, & |
1079 | 0 | cosr, &sinr); |
1080 | 0 | } |
1081 | 0 | if (*nru > 0) { |
1082 | 0 | drot_(nru, &u[(m - 1) * u_dim1 + 1], &c__1, &u[m * u_dim1 + 1], & |
1083 | 0 | c__1, &cosl, &sinl); |
1084 | 0 | } |
1085 | 0 | if (*ncc > 0) { |
1086 | 0 | drot_(ncc, &c__[m - 1 + c_dim1], ldc, &c__[m + c_dim1], ldc, & |
1087 | 0 | cosl, &sinl); |
1088 | 0 | } |
1089 | 0 | m += -2; |
1090 | 0 | goto L60; |
1091 | 0 | } |
1092 | | |
1093 | | /* If working on new submatrix, choose shift direction */ |
1094 | | /* (from larger end diagonal element towards smaller) */ |
1095 | | |
1096 | 0 | if (ll > oldm || m < oldll) { |
1097 | 0 | if ((d__1 = d__[ll], abs(d__1)) >= (d__2 = d__[m], abs(d__2))) { |
1098 | | |
1099 | | /* Chase bulge from top (big end) to bottom (small end) */ |
1100 | |
|
1101 | 0 | idir = 1; |
1102 | 0 | } else { |
1103 | | |
1104 | | /* Chase bulge from bottom (big end) to top (small end) */ |
1105 | |
|
1106 | 0 | idir = 2; |
1107 | 0 | } |
1108 | 0 | } |
1109 | | |
1110 | | /* Apply convergence tests */ |
1111 | |
|
1112 | 0 | if (idir == 1) { |
1113 | | |
1114 | | /* Run convergence test in forward direction */ |
1115 | | /* First apply standard test to bottom of matrix */ |
1116 | |
|
1117 | 0 | if ((d__2 = e[m - 1], abs(d__2)) <= abs(tol) * (d__1 = d__[m], abs( |
1118 | 0 | d__1)) || tol < 0. && (d__3 = e[m - 1], abs(d__3)) <= thresh) |
1119 | 0 | { |
1120 | 0 | e[m - 1] = 0.; |
1121 | 0 | goto L60; |
1122 | 0 | } |
1123 | | |
1124 | 0 | if (tol >= 0.) { |
1125 | | |
1126 | | /* If relative accuracy desired, */ |
1127 | | /* apply convergence criterion forward */ |
1128 | |
|
1129 | 0 | mu = (d__1 = d__[ll], abs(d__1)); |
1130 | 0 | sminl = mu; |
1131 | 0 | i__1 = m - 1; |
1132 | 0 | for (lll = ll; lll <= i__1; ++lll) { |
1133 | 0 | if ((d__1 = e[lll], abs(d__1)) <= tol * mu) { |
1134 | 0 | e[lll] = 0.; |
1135 | 0 | goto L60; |
1136 | 0 | } |
1137 | 0 | mu = (d__2 = d__[lll + 1], abs(d__2)) * (mu / (mu + (d__1 = e[ |
1138 | 0 | lll], abs(d__1)))); |
1139 | 0 | sminl = f2cmin(sminl,mu); |
1140 | | /* L100: */ |
1141 | 0 | } |
1142 | 0 | } |
1143 | |
|
1144 | 0 | } else { |
1145 | | |
1146 | | /* Run convergence test in backward direction */ |
1147 | | /* First apply standard test to top of matrix */ |
1148 | |
|
1149 | 0 | if ((d__2 = e[ll], abs(d__2)) <= abs(tol) * (d__1 = d__[ll], abs(d__1) |
1150 | 0 | ) || tol < 0. && (d__3 = e[ll], abs(d__3)) <= thresh) { |
1151 | 0 | e[ll] = 0.; |
1152 | 0 | goto L60; |
1153 | 0 | } |
1154 | | |
1155 | 0 | if (tol >= 0.) { |
1156 | | |
1157 | | /* If relative accuracy desired, */ |
1158 | | /* apply convergence criterion backward */ |
1159 | |
|
1160 | 0 | mu = (d__1 = d__[m], abs(d__1)); |
1161 | 0 | sminl = mu; |
1162 | 0 | i__1 = ll; |
1163 | 0 | for (lll = m - 1; lll >= i__1; --lll) { |
1164 | 0 | if ((d__1 = e[lll], abs(d__1)) <= tol * mu) { |
1165 | 0 | e[lll] = 0.; |
1166 | 0 | goto L60; |
1167 | 0 | } |
1168 | 0 | mu = (d__2 = d__[lll], abs(d__2)) * (mu / (mu + (d__1 = e[lll] |
1169 | 0 | , abs(d__1)))); |
1170 | 0 | sminl = f2cmin(sminl,mu); |
1171 | | /* L110: */ |
1172 | 0 | } |
1173 | 0 | } |
1174 | 0 | } |
1175 | 0 | oldll = ll; |
1176 | 0 | oldm = m; |
1177 | | |
1178 | | /* Compute shift. First, test if shifting would ruin relative */ |
1179 | | /* accuracy, and if so set the shift to zero. */ |
1180 | | |
1181 | | /* Computing MAX */ |
1182 | 0 | d__1 = eps, d__2 = tol * .01; |
1183 | 0 | if (tol >= 0. && *n * tol * (sminl / smax) <= f2cmax(d__1,d__2)) { |
1184 | | |
1185 | | /* Use a zero shift to avoid loss of relative accuracy */ |
1186 | |
|
1187 | 0 | shift = 0.; |
1188 | 0 | } else { |
1189 | | |
1190 | | /* Compute the shift from 2-by-2 block at end of matrix */ |
1191 | |
|
1192 | 0 | if (idir == 1) { |
1193 | 0 | sll = (d__1 = d__[ll], abs(d__1)); |
1194 | 0 | dlas2_(&d__[m - 1], &e[m - 1], &d__[m], &shift, &r__); |
1195 | 0 | } else { |
1196 | 0 | sll = (d__1 = d__[m], abs(d__1)); |
1197 | 0 | dlas2_(&d__[ll], &e[ll], &d__[ll + 1], &shift, &r__); |
1198 | 0 | } |
1199 | | |
1200 | | /* Test if shift negligible, and if so set to zero */ |
1201 | |
|
1202 | 0 | if (sll > 0.) { |
1203 | | /* Computing 2nd power */ |
1204 | 0 | d__1 = shift / sll; |
1205 | 0 | if (d__1 * d__1 < eps) { |
1206 | 0 | shift = 0.; |
1207 | 0 | } |
1208 | 0 | } |
1209 | 0 | } |
1210 | | |
1211 | | /* Increment iteration count */ |
1212 | |
|
1213 | 0 | iter = iter + m - ll; |
1214 | | |
1215 | | /* If SHIFT = 0, do simplified QR iteration */ |
1216 | |
|
1217 | 0 | if (shift == 0.) { |
1218 | 0 | if (idir == 1) { |
1219 | | |
1220 | | /* Chase bulge from top to bottom */ |
1221 | | /* Save cosines and sines for later singular vector updates */ |
1222 | |
|
1223 | 0 | cs = 1.; |
1224 | 0 | oldcs = 1.; |
1225 | 0 | i__1 = m - 1; |
1226 | 0 | for (i__ = ll; i__ <= i__1; ++i__) { |
1227 | 0 | d__1 = d__[i__] * cs; |
1228 | 0 | dlartg_(&d__1, &e[i__], &cs, &sn, &r__); |
1229 | 0 | if (i__ > ll) { |
1230 | 0 | e[i__ - 1] = oldsn * r__; |
1231 | 0 | } |
1232 | 0 | d__1 = oldcs * r__; |
1233 | 0 | d__2 = d__[i__ + 1] * sn; |
1234 | 0 | dlartg_(&d__1, &d__2, &oldcs, &oldsn, &d__[i__]); |
1235 | 0 | work[i__ - ll + 1] = cs; |
1236 | 0 | work[i__ - ll + 1 + nm1] = sn; |
1237 | 0 | work[i__ - ll + 1 + nm12] = oldcs; |
1238 | 0 | work[i__ - ll + 1 + nm13] = oldsn; |
1239 | | /* L120: */ |
1240 | 0 | } |
1241 | 0 | h__ = d__[m] * cs; |
1242 | 0 | d__[m] = h__ * oldcs; |
1243 | 0 | e[m - 1] = h__ * oldsn; |
1244 | | |
1245 | | /* Update singular vectors */ |
1246 | |
|
1247 | 0 | if (*ncvt > 0) { |
1248 | 0 | i__1 = m - ll + 1; |
1249 | 0 | dlasr_("L", "V", "F", &i__1, ncvt, &work[1], &work[*n], &vt[ |
1250 | 0 | ll + vt_dim1], ldvt); |
1251 | 0 | } |
1252 | 0 | if (*nru > 0) { |
1253 | 0 | i__1 = m - ll + 1; |
1254 | 0 | dlasr_("R", "V", "F", nru, &i__1, &work[nm12 + 1], &work[nm13 |
1255 | 0 | + 1], &u[ll * u_dim1 + 1], ldu); |
1256 | 0 | } |
1257 | 0 | if (*ncc > 0) { |
1258 | 0 | i__1 = m - ll + 1; |
1259 | 0 | dlasr_("L", "V", "F", &i__1, ncc, &work[nm12 + 1], &work[nm13 |
1260 | 0 | + 1], &c__[ll + c_dim1], ldc); |
1261 | 0 | } |
1262 | | |
1263 | | /* Test convergence */ |
1264 | |
|
1265 | 0 | if ((d__1 = e[m - 1], abs(d__1)) <= thresh) { |
1266 | 0 | e[m - 1] = 0.; |
1267 | 0 | } |
1268 | |
|
1269 | 0 | } else { |
1270 | | |
1271 | | /* Chase bulge from bottom to top */ |
1272 | | /* Save cosines and sines for later singular vector updates */ |
1273 | |
|
1274 | 0 | cs = 1.; |
1275 | 0 | oldcs = 1.; |
1276 | 0 | i__1 = ll + 1; |
1277 | 0 | for (i__ = m; i__ >= i__1; --i__) { |
1278 | 0 | d__1 = d__[i__] * cs; |
1279 | 0 | dlartg_(&d__1, &e[i__ - 1], &cs, &sn, &r__); |
1280 | 0 | if (i__ < m) { |
1281 | 0 | e[i__] = oldsn * r__; |
1282 | 0 | } |
1283 | 0 | d__1 = oldcs * r__; |
1284 | 0 | d__2 = d__[i__ - 1] * sn; |
1285 | 0 | dlartg_(&d__1, &d__2, &oldcs, &oldsn, &d__[i__]); |
1286 | 0 | work[i__ - ll] = cs; |
1287 | 0 | work[i__ - ll + nm1] = -sn; |
1288 | 0 | work[i__ - ll + nm12] = oldcs; |
1289 | 0 | work[i__ - ll + nm13] = -oldsn; |
1290 | | /* L130: */ |
1291 | 0 | } |
1292 | 0 | h__ = d__[ll] * cs; |
1293 | 0 | d__[ll] = h__ * oldcs; |
1294 | 0 | e[ll] = h__ * oldsn; |
1295 | | |
1296 | | /* Update singular vectors */ |
1297 | |
|
1298 | 0 | if (*ncvt > 0) { |
1299 | 0 | i__1 = m - ll + 1; |
1300 | 0 | dlasr_("L", "V", "B", &i__1, ncvt, &work[nm12 + 1], &work[ |
1301 | 0 | nm13 + 1], &vt[ll + vt_dim1], ldvt); |
1302 | 0 | } |
1303 | 0 | if (*nru > 0) { |
1304 | 0 | i__1 = m - ll + 1; |
1305 | 0 | dlasr_("R", "V", "B", nru, &i__1, &work[1], &work[*n], &u[ll * |
1306 | 0 | u_dim1 + 1], ldu); |
1307 | 0 | } |
1308 | 0 | if (*ncc > 0) { |
1309 | 0 | i__1 = m - ll + 1; |
1310 | 0 | dlasr_("L", "V", "B", &i__1, ncc, &work[1], &work[*n], &c__[ |
1311 | 0 | ll + c_dim1], ldc); |
1312 | 0 | } |
1313 | | |
1314 | | /* Test convergence */ |
1315 | |
|
1316 | 0 | if ((d__1 = e[ll], abs(d__1)) <= thresh) { |
1317 | 0 | e[ll] = 0.; |
1318 | 0 | } |
1319 | 0 | } |
1320 | 0 | } else { |
1321 | | |
1322 | | /* Use nonzero shift */ |
1323 | |
|
1324 | 0 | if (idir == 1) { |
1325 | | |
1326 | | /* Chase bulge from top to bottom */ |
1327 | | /* Save cosines and sines for later singular vector updates */ |
1328 | |
|
1329 | 0 | f = ((d__1 = d__[ll], abs(d__1)) - shift) * (d_sign(&c_b49, &d__[ |
1330 | 0 | ll]) + shift / d__[ll]); |
1331 | 0 | g = e[ll]; |
1332 | 0 | i__1 = m - 1; |
1333 | 0 | for (i__ = ll; i__ <= i__1; ++i__) { |
1334 | 0 | dlartg_(&f, &g, &cosr, &sinr, &r__); |
1335 | 0 | if (i__ > ll) { |
1336 | 0 | e[i__ - 1] = r__; |
1337 | 0 | } |
1338 | 0 | f = cosr * d__[i__] + sinr * e[i__]; |
1339 | 0 | e[i__] = cosr * e[i__] - sinr * d__[i__]; |
1340 | 0 | g = sinr * d__[i__ + 1]; |
1341 | 0 | d__[i__ + 1] = cosr * d__[i__ + 1]; |
1342 | 0 | dlartg_(&f, &g, &cosl, &sinl, &r__); |
1343 | 0 | d__[i__] = r__; |
1344 | 0 | f = cosl * e[i__] + sinl * d__[i__ + 1]; |
1345 | 0 | d__[i__ + 1] = cosl * d__[i__ + 1] - sinl * e[i__]; |
1346 | 0 | if (i__ < m - 1) { |
1347 | 0 | g = sinl * e[i__ + 1]; |
1348 | 0 | e[i__ + 1] = cosl * e[i__ + 1]; |
1349 | 0 | } |
1350 | 0 | work[i__ - ll + 1] = cosr; |
1351 | 0 | work[i__ - ll + 1 + nm1] = sinr; |
1352 | 0 | work[i__ - ll + 1 + nm12] = cosl; |
1353 | 0 | work[i__ - ll + 1 + nm13] = sinl; |
1354 | | /* L140: */ |
1355 | 0 | } |
1356 | 0 | e[m - 1] = f; |
1357 | | |
1358 | | /* Update singular vectors */ |
1359 | |
|
1360 | 0 | if (*ncvt > 0) { |
1361 | 0 | i__1 = m - ll + 1; |
1362 | 0 | dlasr_("L", "V", "F", &i__1, ncvt, &work[1], &work[*n], &vt[ |
1363 | 0 | ll + vt_dim1], ldvt); |
1364 | 0 | } |
1365 | 0 | if (*nru > 0) { |
1366 | 0 | i__1 = m - ll + 1; |
1367 | 0 | dlasr_("R", "V", "F", nru, &i__1, &work[nm12 + 1], &work[nm13 |
1368 | 0 | + 1], &u[ll * u_dim1 + 1], ldu); |
1369 | 0 | } |
1370 | 0 | if (*ncc > 0) { |
1371 | 0 | i__1 = m - ll + 1; |
1372 | 0 | dlasr_("L", "V", "F", &i__1, ncc, &work[nm12 + 1], &work[nm13 |
1373 | 0 | + 1], &c__[ll + c_dim1], ldc); |
1374 | 0 | } |
1375 | | |
1376 | | /* Test convergence */ |
1377 | |
|
1378 | 0 | if ((d__1 = e[m - 1], abs(d__1)) <= thresh) { |
1379 | 0 | e[m - 1] = 0.; |
1380 | 0 | } |
1381 | |
|
1382 | 0 | } else { |
1383 | | |
1384 | | /* Chase bulge from bottom to top */ |
1385 | | /* Save cosines and sines for later singular vector updates */ |
1386 | |
|
1387 | 0 | f = ((d__1 = d__[m], abs(d__1)) - shift) * (d_sign(&c_b49, &d__[m] |
1388 | 0 | ) + shift / d__[m]); |
1389 | 0 | g = e[m - 1]; |
1390 | 0 | i__1 = ll + 1; |
1391 | 0 | for (i__ = m; i__ >= i__1; --i__) { |
1392 | 0 | dlartg_(&f, &g, &cosr, &sinr, &r__); |
1393 | 0 | if (i__ < m) { |
1394 | 0 | e[i__] = r__; |
1395 | 0 | } |
1396 | 0 | f = cosr * d__[i__] + sinr * e[i__ - 1]; |
1397 | 0 | e[i__ - 1] = cosr * e[i__ - 1] - sinr * d__[i__]; |
1398 | 0 | g = sinr * d__[i__ - 1]; |
1399 | 0 | d__[i__ - 1] = cosr * d__[i__ - 1]; |
1400 | 0 | dlartg_(&f, &g, &cosl, &sinl, &r__); |
1401 | 0 | d__[i__] = r__; |
1402 | 0 | f = cosl * e[i__ - 1] + sinl * d__[i__ - 1]; |
1403 | 0 | d__[i__ - 1] = cosl * d__[i__ - 1] - sinl * e[i__ - 1]; |
1404 | 0 | if (i__ > ll + 1) { |
1405 | 0 | g = sinl * e[i__ - 2]; |
1406 | 0 | e[i__ - 2] = cosl * e[i__ - 2]; |
1407 | 0 | } |
1408 | 0 | work[i__ - ll] = cosr; |
1409 | 0 | work[i__ - ll + nm1] = -sinr; |
1410 | 0 | work[i__ - ll + nm12] = cosl; |
1411 | 0 | work[i__ - ll + nm13] = -sinl; |
1412 | | /* L150: */ |
1413 | 0 | } |
1414 | 0 | e[ll] = f; |
1415 | | |
1416 | | /* Test convergence */ |
1417 | |
|
1418 | 0 | if ((d__1 = e[ll], abs(d__1)) <= thresh) { |
1419 | 0 | e[ll] = 0.; |
1420 | 0 | } |
1421 | | |
1422 | | /* Update singular vectors if desired */ |
1423 | |
|
1424 | 0 | if (*ncvt > 0) { |
1425 | 0 | i__1 = m - ll + 1; |
1426 | 0 | dlasr_("L", "V", "B", &i__1, ncvt, &work[nm12 + 1], &work[ |
1427 | 0 | nm13 + 1], &vt[ll + vt_dim1], ldvt); |
1428 | 0 | } |
1429 | 0 | if (*nru > 0) { |
1430 | 0 | i__1 = m - ll + 1; |
1431 | 0 | dlasr_("R", "V", "B", nru, &i__1, &work[1], &work[*n], &u[ll * |
1432 | 0 | u_dim1 + 1], ldu); |
1433 | 0 | } |
1434 | 0 | if (*ncc > 0) { |
1435 | 0 | i__1 = m - ll + 1; |
1436 | 0 | dlasr_("L", "V", "B", &i__1, ncc, &work[1], &work[*n], &c__[ |
1437 | 0 | ll + c_dim1], ldc); |
1438 | 0 | } |
1439 | 0 | } |
1440 | 0 | } |
1441 | | |
1442 | | /* QR iteration finished, go back and check convergence */ |
1443 | |
|
1444 | 0 | goto L60; |
1445 | | |
1446 | | /* All singular values converged, so make them positive */ |
1447 | | |
1448 | 0 | L160: |
1449 | 0 | i__1 = *n; |
1450 | 0 | for (i__ = 1; i__ <= i__1; ++i__) { |
1451 | 0 | if (d__[i__] < 0.) { |
1452 | 0 | d__[i__] = -d__[i__]; |
1453 | | |
1454 | | /* Change sign of singular vectors, if desired */ |
1455 | |
|
1456 | 0 | if (*ncvt > 0) { |
1457 | 0 | dscal_(ncvt, &c_b72, &vt[i__ + vt_dim1], ldvt); |
1458 | 0 | } |
1459 | 0 | } |
1460 | | /* L170: */ |
1461 | 0 | } |
1462 | | |
1463 | | /* Sort the singular values into decreasing order (insertion sort on */ |
1464 | | /* singular values, but only one transposition per singular vector) */ |
1465 | |
|
1466 | 0 | i__1 = *n - 1; |
1467 | 0 | for (i__ = 1; i__ <= i__1; ++i__) { |
1468 | | |
1469 | | /* Scan for smallest D(I) */ |
1470 | |
|
1471 | 0 | isub = 1; |
1472 | 0 | smin = d__[1]; |
1473 | 0 | i__2 = *n + 1 - i__; |
1474 | 0 | for (j = 2; j <= i__2; ++j) { |
1475 | 0 | if (d__[j] <= smin) { |
1476 | 0 | isub = j; |
1477 | 0 | smin = d__[j]; |
1478 | 0 | } |
1479 | | /* L180: */ |
1480 | 0 | } |
1481 | 0 | if (isub != *n + 1 - i__) { |
1482 | | |
1483 | | /* Swap singular values and vectors */ |
1484 | |
|
1485 | 0 | d__[isub] = d__[*n + 1 - i__]; |
1486 | 0 | d__[*n + 1 - i__] = smin; |
1487 | 0 | if (*ncvt > 0) { |
1488 | 0 | dswap_(ncvt, &vt[isub + vt_dim1], ldvt, &vt[*n + 1 - i__ + |
1489 | 0 | vt_dim1], ldvt); |
1490 | 0 | } |
1491 | 0 | if (*nru > 0) { |
1492 | 0 | dswap_(nru, &u[isub * u_dim1 + 1], &c__1, &u[(*n + 1 - i__) * |
1493 | 0 | u_dim1 + 1], &c__1); |
1494 | 0 | } |
1495 | 0 | if (*ncc > 0) { |
1496 | 0 | dswap_(ncc, &c__[isub + c_dim1], ldc, &c__[*n + 1 - i__ + |
1497 | 0 | c_dim1], ldc); |
1498 | 0 | } |
1499 | 0 | } |
1500 | | /* L190: */ |
1501 | 0 | } |
1502 | 0 | goto L220; |
1503 | | |
1504 | | /* Maximum number of iterations exceeded, failure to converge */ |
1505 | | |
1506 | 0 | L200: |
1507 | 0 | *info = 0; |
1508 | 0 | i__1 = *n - 1; |
1509 | 0 | for (i__ = 1; i__ <= i__1; ++i__) { |
1510 | 0 | if (e[i__] != 0.) { |
1511 | 0 | ++(*info); |
1512 | 0 | } |
1513 | | /* L210: */ |
1514 | 0 | } |
1515 | 0 | L220: |
1516 | 0 | return; |
1517 | | |
1518 | | /* End of DBDSQR */ |
1519 | |
|
1520 | 0 | } /* dbdsqr_ */ |
1521 | | |