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_b10 = 1.;
516 static doublereal c_b14 = -.125;
517 static integer c__1 = 1;
518 static doublereal c_b19 = 0.;
519 static integer c__2 = 2;
521 /* > \brief \b DBDSVDX */
523 /* =========== DOCUMENTATION =========== */
525 /* Online html documentation available at */
526 /* http://www.netlib.org/lapack/explore-html/ */
529 /* > Download DBDSVDX + dependencies */
530 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dbdsvdx
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dbdsvdx
536 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dbdsvdx
544 /* SUBROUTINE DBDSVDX( 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 */
549 /* DOUBLE PRECISION VL, VU */
550 /* INTEGER IWORK( * ) */
551 /* DOUBLE PRECISION D( * ), E( * ), S( * ), WORK( * ), */
554 /* > \par Purpose: */
559 /* > DBDSVDX 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 ], DBDSVDX 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 DGESVD/DGESDD) or b) compute s,v and reorder */
584 /* > the values (and corresponding vectors). DBDSVDX implements a) by */
585 /* > calling DSTEVX (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 DOUBLE PRECISION array, dimension (N) */
627 /* > The n diagonal elements of the bidiagonal matrix B. */
632 /* > E is DOUBLE PRECISION 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 */
639 /* > VL is DOUBLE PRECISION */
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 */
647 /* > VU is DOUBLE PRECISION */
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 DOUBLE PRECISION array, dimension (N) */
681 /* > The first NS elements contain the selected singular values in */
682 /* > ascending order. */
685 /* > \param[out] Z */
687 /* > Z is DOUBLE PRECISION 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 DOUBLE PRECISION 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 DSTEVX. The indices of the eigenvectors */
727 /* > (as returned by DSTEVX) 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 doubleOTHEReigen */
744 /* ===================================================================== */
745 /* Subroutine */ int dbdsvdx_(char *uplo, char *jobz, char *range, integer *n,
746 doublereal *d__, doublereal *e, doublereal *vl, doublereal *vu,
747 integer *il, integer *iu, integer *ns, doublereal *s, doublereal *z__,
748 integer *ldz, doublereal *work, integer *iwork, integer *info)
750 /* System generated locals */
751 integer z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
752 doublereal d__1, d__2, d__3, d__4;
754 /* Local variables */
756 extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
759 doublereal smin, smax, nrmu, nrmv;
760 extern doublereal dnrm2_(integer *, doublereal *, integer *);
762 integer i__, idbeg, j, k;
765 extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
768 extern logical lsame_(char *, char *);
769 integer idtgk, ietgk, iltgk, itemp;
770 extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
771 doublereal *, integer *);
776 integer ieptr, iutgk;
777 extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *,
778 integer *, doublereal *, integer *);
781 extern /* Subroutine */ int dswap_(integer *, doublereal *, integer *,
782 doublereal *, integer *);
784 logical split, valsv;
786 doublereal ortol, vutgk;
789 integer irowu, irowv, irowz;
790 extern doublereal dlamch_(char *);
793 extern integer idamax_(integer *, doublereal *, integer *);
794 extern /* Subroutine */ int dlaset_(char *, integer *, integer *,
795 doublereal *, doublereal *, doublereal *, integer *),
796 xerbla_(char *, integer *, ftnlen);
797 doublereal abstol, thresh;
799 extern /* Subroutine */ int dstevx_(char *, char *, integer *, doublereal
800 *, doublereal *, doublereal *, doublereal *, integer *, integer *,
801 doublereal *, integer *, doublereal *, doublereal *, integer *,
802 doublereal *, integer *, integer *, integer *),
810 /* -- LAPACK driver routine (version 3.8.0) -- */
811 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
812 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
816 /* ===================================================================== */
819 /* Test the input parameters. */
821 /* Parameter adjustments */
826 z_offset = 1 + z_dim1 * 1;
832 allsv = lsame_(range, "A");
833 valsv = lsame_(range, "V");
834 indsv = lsame_(range, "I");
835 wantz = lsame_(jobz, "V");
836 lower = lsame_(uplo, "L");
839 if (! lsame_(uplo, "U") && ! lower) {
841 } else if (! (wantz || lsame_(jobz, "N"))) {
843 } else if (! (allsv || valsv || indsv)) {
851 } else if (*vu <= *vl) {
855 if (*il < 1 || *il > f2cmax(1,*n)) {
857 } else if (*iu < f2cmin(*n,*il) || *iu > *n) {
863 if (*ldz < 1 || wantz && *ldz < *n << 1) {
870 xerbla_("DBDSVDX", &i__1, (ftnlen)7);
874 /* Quick return if possible (N.LE.1) */
882 if (allsv || indsv) {
886 if (*vl < abs(d__[1]) && *vu >= abs(d__[1])) {
892 z__[z_dim1 + 1] = d_sign(&c_b10, &d__[1]);
893 z__[z_dim1 + 2] = 1.;
898 abstol = dlamch_("Safe Minimum") * 2;
899 ulp = dlamch_("Precision");
900 eps = dlamch_("Epsilon");
904 /* Criterion for splitting is taken from DBDSQR when singular */
905 /* values are computed to relative accuracy TOL. (See J. Demmel and */
906 /* W. Kahan, Accurate singular values of bidiagonal matrices, SIAM */
907 /* J. Sci. and Stat. Comput., 11:873–912, 1990.) */
911 d__3 = 100., d__4 = pow_dd(&eps, &c_b14);
912 d__1 = 10., d__2 = f2cmin(d__3,d__4);
913 tol = f2cmax(d__1,d__2) * eps;
915 /* Compute approximate maximum, minimum singular values. */
917 i__ = idamax_(n, &d__[1], &c__1);
918 smax = (d__1 = d__[i__], abs(d__1));
920 i__ = idamax_(&i__1, &e[1], &c__1);
922 d__2 = smax, d__3 = (d__1 = e[i__], abs(d__1));
923 smax = f2cmax(d__2,d__3);
925 /* Compute threshold for neglecting D's and E's. */
931 for (i__ = 2; i__ <= i__1; ++i__) {
932 mu = (d__2 = d__[i__], abs(d__2)) * (mu / (mu + (d__1 = e[i__ - 1]
934 smin = f2cmin(smin,mu);
940 smin /= sqrt((doublereal) (*n));
943 /* Check for zeros in D and E (splits), i.e. submatrices. */
946 for (i__ = 1; i__ <= i__1; ++i__) {
947 if ((d__1 = d__[i__], abs(d__1)) <= thresh) {
950 if ((d__1 = e[i__], abs(d__1)) <= thresh) {
954 if ((d__1 = d__[*n], abs(d__1)) <= thresh) {
958 /* Pointers for arrays used by DSTEVX. */
961 ietgk = idtgk + (*n << 1);
962 itemp = ietgk + (*n << 1);
964 iiwork = iifail + (*n << 1);
966 /* Set RNGVX, which corresponds to RANGE for DSTEVX in TGK mode. */
967 /* VL,VU or IL,IU are redefined to conform to implementation a) */
968 /* described in the leading comments. */
977 /* All singular values will be found. We aim at -s (see */
978 /* leading comments) with RNGVX = 'I'. IL and IU are set */
979 /* later (as ILTGK and IUTGK) according to the dimension */
980 /* of the active submatrix. */
982 *(unsigned char *)rngvx = 'I';
986 dlaset_("F", &i__1, &i__2, &c_b19, &c_b19, &z__[z_offset], ldz);
990 /* Find singular values in a half-open interval. We aim */
991 /* at -s (see leading comments) and we swap VL and VU */
992 /* (as VUTGK and VLTGK), changing their signs. */
994 *(unsigned char *)rngvx = 'V';
997 i__1 = idtgk + (*n << 1) - 1;
998 for (i__ = idtgk; i__ <= i__1; ++i__) {
1001 /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
1002 dcopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
1004 dcopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
1006 dstevx_("N", "V", &i__1, &work[idtgk], &work[ietgk], &vltgk, &vutgk, &
1007 iltgk, &iltgk, &abstol, ns, &s[1], &z__[z_offset], ldz, &work[
1008 itemp], &iwork[iiwork], &iwork[iifail], info);
1014 dlaset_("F", &i__1, ns, &c_b19, &c_b19, &z__[z_offset], ldz);
1019 /* Find the IL-th through the IU-th singular values. We aim */
1020 /* at -s (see leading comments) and indices are mapped into */
1021 /* values, therefore mimicking DSTEBZ, where */
1023 /* GL = GL - FUDGE*TNORM*ULP*N - FUDGE*TWO*PIVMIN */
1024 /* GU = GU + FUDGE*TNORM*ULP*N + FUDGE*PIVMIN */
1028 *(unsigned char *)rngvx = 'V';
1029 i__1 = idtgk + (*n << 1) - 1;
1030 for (i__ = idtgk; i__ <= i__1; ++i__) {
1033 /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
1034 dcopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
1036 dcopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
1038 dstevx_("N", "I", &i__1, &work[idtgk], &work[ietgk], &vltgk, &vltgk, &
1039 iltgk, &iltgk, &abstol, ns, &s[1], &z__[z_offset], ldz, &work[
1040 itemp], &iwork[iiwork], &iwork[iifail], info);
1041 vltgk = s[1] - smax * 2. * ulp * *n;
1042 i__1 = idtgk + (*n << 1) - 1;
1043 for (i__ = idtgk; i__ <= i__1; ++i__) {
1046 /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
1047 dcopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
1049 dcopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
1051 dstevx_("N", "I", &i__1, &work[idtgk], &work[ietgk], &vutgk, &vutgk, &
1052 iutgk, &iutgk, &abstol, ns, &s[1], &z__[z_offset], ldz, &work[
1053 itemp], &iwork[iiwork], &iwork[iifail], info);
1054 vutgk = s[1] + smax * 2. * ulp * *n;
1055 vutgk = f2cmin(vutgk,0.);
1057 /* If VLTGK=VUTGK, DSTEVX returns an error message, */
1058 /* so if needed we change VUTGK slightly. */
1060 if (vltgk == vutgk) {
1066 i__2 = *iu - *il + 1;
1067 dlaset_("F", &i__1, &i__2, &c_b19, &c_b19, &z__[z_offset], ldz);
1071 /* Initialize variables and pointers for S, Z, and WORK. */
1073 /* NRU, NRV: number of rows in U and V for the active submatrix */
1074 /* IDBEG, ISBEG: offsets for the entries of D and S */
1075 /* IROWZ, ICOLZ: offsets for the rows and columns of Z */
1076 /* IROWU, IROWV: offsets for the rows of U and V */
1090 /* Form the tridiagonal TGK matrix. */
1093 for (i__ = 1; i__ <= i__1; ++i__) {
1096 /* S( 1:N ) = ZERO */
1097 work[ietgk + (*n << 1) - 1] = 0.;
1098 i__1 = idtgk + (*n << 1) - 1;
1099 for (i__ = idtgk; i__ <= i__1; ++i__) {
1102 /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
1103 dcopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
1105 dcopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
1108 /* Check for splits in two levels, outer level */
1109 /* in E and inner level in D. */
1112 for (ieptr = 2; ieptr <= i__1; ieptr += 2) {
1113 if (work[ietgk + ieptr - 1] == 0.) {
1115 /* Split in E (this piece of B is square) or bottom */
1116 /* of the (input bidiagonal) matrix. */
1121 for (idptr = idbeg; idptr <= i__2; idptr += 2) {
1122 if (work[ietgk + idptr - 1] == 0.) {
1124 /* Split in D (rectangular submatrix). Set the number */
1125 /* of rows in U and V (NRU and NRV) accordingly. */
1127 if (idptr == idbeg) {
1129 /* D=0 at the top. */
1132 if (idbeg == idend) {
1136 } else if (idptr == idend) {
1138 /* D=0 at the bottom. */
1141 nru = (idend - isplt) / 2 + 1;
1143 if (isplt != idbeg) {
1147 if (isplt == idbeg) {
1149 /* Split: top rectangular submatrix. */
1151 nru = (idptr - idbeg) / 2;
1155 /* Split: middle square submatrix. */
1157 nru = (idptr - isplt) / 2 + 1;
1161 } else if (idptr == idend) {
1163 /* Last entry of D in the active submatrix. */
1165 if (isplt == idbeg) {
1167 /* No split (trivial case). */
1169 nru = (idend - idbeg) / 2 + 1;
1173 /* Split: bottom rectangular submatrix. */
1175 nrv = (idend - isplt) / 2 + 1;
1184 /* Compute eigenvalues/vectors of the active */
1185 /* submatrix according to RANGE: */
1186 /* if RANGE='A' (ALLSV) then RNGVX = 'I' */
1187 /* if RANGE='V' (VALSV) then RNGVX = 'V' */
1188 /* if RANGE='I' (INDSV) then RNGVX = 'V' */
1192 if (allsv || vutgk == 0.) {
1193 if (sveq0 || smin < eps || ntgk % 2 > 0) {
1194 /* Special case: eigenvalue equal to zero or very */
1195 /* small, additional eigenvector is needed. */
1200 /* Workspace needed by DSTEVX: */
1201 /* WORK( ITEMP: ): 2*5*NTGK */
1202 /* IWORK( 1: ): 2*6*NTGK */
1204 dstevx_(jobz, rngvx, &ntgk, &work[idtgk + isplt - 1], &
1205 work[ietgk + isplt - 1], &vltgk, &vutgk, &iltgk, &
1206 iutgk, &abstol, &nsl, &s[isbeg], &z__[irowz +
1207 icolz * z_dim1], ldz, &work[itemp], &iwork[iiwork]
1208 , &iwork[iifail], info);
1210 /* Exit with the error code from DSTEVX. */
1213 emin = (d__1 = s[isbeg], abs(d__1));
1214 i__3 = isbeg + nsl - 1;
1215 for (i__ = isbeg; i__ <= i__3; ++i__) {
1216 if ((d__1 = s[i__], abs(d__1)) > emin) {
1220 /* EMIN = ABS( MAXVAL( S( ISBEG:ISBEG+NSL-1 ) ) ) */
1222 if (nsl > 0 && wantz) {
1224 /* Normalize u=Z([2,4,...],:) and v=Z([1,3,...],:), */
1225 /* changing the sign of v as discussed in the leading */
1226 /* comments. The norms of u and v may be (slightly) */
1227 /* different from 1/sqrt(2) if the corresponding */
1228 /* eigenvalues are very small or too close. We check */
1229 /* those norms and, if needed, reorthogonalize the */
1232 if (nsl > 1 && vutgk == 0. && ntgk % 2 == 0 && emin ==
1235 /* D=0 at the top or bottom of the active submatrix: */
1236 /* one eigenvalue is equal to zero; concatenate the */
1237 /* eigenvectors corresponding to the two smallest */
1240 i__3 = irowz + ntgk - 1;
1241 for (i__ = irowz; i__ <= i__3; ++i__) {
1242 z__[i__ + (icolz + nsl - 2) * z_dim1] += z__[
1243 i__ + (icolz + nsl - 1) * z_dim1];
1244 z__[i__ + (icolz + nsl - 1) * z_dim1] = 0.;
1246 /* Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-2 ) = */
1247 /* $ Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-2 ) + */
1248 /* $ Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-1 ) */
1249 /* Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-1 ) = */
1251 /* IF( IUTGK*2.GT.NTGK ) THEN */
1252 /* Eigenvalue equal to zero or very small. */
1258 i__4 = nsl - 1, i__5 = nru - 1;
1259 i__3 = f2cmin(i__4,i__5);
1260 for (i__ = 0; i__ <= i__3; ++i__) {
1261 nrmu = dnrm2_(&nru, &z__[irowu + (icolz + i__) *
1264 *info = (*n << 1) + 1;
1268 dscal_(&nru, &d__1, &z__[irowu + (icolz + i__) *
1270 if (nrmu != 1. && (d__1 = nrmu - ortol, abs(d__1))
1273 for (j = 0; j <= i__4; ++j) {
1274 zjtji = -ddot_(&nru, &z__[irowu + (icolz
1275 + j) * z_dim1], &c__2, &z__[irowu
1276 + (icolz + i__) * z_dim1], &c__2);
1277 daxpy_(&nru, &zjtji, &z__[irowu + (icolz
1278 + j) * z_dim1], &c__2, &z__[irowu
1279 + (icolz + i__) * z_dim1], &c__2);
1281 nrmu = dnrm2_(&nru, &z__[irowu + (icolz + i__)
1284 dscal_(&nru, &d__1, &z__[irowu + (icolz + i__)
1289 i__4 = nsl - 1, i__5 = nrv - 1;
1290 i__3 = f2cmin(i__4,i__5);
1291 for (i__ = 0; i__ <= i__3; ++i__) {
1292 nrmv = dnrm2_(&nrv, &z__[irowv + (icolz + i__) *
1295 *info = (*n << 1) + 1;
1299 dscal_(&nrv, &d__1, &z__[irowv + (icolz + i__) *
1301 if (nrmv != 1. && (d__1 = nrmv - ortol, abs(d__1))
1304 for (j = 0; j <= i__4; ++j) {
1305 zjtji = -ddot_(&nrv, &z__[irowv + (icolz
1306 + j) * z_dim1], &c__2, &z__[irowv
1307 + (icolz + i__) * z_dim1], &c__2);
1308 daxpy_(&nru, &zjtji, &z__[irowv + (icolz
1309 + j) * z_dim1], &c__2, &z__[irowv
1310 + (icolz + i__) * z_dim1], &c__2);
1312 nrmv = dnrm2_(&nrv, &z__[irowv + (icolz + i__)
1315 dscal_(&nrv, &d__1, &z__[irowv + (icolz + i__)
1319 if (vutgk == 0. && idptr < idend && ntgk % 2 > 0) {
1321 /* D=0 in the middle of the active submatrix (one */
1322 /* eigenvalue is equal to zero): save the corresponding */
1323 /* eigenvector for later use (when bottom of the */
1324 /* active submatrix is reached). */
1327 i__3 = irowz + ntgk - 1;
1328 for (i__ = irowz; i__ <= i__3; ++i__) {
1329 z__[i__ + (*n + 1) * z_dim1] = z__[i__ + (*ns
1331 z__[i__ + (*ns + nsl) * z_dim1] = 0.;
1333 /* Z( IROWZ:IROWZ+NTGK-1,N+1 ) = */
1334 /* $ Z( IROWZ:IROWZ+NTGK-1,NS+NSL ) */
1335 /* Z( IROWZ:IROWZ+NTGK-1,NS+NSL ) = */
1341 nsl = f2cmin(nsl,nru);
1344 /* Absolute values of the eigenvalues of TGK. */
1347 for (i__ = 0; i__ <= i__3; ++i__) {
1348 s[isbeg + i__] = (d__1 = s[isbeg + i__], abs(d__1));
1351 /* Update pointers for TGK, S and Z. */
1363 /* ** NTGK.GT.0 **! */
1364 if (irowz < *n << 1 && wantz) {
1366 for (i__ = 1; i__ <= i__3; ++i__) {
1367 z__[i__ + icolz * z_dim1] = 0.;
1369 /* Z( 1:IROWZ-1, ICOLZ ) = ZERO */
1372 /* ** IDPTR loop **! */
1373 if (split && wantz) {
1375 /* Bring back eigenvector corresponding */
1376 /* to eigenvalue equal to zero. */
1378 i__2 = idend - ntgk + 1;
1379 for (i__ = idbeg; i__ <= i__2; ++i__) {
1380 z__[i__ + (isbeg - 1) * z_dim1] += z__[i__ + (*n + 1) *
1382 z__[i__ + (*n + 1) * z_dim1] = 0.;
1384 /* Z( IDBEG:IDEND-NTGK+1,ISBEG-1 ) = */
1385 /* $ Z( IDBEG:IDEND-NTGK+1,ISBEG-1 ) + */
1386 /* $ Z( IDBEG:IDEND-NTGK+1,N+1 ) */
1387 /* Z( IDBEG:IDEND-NTGK+1,N+1 ) = 0 */
1395 /* ** Check for split in E **! */
1398 /* Sort the singular values into decreasing order (insertion sort on */
1399 /* singular values, but only one transposition per singular vector) */
1401 /* ** IEPTR loop **! */
1403 for (i__ = 1; i__ <= i__1; ++i__) {
1406 i__2 = *ns + 1 - i__;
1407 for (j = 2; j <= i__2; ++j) {
1413 if (k != *ns + 1 - i__) {
1414 s[k] = s[*ns + 1 - i__];
1415 s[*ns + 1 - i__] = smin;
1418 dswap_(&i__2, &z__[k * z_dim1 + 1], &c__1, &z__[(*ns + 1 -
1419 i__) * z_dim1 + 1], &c__1);
1424 /* If RANGE=I, check for singular values/vectors to be discarded. */
1430 for (i__ = k + 1; i__ <= i__1; ++i__) {
1433 /* S( K+1:NS ) = ZERO */
1436 for (i__ = 1; i__ <= i__1; ++i__) {
1438 for (j = k + 1; j <= i__2; ++j) {
1439 z__[i__ + j * z_dim1] = 0.;
1442 /* Z( 1:N*2,K+1:NS ) = ZERO */
1448 /* Reorder Z: U = Z( 1:N,1:NS ), V = Z( N+1:N*2,1:NS ). */
1449 /* If B is a lower diagonal, swap U and V. */
1453 for (i__ = 1; i__ <= i__1; ++i__) {
1455 dcopy_(&i__2, &z__[i__ * z_dim1 + 1], &c__1, &work[1], &c__1);
1457 dcopy_(n, &work[2], &c__2, &z__[*n + 1 + i__ * z_dim1], &c__1)
1459 dcopy_(n, &work[1], &c__2, &z__[i__ * z_dim1 + 1], &c__1);
1461 dcopy_(n, &work[2], &c__2, &z__[i__ * z_dim1 + 1], &c__1);
1462 dcopy_(n, &work[1], &c__2, &z__[*n + 1 + i__ * z_dim1], &c__1)
1470 /* End of DBDSVDX */