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 real c_b10 = 1.f;
516 static doublereal c_b14 = -.125;
517 static integer c__1 = 1;
518 static real c_b19 = 0.f;
519 static integer c__2 = 2;
521 /* > \brief \b SBDSVDX */
523 /* =========== DOCUMENTATION =========== */
525 /* Online html documentation available at */
526 /* http://www.netlib.org/lapack/explore-html/ */
529 /* > Download SBDSVDX + dependencies */
530 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sbdsvdx
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sbdsvdx
536 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sbdsvdx
544 /* SUBROUTINE SBDSVDX( UPLO, JOBZ, RANGE, N, D, E, VL, VU, IL, IU, */
545 /* $ NS, S, Z, LDZ, WORK, IWORK, INFO ) */
547 /* CHARACTER JOBZ, RANGE, UPLO */
548 /* INTEGER IL, INFO, IU, LDZ, N, NS */
550 /* INTEGER IWORK( * ) */
551 /* REAL D( * ), E( * ), S( * ), WORK( * ), */
554 /* > \par Purpose: */
559 /* > SBDSVDX computes the singular value decomposition (SVD) of a real */
560 /* > N-by-N (upper or lower) bidiagonal matrix B, B = U * S * VT, */
561 /* > where S is a diagonal matrix with non-negative diagonal elements */
562 /* > (the singular values of B), and U and VT are orthogonal matrices */
563 /* > of left and right singular vectors, respectively. */
565 /* > Given an upper bidiagonal B with diagonal D = [ d_1 d_2 ... d_N ] */
566 /* > and superdiagonal E = [ e_1 e_2 ... e_N-1 ], SBDSVDX computes the */
567 /* > singular value decompositon of B through the eigenvalues and */
568 /* > eigenvectors of the N*2-by-N*2 tridiagonal matrix */
571 /* > | d_1 0 e_1 | */
572 /* > TGK = | e_1 0 d_2 | */
576 /* > If (s,u,v) is a singular triplet of B with ||u|| = ||v|| = 1, then */
577 /* > (+/-s,q), ||q|| = 1, are eigenpairs of TGK, with q = P * ( u' +/-v' ) / */
578 /* > sqrt(2) = ( v_1 u_1 v_2 u_2 ... v_n u_n ) / sqrt(2), and */
579 /* > P = [ e_{n+1} e_{1} e_{n+2} e_{2} ... ]. */
581 /* > Given a TGK matrix, one can either a) compute -s,-v and change signs */
582 /* > so that the singular values (and corresponding vectors) are already in */
583 /* > descending order (as in SGESVD/SGESDD) or b) compute s,v and reorder */
584 /* > the values (and corresponding vectors). SBDSVDX implements a) by */
585 /* > calling SSTEVX (bisection plus inverse iteration, to be replaced */
586 /* > with a version of the Multiple Relative Robust Representation */
587 /* > algorithm. (See P. Willems and B. Lang, A framework for the MR^3 */
588 /* > algorithm: theory and implementation, SIAM J. Sci. Comput., */
589 /* > 35:740-766, 2013.) */
595 /* > \param[in] UPLO */
597 /* > UPLO is CHARACTER*1 */
598 /* > = 'U': B is upper bidiagonal; */
599 /* > = 'L': B is lower bidiagonal. */
602 /* > \param[in] JOBZ */
604 /* > JOBZ is CHARACTER*1 */
605 /* > = 'N': Compute singular values only; */
606 /* > = 'V': Compute singular values and singular vectors. */
609 /* > \param[in] RANGE */
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. */
621 /* > The order of the bidiagonal matrix. N >= 0. */
626 /* > D is REAL array, dimension (N) */
627 /* > The n diagonal elements of the bidiagonal matrix B. */
632 /* > E is REAL array, dimension (f2cmax(1,N-1)) */
633 /* > The (n-1) superdiagonal elements of the bidiagonal matrix */
634 /* > B in elements 1 to N-1. */
637 /* > \param[in] VL */
640 /* > If RANGE='V', the lower bound of the interval to */
641 /* > be searched for singular values. VU > VL. */
642 /* > Not referenced if RANGE = 'A' or 'I'. */
645 /* > \param[in] VU */
648 /* > If RANGE='V', the upper bound of the interval to */
649 /* > be searched for singular values. VU > VL. */
650 /* > Not referenced if RANGE = 'A' or 'I'. */
653 /* > \param[in] IL */
655 /* > IL is INTEGER */
656 /* > If RANGE='I', the index of the */
657 /* > smallest singular value to be returned. */
658 /* > 1 <= IL <= IU <= f2cmin(M,N), if f2cmin(M,N) > 0. */
659 /* > Not referenced if RANGE = 'A' or 'V'. */
662 /* > \param[in] IU */
664 /* > IU is INTEGER */
665 /* > If RANGE='I', the index of the */
666 /* > largest singular value to be returned. */
667 /* > 1 <= IL <= IU <= f2cmin(M,N), if f2cmin(M,N) > 0. */
668 /* > Not referenced if RANGE = 'A' or 'V'. */
671 /* > \param[out] NS */
673 /* > NS is INTEGER */
674 /* > The total number of singular values found. 0 <= NS <= N. */
675 /* > If RANGE = 'A', NS = N, and if RANGE = 'I', NS = IU-IL+1. */
678 /* > \param[out] S */
680 /* > S is REAL array, dimension (N) */
681 /* > The first NS elements contain the selected singular values in */
682 /* > ascending order. */
685 /* > \param[out] Z */
687 /* > Z is REAL array, dimension (2*N,K) */
688 /* > If JOBZ = 'V', then if INFO = 0 the first NS columns of Z */
689 /* > contain the singular vectors of the matrix B corresponding to */
690 /* > the selected singular values, with U in rows 1 to N and V */
691 /* > in rows N+1 to N*2, i.e. */
694 /* > If JOBZ = 'N', then Z is not referenced. */
695 /* > Note: The user must ensure that at least K = NS+1 columns are */
696 /* > supplied in the array Z; if RANGE = 'V', the exact value of */
697 /* > NS is not known in advance and an upper bound must be used. */
700 /* > \param[in] LDZ */
702 /* > LDZ is INTEGER */
703 /* > The leading dimension of the array Z. LDZ >= 1, and if */
704 /* > JOBZ = 'V', LDZ >= f2cmax(2,N*2). */
707 /* > \param[out] WORK */
709 /* > WORK is REAL array, dimension (14*N) */
712 /* > \param[out] IWORK */
714 /* > IWORK is INTEGER array, dimension (12*N) */
715 /* > If JOBZ = 'V', then if INFO = 0, the first NS elements of */
716 /* > IWORK are zero. If INFO > 0, then IWORK contains the indices */
717 /* > of the eigenvectors that failed to converge in DSTEVX. */
720 /* > \param[out] INFO */
722 /* > INFO is INTEGER */
723 /* > = 0: successful exit */
724 /* > < 0: if INFO = -i, the i-th argument had an illegal value */
725 /* > > 0: if INFO = i, then i eigenvectors failed to converge */
726 /* > in SSTEVX. The indices of the eigenvectors */
727 /* > (as returned by SSTEVX) are stored in the */
729 /* > if INFO = N*2 + 1, an internal error occurred. */
735 /* > \author Univ. of Tennessee */
736 /* > \author Univ. of California Berkeley */
737 /* > \author Univ. of Colorado Denver */
738 /* > \author NAG Ltd. */
740 /* > \date June 2016 */
742 /* > \ingroup realOTHEReigen */
744 /* ===================================================================== */
745 /* Subroutine */ int sbdsvdx_(char *uplo, char *jobz, char *range, integer *n,
746 real *d__, real *e, real *vl, real *vu, integer *il, integer *iu,
747 integer *ns, real *s, real *z__, integer *ldz, real *work, integer *
748 iwork, integer *info)
750 /* System generated locals */
751 integer z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
752 real r__1, r__2, r__3, r__4;
755 /* Local variables */
759 extern real sdot_(integer *, real *, integer *, real *, integer *);
762 extern real snrm2_(integer *, real *, integer *);
763 integer i__, idbeg, j, k;
765 integer idend, isbeg;
766 extern logical lsame_(char *, char *);
767 integer idtgk, ietgk;
768 extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
769 integer iltgk, itemp, icolz;
773 integer ieptr, iutgk;
777 logical split, valsv;
780 extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
781 integer *), sswap_(integer *, real *, integer *, real *, integer *
785 integer irowu, irowv;
786 extern /* Subroutine */ int saxpy_(integer *, real *, real *, integer *,
788 integer irowz, iifail;
790 extern real slamch_(char *);
791 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
792 extern integer isamax_(integer *, real *, integer *);
794 extern /* Subroutine */ int slaset_(char *, integer *, integer *, real *,
795 real *, real *, integer *);
798 extern /* Subroutine */ int mecago_(), sstevx_(char *, char *,
799 integer *, real *, real *, real *, real *, integer *, integer *,
800 real *, integer *, real *, real *, integer *, real *, integer *,
801 integer *, integer *);
808 /* -- LAPACK driver routine (version 3.8.0) -- */
809 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
810 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
814 /* ===================================================================== */
817 /* Test the input parameters. */
819 /* Parameter adjustments */
824 z_offset = 1 + z_dim1 * 1;
830 allsv = lsame_(range, "A");
831 valsv = lsame_(range, "V");
832 indsv = lsame_(range, "I");
833 wantz = lsame_(jobz, "V");
834 lower = lsame_(uplo, "L");
837 if (! lsame_(uplo, "U") && ! lower) {
839 } else if (! (wantz || lsame_(jobz, "N"))) {
841 } else if (! (allsv || valsv || indsv)) {
849 } else if (*vu <= *vl) {
853 if (*il < 1 || *il > f2cmax(1,*n)) {
855 } else if (*iu < f2cmin(*n,*il) || *iu > *n) {
861 if (*ldz < 1 || wantz && *ldz < *n << 1) {
868 xerbla_("SBDSVDX", &i__1, (ftnlen)7);
872 /* Quick return if possible (N.LE.1) */
880 if (allsv || indsv) {
884 if (*vl < abs(d__[1]) && *vu >= abs(d__[1])) {
890 z__[z_dim1 + 1] = r_sign(&c_b10, &d__[1]);
891 z__[z_dim1 + 2] = 1.f;
896 abstol = slamch_("Safe Minimum") * 2;
897 ulp = slamch_("Precision");
898 eps = slamch_("Epsilon");
902 /* Criterion for splitting is taken from SBDSQR when singular */
903 /* values are computed to relative accuracy TOL. (See J. Demmel and */
904 /* W. Kahan, Accurate singular values of bidiagonal matrices, SIAM */
905 /* J. Sci. and Stat. Comput., 11:873–912, 1990.) */
909 d__1 = (doublereal) eps;
910 r__3 = 100.f, r__4 = pow_dd(&d__1, &c_b14);
911 r__1 = 10.f, r__2 = f2cmin(r__3,r__4);
912 tol = f2cmax(r__1,r__2) * eps;
914 /* Compute approximate maximum, minimum singular values. */
916 i__ = isamax_(n, &d__[1], &c__1);
917 smax = (r__1 = d__[i__], abs(r__1));
919 i__ = isamax_(&i__1, &e[1], &c__1);
921 r__2 = smax, r__3 = (r__1 = e[i__], abs(r__1));
922 smax = f2cmax(r__2,r__3);
924 /* Compute threshold for neglecting D's and E's. */
930 for (i__ = 2; i__ <= i__1; ++i__) {
931 mu = (r__2 = d__[i__], abs(r__2)) * (mu / (mu + (r__1 = e[i__ - 1]
933 smin = f2cmin(smin,mu);
939 smin /= sqrt((real) (*n));
942 /* Check for zeros in D and E (splits), i.e. submatrices. */
945 for (i__ = 1; i__ <= i__1; ++i__) {
946 if ((r__1 = d__[i__], abs(r__1)) <= thresh) {
949 if ((r__1 = e[i__], abs(r__1)) <= thresh) {
953 if ((r__1 = d__[*n], abs(r__1)) <= thresh) {
957 /* Pointers for arrays used by SSTEVX. */
960 ietgk = idtgk + (*n << 1);
961 itemp = ietgk + (*n << 1);
963 iiwork = iifail + (*n << 1);
965 /* Set RNGVX, which corresponds to RANGE for SSTEVX in TGK mode. */
966 /* VL,VU or IL,IU are redefined to conform to implementation a) */
967 /* described in the leading comments. */
976 /* All singular values will be found. We aim at -s (see */
977 /* leading comments) with RNGVX = 'I'. IL and IU are set */
978 /* later (as ILTGK and IUTGK) according to the dimension */
979 /* of the active submatrix. */
981 *(unsigned char *)rngvx = 'I';
985 slaset_("F", &i__1, &i__2, &c_b19, &c_b19, &z__[z_offset], ldz);
989 /* Find singular values in a half-open interval. We aim */
990 /* at -s (see leading comments) and we swap VL and VU */
991 /* (as VUTGK and VLTGK), changing their signs. */
993 *(unsigned char *)rngvx = 'V';
996 i__1 = idtgk + (*n << 1) - 1;
997 for (i__ = idtgk; i__ <= i__1; ++i__) {
1000 /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
1001 scopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
1003 scopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
1005 sstevx_("N", "V", &i__1, &work[idtgk], &work[ietgk], &vltgk, &vutgk, &
1006 iltgk, &iltgk, &abstol, ns, &s[1], &z__[z_offset], ldz, &work[
1007 itemp], &iwork[iiwork], &iwork[iifail], info);
1013 slaset_("F", &i__1, ns, &c_b19, &c_b19, &z__[z_offset], ldz);
1018 /* Find the IL-th through the IU-th singular values. We aim */
1019 /* at -s (see leading comments) and indices are mapped into */
1020 /* values, therefore mimicking SSTEBZ, where */
1022 /* GL = GL - FUDGE*TNORM*ULP*N - FUDGE*TWO*PIVMIN */
1023 /* GU = GU + FUDGE*TNORM*ULP*N + FUDGE*PIVMIN */
1027 *(unsigned char *)rngvx = 'V';
1028 i__1 = idtgk + (*n << 1) - 1;
1029 for (i__ = idtgk; i__ <= i__1; ++i__) {
1032 /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
1033 scopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
1035 scopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
1037 sstevx_("N", "I", &i__1, &work[idtgk], &work[ietgk], &vltgk, &vltgk, &
1038 iltgk, &iltgk, &abstol, ns, &s[1], &z__[z_offset], ldz, &work[
1039 itemp], &iwork[iiwork], &iwork[iifail], info);
1040 vltgk = s[1] - smax * 2.f * ulp * *n;
1041 i__1 = idtgk + (*n << 1) - 1;
1042 for (i__ = idtgk; i__ <= i__1; ++i__) {
1045 /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
1046 scopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
1048 scopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
1050 sstevx_("N", "I", &i__1, &work[idtgk], &work[ietgk], &vutgk, &vutgk, &
1051 iutgk, &iutgk, &abstol, ns, &s[1], &z__[z_offset], ldz, &work[
1052 itemp], &iwork[iiwork], &iwork[iifail], info);
1053 vutgk = s[1] + smax * 2.f * ulp * *n;
1054 vutgk = f2cmin(vutgk,0.f);
1056 /* If VLTGK=VUTGK, SSTEVX returns an error message, */
1057 /* so if needed we change VUTGK slightly. */
1059 if (vltgk == vutgk) {
1065 i__2 = *iu - *il + 1;
1066 slaset_("F", &i__1, &i__2, &c_b19, &c_b19, &z__[z_offset], ldz);
1070 /* Initialize variables and pointers for S, Z, and WORK. */
1072 /* NRU, NRV: number of rows in U and V for the active submatrix */
1073 /* IDBEG, ISBEG: offsets for the entries of D and S */
1074 /* IROWZ, ICOLZ: offsets for the rows and columns of Z */
1075 /* IROWU, IROWV: offsets for the rows of U and V */
1089 /* Form the tridiagonal TGK matrix. */
1092 for (i__ = 1; i__ <= i__1; ++i__) {
1095 /* S( 1:N ) = ZERO */
1096 work[ietgk + (*n << 1) - 1] = 0.f;
1097 i__1 = idtgk + (*n << 1) - 1;
1098 for (i__ = idtgk; i__ <= i__1; ++i__) {
1101 /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
1102 scopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
1104 scopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
1107 /* Check for splits in two levels, outer level */
1108 /* in E and inner level in D. */
1111 for (ieptr = 2; ieptr <= i__1; ieptr += 2) {
1112 if (work[ietgk + ieptr - 1] == 0.f) {
1114 /* Split in E (this piece of B is square) or bottom */
1115 /* of the (input bidiagonal) matrix. */
1120 for (idptr = idbeg; idptr <= i__2; idptr += 2) {
1121 if (work[ietgk + idptr - 1] == 0.f) {
1123 /* Split in D (rectangular submatrix). Set the number */
1124 /* of rows in U and V (NRU and NRV) accordingly. */
1126 if (idptr == idbeg) {
1128 /* D=0 at the top. */
1131 if (idbeg == idend) {
1135 } else if (idptr == idend) {
1137 /* D=0 at the bottom. */
1140 nru = (idend - isplt) / 2 + 1;
1142 if (isplt != idbeg) {
1146 if (isplt == idbeg) {
1148 /* Split: top rectangular submatrix. */
1150 nru = (idptr - idbeg) / 2;
1154 /* Split: middle square submatrix. */
1156 nru = (idptr - isplt) / 2 + 1;
1160 } else if (idptr == idend) {
1162 /* Last entry of D in the active submatrix. */
1164 if (isplt == idbeg) {
1166 /* No split (trivial case). */
1168 nru = (idend - idbeg) / 2 + 1;
1172 /* Split: bottom rectangular submatrix. */
1174 nrv = (idend - isplt) / 2 + 1;
1183 /* Compute eigenvalues/vectors of the active */
1184 /* submatrix according to RANGE: */
1185 /* if RANGE='A' (ALLSV) then RNGVX = 'I' */
1186 /* if RANGE='V' (VALSV) then RNGVX = 'V' */
1187 /* if RANGE='I' (INDSV) then RNGVX = 'V' */
1191 if (allsv || vutgk == 0.f) {
1192 if (sveq0 || smin < eps || ntgk % 2 > 0) {
1193 /* Special case: eigenvalue equal to zero or very */
1194 /* small, additional eigenvector is needed. */
1199 /* Workspace needed by SSTEVX: */
1200 /* WORK( ITEMP: ): 2*5*NTGK */
1201 /* IWORK( 1: ): 2*6*NTGK */
1203 sstevx_(jobz, rngvx, &ntgk, &work[idtgk + isplt - 1], &
1204 work[ietgk + isplt - 1], &vltgk, &vutgk, &iltgk, &
1205 iutgk, &abstol, &nsl, &s[isbeg], &z__[irowz +
1206 icolz * z_dim1], ldz, &work[itemp], &iwork[iiwork]
1207 , &iwork[iifail], info);
1209 /* Exit with the error code from SSTEVX. */
1212 emin = (r__1 = s[isbeg], abs(r__1));
1213 i__3 = isbeg + nsl - 1;
1214 for (i__ = isbeg; i__ <= i__3; ++i__) {
1215 if ((r__1 = s[i__], abs(r__1)) > emin) {
1219 /* EMIN = ABS( MAXVAL( S( ISBEG:ISBEG+NSL-1 ) ) ) */
1221 if (nsl > 0 && wantz) {
1223 /* Normalize u=Z([2,4,...],:) and v=Z([1,3,...],:), */
1224 /* changing the sign of v as discussed in the leading */
1225 /* comments. The norms of u and v may be (slightly) */
1226 /* different from 1/sqrt(2) if the corresponding */
1227 /* eigenvalues are very small or too close. We check */
1228 /* those norms and, if needed, reorthogonalize the */
1231 if (nsl > 1 && vutgk == 0.f && ntgk % 2 == 0 && emin
1232 == 0.f && ! split) {
1234 /* D=0 at the top or bottom of the active submatrix: */
1235 /* one eigenvalue is equal to zero; concatenate the */
1236 /* eigenvectors corresponding to the two smallest */
1239 i__3 = irowz + ntgk - 1;
1240 for (i__ = irowz; i__ <= i__3; ++i__) {
1241 z__[i__ + (icolz + nsl - 2) * z_dim1] += z__[
1242 i__ + (icolz + nsl - 1) * z_dim1];
1243 z__[i__ + (icolz + nsl - 1) * z_dim1] = 0.f;
1245 /* Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-2 ) = */
1246 /* $ Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-2 ) + */
1247 /* $ Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-1 ) */
1248 /* Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-1 ) = */
1250 /* IF( IUTGK*2.GT.NTGK ) THEN */
1251 /* Eigenvalue equal to zero or very small. */
1257 i__4 = nsl - 1, i__5 = nru - 1;
1258 i__3 = f2cmin(i__4,i__5);
1259 for (i__ = 0; i__ <= i__3; ++i__) {
1260 nrmu = snrm2_(&nru, &z__[irowu + (icolz + i__) *
1263 *info = (*n << 1) + 1;
1267 sscal_(&nru, &r__1, &z__[irowu + (icolz + i__) *
1269 if (nrmu != 1.f && (r__1 = nrmu - ortol, abs(r__1)
1272 for (j = 0; j <= i__4; ++j) {
1273 zjtji = -sdot_(&nru, &z__[irowu + (icolz
1274 + j) * z_dim1], &c__2, &z__[irowu
1275 + (icolz + i__) * z_dim1], &c__2);
1276 saxpy_(&nru, &zjtji, &z__[irowu + (icolz
1277 + j) * z_dim1], &c__2, &z__[irowu
1278 + (icolz + i__) * z_dim1], &c__2);
1280 nrmu = snrm2_(&nru, &z__[irowu + (icolz + i__)
1283 sscal_(&nru, &r__1, &z__[irowu + (icolz + i__)
1288 i__4 = nsl - 1, i__5 = nrv - 1;
1289 i__3 = f2cmin(i__4,i__5);
1290 for (i__ = 0; i__ <= i__3; ++i__) {
1291 nrmv = snrm2_(&nrv, &z__[irowv + (icolz + i__) *
1294 *info = (*n << 1) + 1;
1298 sscal_(&nrv, &r__1, &z__[irowv + (icolz + i__) *
1300 if (nrmv != 1.f && (r__1 = nrmv - ortol, abs(r__1)
1303 for (j = 0; j <= i__4; ++j) {
1304 zjtji = -sdot_(&nrv, &z__[irowv + (icolz
1305 + j) * z_dim1], &c__2, &z__[irowv
1306 + (icolz + i__) * z_dim1], &c__2);
1307 saxpy_(&nru, &zjtji, &z__[irowv + (icolz
1308 + j) * z_dim1], &c__2, &z__[irowv
1309 + (icolz + i__) * z_dim1], &c__2);
1311 nrmv = snrm2_(&nrv, &z__[irowv + (icolz + i__)
1314 sscal_(&nrv, &r__1, &z__[irowv + (icolz + i__)
1318 if (vutgk == 0.f && idptr < idend && ntgk % 2 > 0) {
1320 /* D=0 in the middle of the active submatrix (one */
1321 /* eigenvalue is equal to zero): save the corresponding */
1322 /* eigenvector for later use (when bottom of the */
1323 /* active submatrix is reached). */
1326 i__3 = irowz + ntgk - 1;
1327 for (i__ = irowz; i__ <= i__3; ++i__) {
1328 z__[i__ + (*n + 1) * z_dim1] = z__[i__ + (*ns
1330 z__[i__ + (*ns + nsl) * z_dim1] = 0.f;
1332 /* Z( IROWZ:IROWZ+NTGK-1,N+1 ) = */
1333 /* $ Z( IROWZ:IROWZ+NTGK-1,NS+NSL ) */
1334 /* Z( IROWZ:IROWZ+NTGK-1,NS+NSL ) = */
1340 nsl = f2cmin(nsl,nru);
1343 /* Absolute values of the eigenvalues of TGK. */
1346 for (i__ = 0; i__ <= i__3; ++i__) {
1347 s[isbeg + i__] = (r__1 = s[isbeg + i__], abs(r__1));
1350 /* Update pointers for TGK, S and Z. */
1362 /* ** NTGK.GT.0 **! */
1363 if (irowz < *n << 1 && wantz) {
1365 for (i__ = 1; i__ <= i__3; ++i__) {
1366 z__[i__ + icolz * z_dim1] = 0.f;
1368 /* Z( 1:IROWZ-1, ICOLZ ) = ZERO */
1371 /* ** IDPTR loop **! */
1372 if (split && wantz) {
1374 /* Bring back eigenvector corresponding */
1375 /* to eigenvalue equal to zero. */
1377 i__2 = idend - ntgk + 1;
1378 for (i__ = idbeg; i__ <= i__2; ++i__) {
1379 z__[i__ + (isbeg - 1) * z_dim1] += z__[i__ + (*n + 1) *
1381 z__[i__ + (*n + 1) * z_dim1] = 0.f;
1383 /* Z( IDBEG:IDEND-NTGK+1,ISBEG-1 ) = */
1384 /* $ Z( IDBEG:IDEND-NTGK+1,ISBEG-1 ) + */
1385 /* $ Z( IDBEG:IDEND-NTGK+1,N+1 ) */
1386 /* Z( IDBEG:IDEND-NTGK+1,N+1 ) = 0 */
1394 /* ** Check for split in E **! */
1397 /* Sort the singular values into decreasing order (insertion sort on */
1398 /* singular values, but only one transposition per singular vector) */
1400 /* ** IEPTR loop **! */
1402 for (i__ = 1; i__ <= i__1; ++i__) {
1405 i__2 = *ns + 1 - i__;
1406 for (j = 2; j <= i__2; ++j) {
1412 if (k != *ns + 1 - i__) {
1413 s[k] = s[*ns + 1 - i__];
1414 s[*ns + 1 - i__] = smin;
1417 sswap_(&i__2, &z__[k * z_dim1 + 1], &c__1, &z__[(*ns + 1 -
1418 i__) * z_dim1 + 1], &c__1);
1423 /* If RANGE=I, check for singular values/vectors to be discarded. */
1429 for (i__ = k + 1; i__ <= i__1; ++i__) {
1432 /* S( K+1:NS ) = ZERO */
1435 for (i__ = 1; i__ <= i__1; ++i__) {
1437 for (j = k + 1; j <= i__2; ++j) {
1438 z__[i__ + j * z_dim1] = 0.f;
1441 /* Z( 1:N*2,K+1:NS ) = ZERO */
1447 /* Reorder Z: U = Z( 1:N,1:NS ), V = Z( N+1:N*2,1:NS ). */
1448 /* If B is a lower diagonal, swap U and V. */
1452 for (i__ = 1; i__ <= i__1; ++i__) {
1454 scopy_(&i__2, &z__[i__ * z_dim1 + 1], &c__1, &work[1], &c__1);
1456 scopy_(n, &work[2], &c__2, &z__[*n + 1 + i__ * z_dim1], &c__1)
1458 scopy_(n, &work[1], &c__2, &z__[i__ * z_dim1 + 1], &c__1);
1460 scopy_(n, &work[2], &c__2, &z__[i__ * z_dim1 + 1], &c__1);
1461 scopy_(n, &work[1], &c__2, &z__[*n + 1 + i__ * z_dim1], &c__1)
1469 /* End of SBDSVDX */