14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
22 typedef BLASLONG blasint;
24 #define blasabs(x) llabs(x)
26 #define blasabs(x) labs(x)
30 #define blasabs(x) abs(x)
33 typedef blasint integer;
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
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;}
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;}
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
63 /* Extern is for use with -E */
74 /*external read, write*/
83 /*internal read, write*/
113 /*rewind, backspace, endfile*/
125 ftnint *inex; /*parameters in standard's order*/
151 union Multitype { /* for multiple entry points */
162 typedef union Multitype Multitype;
164 struct Vardesc { /* for Namelist */
170 typedef struct Vardesc Vardesc;
177 typedef struct Namelist Namelist;
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)))
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)); }
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]);}
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);}
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)}
261 /* procedure parameter types for -A and -C++ */
263 #define F2C_proc_par_types 1
265 typedef logical (*L_fp)(...);
267 typedef logical (*L_fp)();
270 static float spow_ui(float x, integer n) {
271 float pow=1.0; unsigned long int u;
273 if(n < 0) n = -n, x = 1/x;
282 static double dpow_ui(double x, integer n) {
283 double pow=1.0; unsigned long int u;
285 if(n < 0) n = -n, x = 1/x;
295 static _Fcomplex cpow_ui(complex x, integer n) {
296 complex pow={1.0,0.0}; unsigned long int u;
298 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
300 if(u & 01) pow.r *= x.r, pow.i *= x.i;
301 if(u >>= 1) x.r *= x.r, x.i *= x.i;
305 _Fcomplex p={pow.r, pow.i};
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310 _Complex float pow=1.0; unsigned long int u;
312 if(n < 0) n = -n, x = 1/x;
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324 _Dcomplex pow={1.0,0.0}; unsigned long int u;
326 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
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];
333 _Dcomplex p = {pow._Val[0], pow._Val[1]};
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338 _Complex double pow=1.0; unsigned long int u;
340 if(n < 0) n = -n, x = 1/x;
350 static integer pow_ii(integer x, integer n) {
351 integer pow; unsigned long int u;
353 if (n == 0 || x == 1) pow = 1;
354 else if (x != -1) pow = x == 0 ? 1/x : 0;
357 if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
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];
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
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];
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;
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];
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];
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]);
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]);
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;
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];
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];
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]);
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]);
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;
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];
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];
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]);
467 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468 zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
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;
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];
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];
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]);
498 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499 zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
505 /* -- translated by f2c (version 20000121).
506 You must link the resulting object file with the libraries:
507 -lf2c -lm (in that order)
513 /* Table of constant values */
515 static doublereal c_b15 = -.125;
516 static integer c__1 = 1;
517 static doublereal c_b49 = 1.;
518 static doublereal c_b72 = -1.;
520 /* > \brief \b ZBDSQR */
522 /* =========== DOCUMENTATION =========== */
524 /* Online html documentation available at */
525 /* http://www.netlib.org/lapack/explore-html/ */
528 /* > Download ZBDSQR + dependencies */
529 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zbdsqr.
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zbdsqr.
535 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zbdsqr.
543 /* SUBROUTINE ZBDSQR( UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U, */
544 /* LDU, C, LDC, RWORK, INFO ) */
547 /* INTEGER INFO, LDC, LDU, LDVT, N, NCC, NCVT, NRU */
548 /* DOUBLE PRECISION D( * ), E( * ), RWORK( * ) */
549 /* COMPLEX*16 C( LDC, * ), U( LDU, * ), VT( LDVT, * ) */
552 /* > \par Purpose: */
557 /* > ZBDSQR 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 */
562 /* > B = Q * S * P**H */
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**H*VT instead of */
569 /* > P**H, for given complex input matrices U and VT. When U and VT are */
570 /* > the unitary matrices that reduce a general matrix A to bidiagonal */
571 /* > form: A = U*B*VT, as computed by ZGEBRD, then */
573 /* > A = (U*Q) * S * (P**H*VT) */
575 /* > is the SVD of A. Optionally, the subroutine may also compute Q**H*C */
576 /* > for a given complex input matrix C. */
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. */
591 /* > \param[in] UPLO */
593 /* > UPLO is CHARACTER*1 */
594 /* > = 'U': B is upper bidiagonal; */
595 /* > = 'L': B is lower bidiagonal. */
601 /* > The order of the matrix B. N >= 0. */
604 /* > \param[in] NCVT */
606 /* > NCVT is INTEGER */
607 /* > The number of columns of the matrix VT. NCVT >= 0. */
610 /* > \param[in] NRU */
612 /* > NRU is INTEGER */
613 /* > The number of rows of the matrix U. NRU >= 0. */
616 /* > \param[in] NCC */
618 /* > NCC is INTEGER */
619 /* > The number of columns of the matrix C. NCC >= 0. */
622 /* > \param[in,out] D */
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 */
630 /* > \param[in,out] E */
632 /* > E is DOUBLE PRECISION array, dimension (N-1) */
633 /* > On entry, the N-1 offdiagonal elements of the bidiagonal */
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 */
641 /* > \param[in,out] VT */
643 /* > VT is COMPLEX*16 array, dimension (LDVT, NCVT) */
644 /* > On entry, an N-by-NCVT matrix VT. */
645 /* > On exit, VT is overwritten by P**H * VT. */
646 /* > Not referenced if NCVT = 0. */
649 /* > \param[in] LDVT */
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. */
656 /* > \param[in,out] U */
658 /* > U is COMPLEX*16 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. */
664 /* > \param[in] LDU */
666 /* > LDU is INTEGER */
667 /* > The leading dimension of the array U. LDU >= f2cmax(1,NRU). */
670 /* > \param[in,out] C */
672 /* > C is COMPLEX*16 array, dimension (LDC, NCC) */
673 /* > On entry, an N-by-NCC matrix C. */
674 /* > On exit, C is overwritten by Q**H * C. */
675 /* > Not referenced if NCC = 0. */
678 /* > \param[in] LDC */
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. */
685 /* > \param[out] RWORK */
687 /* > RWORK is DOUBLE PRECISION array, dimension (4*N) */
690 /* > \param[out] INFO */
692 /* > INFO is INTEGER */
693 /* > = 0: successful exit */
694 /* > < 0: If INFO = -i, the i-th argument had an illegal value */
695 /* > > 0: the algorithm did not converge; D and E contain the */
696 /* > elements of a bidiagonal matrix which is orthogonally */
697 /* > similar to the input matrix B; if INFO = i, i */
698 /* > elements of E have not converged to zero. */
701 /* > \par Internal Parameters: */
702 /* ========================= */
705 /* > TOLMUL DOUBLE PRECISION, default = f2cmax(10,f2cmin(100,EPS**(-1/8))) */
706 /* > TOLMUL controls the convergence criterion of the QR loop. */
707 /* > If it is positive, TOLMUL*EPS is the desired relative */
708 /* > precision in the computed singular values. */
709 /* > If it is negative, abs(TOLMUL*EPS*sigma_max) is the */
710 /* > desired absolute accuracy in the computed singular */
711 /* > values (corresponds to relative accuracy */
712 /* > abs(TOLMUL*EPS) in the largest singular value. */
713 /* > abs(TOLMUL) should be between 1 and 1/EPS, and preferably */
714 /* > between 10 (for fast convergence) and .1/EPS */
715 /* > (for there to be some accuracy in the results). */
716 /* > Default is to lose at either one eighth or 2 of the */
717 /* > available decimal digits in each computed singular value */
718 /* > (whichever is smaller). */
720 /* > MAXITR INTEGER, default = 6 */
721 /* > MAXITR controls the maximum number of passes of the */
722 /* > algorithm through its inner loop. The algorithms stops */
723 /* > (and so fails to converge) if the number of passes */
724 /* > through the inner loop exceeds MAXITR*N**2. */
730 /* > \author Univ. of Tennessee */
731 /* > \author Univ. of California Berkeley */
732 /* > \author Univ. of Colorado Denver */
733 /* > \author NAG Ltd. */
735 /* > \date December 2016 */
737 /* > \ingroup complex16OTHERcomputational */
739 /* ===================================================================== */
740 /* Subroutine */ int zbdsqr_(char *uplo, integer *n, integer *ncvt, integer *
741 nru, integer *ncc, doublereal *d__, doublereal *e, doublecomplex *vt,
742 integer *ldvt, doublecomplex *u, integer *ldu, doublecomplex *c__,
743 integer *ldc, doublereal *rwork, integer *info)
745 /* System generated locals */
746 integer c_dim1, c_offset, u_dim1, u_offset, vt_dim1, vt_offset, i__1,
748 doublereal d__1, d__2, d__3, d__4;
750 /* Local variables */
757 doublereal unfl, sinl, cosr, smin, smax, sinr;
758 extern /* Subroutine */ int dlas2_(doublereal *, doublereal *, doublereal
759 *, doublereal *, doublereal *);
760 doublereal f, g, h__;
763 extern logical lsame_(char *, char *);
766 doublereal shift, sigmn, oldsn;
768 doublereal sminl, sigmx;
770 extern /* Subroutine */ int zlasr_(char *, char *, char *, integer *,
771 integer *, doublereal *, doublereal *, doublecomplex *, integer *), zdrot_(integer *, doublecomplex *,
772 integer *, doublecomplex *, integer *, doublereal *, doublereal *)
773 , zswap_(integer *, doublecomplex *, integer *, doublecomplex *,
774 integer *), dlasq1_(integer *, doublereal *, doublereal *,
775 doublereal *, integer *), dlasv2_(doublereal *, doublereal *,
776 doublereal *, doublereal *, doublereal *, doublereal *,
777 doublereal *, doublereal *, doublereal *);
780 extern doublereal dlamch_(char *);
782 extern /* Subroutine */ int dlartg_(doublereal *, doublereal *,
783 doublereal *, doublereal *, doublereal *), xerbla_(char *,
784 integer *, ftnlen), zdscal_(integer *, doublereal *,
785 doublecomplex *, integer *);
786 doublereal sminoa, thresh;
790 integer nm12, nm13, lll;
791 doublereal eps, sll, tol;
794 /* -- LAPACK computational routine (version 3.7.0) -- */
795 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
796 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
800 /* ===================================================================== */
803 /* Test the input parameters. */
805 /* Parameter adjustments */
809 vt_offset = 1 + vt_dim1 * 1;
812 u_offset = 1 + u_dim1 * 1;
815 c_offset = 1 + c_dim1 * 1;
821 lower = lsame_(uplo, "L");
822 if (! lsame_(uplo, "U") && ! lower) {
826 } else if (*ncvt < 0) {
828 } else if (*nru < 0) {
830 } else if (*ncc < 0) {
832 } else if (*ncvt == 0 && *ldvt < 1 || *ncvt > 0 && *ldvt < f2cmax(1,*n)) {
834 } else if (*ldu < f2cmax(1,*nru)) {
836 } else if (*ncc == 0 && *ldc < 1 || *ncc > 0 && *ldc < f2cmax(1,*n)) {
841 xerbla_("ZBDSQR", &i__1, (ftnlen)6);
851 /* ROTATE is true if any singular vectors desired, false otherwise */
853 rotate = *ncvt > 0 || *nru > 0 || *ncc > 0;
855 /* If no singular vectors desired, use qd algorithm */
858 dlasq1_(n, &d__[1], &e[1], &rwork[1], info);
860 /* If INFO equals 2, dqds didn't finish, try to finish */
873 /* Get machine constants */
875 eps = dlamch_("Epsilon");
876 unfl = dlamch_("Safe minimum");
878 /* If matrix lower bidiagonal, rotate to be upper bidiagonal */
879 /* by applying Givens rotations on the left */
883 for (i__ = 1; i__ <= i__1; ++i__) {
884 dlartg_(&d__[i__], &e[i__], &cs, &sn, &r__);
886 e[i__] = sn * d__[i__ + 1];
887 d__[i__ + 1] = cs * d__[i__ + 1];
889 rwork[nm1 + i__] = sn;
893 /* Update singular vectors if desired */
896 zlasr_("R", "V", "F", nru, n, &rwork[1], &rwork[*n], &u[u_offset],
900 zlasr_("L", "V", "F", n, ncc, &rwork[1], &rwork[*n], &c__[
905 /* Compute singular values to relative accuracy TOL */
906 /* (By setting TOL to be negative, algorithm will compute */
907 /* singular values to absolute accuracy ABS(TOL)*norm(input matrix)) */
911 d__3 = 100., d__4 = pow_dd(&eps, &c_b15);
912 d__1 = 10., d__2 = f2cmin(d__3,d__4);
913 tolmul = f2cmax(d__1,d__2);
916 /* Compute approximate maximum, minimum singular values */
920 for (i__ = 1; i__ <= i__1; ++i__) {
922 d__2 = smax, d__3 = (d__1 = d__[i__], abs(d__1));
923 smax = f2cmax(d__2,d__3);
927 for (i__ = 1; i__ <= i__1; ++i__) {
929 d__2 = smax, d__3 = (d__1 = e[i__], abs(d__1));
930 smax = f2cmax(d__2,d__3);
936 /* Relative accuracy desired */
938 sminoa = abs(d__[1]);
944 for (i__ = 2; i__ <= i__1; ++i__) {
945 mu = (d__2 = d__[i__], abs(d__2)) * (mu / (mu + (d__1 = e[i__ - 1]
947 sminoa = f2cmin(sminoa,mu);
954 sminoa /= sqrt((doublereal) (*n));
956 d__1 = tol * sminoa, d__2 = *n * 6 * *n * unfl;
957 thresh = f2cmax(d__1,d__2);
960 /* Absolute accuracy desired */
963 d__1 = abs(tol) * smax, d__2 = *n * 6 * *n * unfl;
964 thresh = f2cmax(d__1,d__2);
967 /* Prepare for main iteration loop for the singular values */
968 /* (MAXIT is the maximum number of passes through the inner */
969 /* loop permitted before nonconvergence signalled.) */
976 /* M points to last element of unconverged part of matrix */
980 /* Begin main iteration loop */
984 /* Check for convergence or exceeding iteration count */
993 /* Find diagonal block of matrix to work on */
995 if (tol < 0. && (d__1 = d__[m], abs(d__1)) <= thresh) {
998 smax = (d__1 = d__[m], abs(d__1));
1001 for (lll = 1; lll <= i__1; ++lll) {
1003 abss = (d__1 = d__[ll], abs(d__1));
1004 abse = (d__1 = e[ll], abs(d__1));
1005 if (tol < 0. && abss <= thresh) {
1008 if (abse <= thresh) {
1011 smin = f2cmin(smin,abss);
1013 d__1 = f2cmax(smax,abss);
1014 smax = f2cmax(d__1,abse);
1022 /* Matrix splits since E(LL) = 0 */
1026 /* Convergence of bottom singular value, return to top of loop */
1034 /* E(LL) through E(M-1) are nonzero, E(LL-1) is zero */
1038 /* 2 by 2 block, handle separately */
1040 dlasv2_(&d__[m - 1], &e[m - 1], &d__[m], &sigmn, &sigmx, &sinr, &cosr,
1046 /* Compute singular vectors, if desired */
1049 zdrot_(ncvt, &vt[m - 1 + vt_dim1], ldvt, &vt[m + vt_dim1], ldvt, &
1053 zdrot_(nru, &u[(m - 1) * u_dim1 + 1], &c__1, &u[m * u_dim1 + 1], &
1054 c__1, &cosl, &sinl);
1057 zdrot_(ncc, &c__[m - 1 + c_dim1], ldc, &c__[m + c_dim1], ldc, &
1064 /* If working on new submatrix, choose shift direction */
1065 /* (from larger end diagonal element towards smaller) */
1067 if (ll > oldm || m < oldll) {
1068 if ((d__1 = d__[ll], abs(d__1)) >= (d__2 = d__[m], abs(d__2))) {
1070 /* Chase bulge from top (big end) to bottom (small end) */
1075 /* Chase bulge from bottom (big end) to top (small end) */
1081 /* Apply convergence tests */
1085 /* Run convergence test in forward direction */
1086 /* First apply standard test to bottom of matrix */
1088 if ((d__2 = e[m - 1], abs(d__2)) <= abs(tol) * (d__1 = d__[m], abs(
1089 d__1)) || tol < 0. && (d__3 = e[m - 1], abs(d__3)) <= thresh)
1097 /* If relative accuracy desired, */
1098 /* apply convergence criterion forward */
1100 mu = (d__1 = d__[ll], abs(d__1));
1103 for (lll = ll; lll <= i__1; ++lll) {
1104 if ((d__1 = e[lll], abs(d__1)) <= tol * mu) {
1108 mu = (d__2 = d__[lll + 1], abs(d__2)) * (mu / (mu + (d__1 = e[
1110 sminl = f2cmin(sminl,mu);
1117 /* Run convergence test in backward direction */
1118 /* First apply standard test to top of matrix */
1120 if ((d__2 = e[ll], abs(d__2)) <= abs(tol) * (d__1 = d__[ll], abs(d__1)
1121 ) || tol < 0. && (d__3 = e[ll], abs(d__3)) <= thresh) {
1128 /* If relative accuracy desired, */
1129 /* apply convergence criterion backward */
1131 mu = (d__1 = d__[m], abs(d__1));
1134 for (lll = m - 1; lll >= i__1; --lll) {
1135 if ((d__1 = e[lll], abs(d__1)) <= tol * mu) {
1139 mu = (d__2 = d__[lll], abs(d__2)) * (mu / (mu + (d__1 = e[lll]
1141 sminl = f2cmin(sminl,mu);
1149 /* Compute shift. First, test if shifting would ruin relative */
1150 /* accuracy, and if so set the shift to zero. */
1153 d__1 = eps, d__2 = tol * .01;
1154 if (tol >= 0. && *n * tol * (sminl / smax) <= f2cmax(d__1,d__2)) {
1156 /* Use a zero shift to avoid loss of relative accuracy */
1161 /* Compute the shift from 2-by-2 block at end of matrix */
1164 sll = (d__1 = d__[ll], abs(d__1));
1165 dlas2_(&d__[m - 1], &e[m - 1], &d__[m], &shift, &r__);
1167 sll = (d__1 = d__[m], abs(d__1));
1168 dlas2_(&d__[ll], &e[ll], &d__[ll + 1], &shift, &r__);
1171 /* Test if shift negligible, and if so set to zero */
1174 /* Computing 2nd power */
1176 if (d__1 * d__1 < eps) {
1182 /* Increment iteration count */
1184 iter = iter + m - ll;
1186 /* If SHIFT = 0, do simplified QR iteration */
1191 /* Chase bulge from top to bottom */
1192 /* Save cosines and sines for later singular vector updates */
1197 for (i__ = ll; i__ <= i__1; ++i__) {
1198 d__1 = d__[i__] * cs;
1199 dlartg_(&d__1, &e[i__], &cs, &sn, &r__);
1201 e[i__ - 1] = oldsn * r__;
1204 d__2 = d__[i__ + 1] * sn;
1205 dlartg_(&d__1, &d__2, &oldcs, &oldsn, &d__[i__]);
1206 rwork[i__ - ll + 1] = cs;
1207 rwork[i__ - ll + 1 + nm1] = sn;
1208 rwork[i__ - ll + 1 + nm12] = oldcs;
1209 rwork[i__ - ll + 1 + nm13] = oldsn;
1213 d__[m] = h__ * oldcs;
1214 e[m - 1] = h__ * oldsn;
1216 /* Update singular vectors */
1220 zlasr_("L", "V", "F", &i__1, ncvt, &rwork[1], &rwork[*n], &vt[
1221 ll + vt_dim1], ldvt);
1225 zlasr_("R", "V", "F", nru, &i__1, &rwork[nm12 + 1], &rwork[
1226 nm13 + 1], &u[ll * u_dim1 + 1], ldu);
1230 zlasr_("L", "V", "F", &i__1, ncc, &rwork[nm12 + 1], &rwork[
1231 nm13 + 1], &c__[ll + c_dim1], ldc);
1234 /* Test convergence */
1236 if ((d__1 = e[m - 1], abs(d__1)) <= thresh) {
1242 /* Chase bulge from bottom to top */
1243 /* Save cosines and sines for later singular vector updates */
1248 for (i__ = m; i__ >= i__1; --i__) {
1249 d__1 = d__[i__] * cs;
1250 dlartg_(&d__1, &e[i__ - 1], &cs, &sn, &r__);
1252 e[i__] = oldsn * r__;
1255 d__2 = d__[i__ - 1] * sn;
1256 dlartg_(&d__1, &d__2, &oldcs, &oldsn, &d__[i__]);
1257 rwork[i__ - ll] = cs;
1258 rwork[i__ - ll + nm1] = -sn;
1259 rwork[i__ - ll + nm12] = oldcs;
1260 rwork[i__ - ll + nm13] = -oldsn;
1264 d__[ll] = h__ * oldcs;
1265 e[ll] = h__ * oldsn;
1267 /* Update singular vectors */
1271 zlasr_("L", "V", "B", &i__1, ncvt, &rwork[nm12 + 1], &rwork[
1272 nm13 + 1], &vt[ll + vt_dim1], ldvt);
1276 zlasr_("R", "V", "B", nru, &i__1, &rwork[1], &rwork[*n], &u[
1277 ll * u_dim1 + 1], ldu);
1281 zlasr_("L", "V", "B", &i__1, ncc, &rwork[1], &rwork[*n], &c__[
1285 /* Test convergence */
1287 if ((d__1 = e[ll], abs(d__1)) <= thresh) {
1293 /* Use nonzero shift */
1297 /* Chase bulge from top to bottom */
1298 /* Save cosines and sines for later singular vector updates */
1300 f = ((d__1 = d__[ll], abs(d__1)) - shift) * (d_sign(&c_b49, &d__[
1301 ll]) + shift / d__[ll]);
1304 for (i__ = ll; i__ <= i__1; ++i__) {
1305 dlartg_(&f, &g, &cosr, &sinr, &r__);
1309 f = cosr * d__[i__] + sinr * e[i__];
1310 e[i__] = cosr * e[i__] - sinr * d__[i__];
1311 g = sinr * d__[i__ + 1];
1312 d__[i__ + 1] = cosr * d__[i__ + 1];
1313 dlartg_(&f, &g, &cosl, &sinl, &r__);
1315 f = cosl * e[i__] + sinl * d__[i__ + 1];
1316 d__[i__ + 1] = cosl * d__[i__ + 1] - sinl * e[i__];
1318 g = sinl * e[i__ + 1];
1319 e[i__ + 1] = cosl * e[i__ + 1];
1321 rwork[i__ - ll + 1] = cosr;
1322 rwork[i__ - ll + 1 + nm1] = sinr;
1323 rwork[i__ - ll + 1 + nm12] = cosl;
1324 rwork[i__ - ll + 1 + nm13] = sinl;
1329 /* Update singular vectors */
1333 zlasr_("L", "V", "F", &i__1, ncvt, &rwork[1], &rwork[*n], &vt[
1334 ll + vt_dim1], ldvt);
1338 zlasr_("R", "V", "F", nru, &i__1, &rwork[nm12 + 1], &rwork[
1339 nm13 + 1], &u[ll * u_dim1 + 1], ldu);
1343 zlasr_("L", "V", "F", &i__1, ncc, &rwork[nm12 + 1], &rwork[
1344 nm13 + 1], &c__[ll + c_dim1], ldc);
1347 /* Test convergence */
1349 if ((d__1 = e[m - 1], abs(d__1)) <= thresh) {
1355 /* Chase bulge from bottom to top */
1356 /* Save cosines and sines for later singular vector updates */
1358 f = ((d__1 = d__[m], abs(d__1)) - shift) * (d_sign(&c_b49, &d__[m]
1359 ) + shift / d__[m]);
1362 for (i__ = m; i__ >= i__1; --i__) {
1363 dlartg_(&f, &g, &cosr, &sinr, &r__);
1367 f = cosr * d__[i__] + sinr * e[i__ - 1];
1368 e[i__ - 1] = cosr * e[i__ - 1] - sinr * d__[i__];
1369 g = sinr * d__[i__ - 1];
1370 d__[i__ - 1] = cosr * d__[i__ - 1];
1371 dlartg_(&f, &g, &cosl, &sinl, &r__);
1373 f = cosl * e[i__ - 1] + sinl * d__[i__ - 1];
1374 d__[i__ - 1] = cosl * d__[i__ - 1] - sinl * e[i__ - 1];
1376 g = sinl * e[i__ - 2];
1377 e[i__ - 2] = cosl * e[i__ - 2];
1379 rwork[i__ - ll] = cosr;
1380 rwork[i__ - ll + nm1] = -sinr;
1381 rwork[i__ - ll + nm12] = cosl;
1382 rwork[i__ - ll + nm13] = -sinl;
1387 /* Test convergence */
1389 if ((d__1 = e[ll], abs(d__1)) <= thresh) {
1393 /* Update singular vectors if desired */
1397 zlasr_("L", "V", "B", &i__1, ncvt, &rwork[nm12 + 1], &rwork[
1398 nm13 + 1], &vt[ll + vt_dim1], ldvt);
1402 zlasr_("R", "V", "B", nru, &i__1, &rwork[1], &rwork[*n], &u[
1403 ll * u_dim1 + 1], ldu);
1407 zlasr_("L", "V", "B", &i__1, ncc, &rwork[1], &rwork[*n], &c__[
1413 /* QR iteration finished, go back and check convergence */
1417 /* All singular values converged, so make them positive */
1421 for (i__ = 1; i__ <= i__1; ++i__) {
1422 if (d__[i__] < 0.) {
1423 d__[i__] = -d__[i__];
1425 /* Change sign of singular vectors, if desired */
1428 zdscal_(ncvt, &c_b72, &vt[i__ + vt_dim1], ldvt);
1434 /* Sort the singular values into decreasing order (insertion sort on */
1435 /* singular values, but only one transposition per singular vector) */
1438 for (i__ = 1; i__ <= i__1; ++i__) {
1440 /* Scan for smallest D(I) */
1444 i__2 = *n + 1 - i__;
1445 for (j = 2; j <= i__2; ++j) {
1446 if (d__[j] <= smin) {
1452 if (isub != *n + 1 - i__) {
1454 /* Swap singular values and vectors */
1456 d__[isub] = d__[*n + 1 - i__];
1457 d__[*n + 1 - i__] = smin;
1459 zswap_(ncvt, &vt[isub + vt_dim1], ldvt, &vt[*n + 1 - i__ +
1463 zswap_(nru, &u[isub * u_dim1 + 1], &c__1, &u[(*n + 1 - i__) *
1464 u_dim1 + 1], &c__1);
1467 zswap_(ncc, &c__[isub + c_dim1], ldc, &c__[*n + 1 - i__ +
1475 /* Maximum number of iterations exceeded, failure to converge */
1480 for (i__ = 1; i__ <= i__1; ++i__) {