2010-07-16 14:54:53 +02:00
|
|
|
/* slasq3.f -- translated by f2c (version 20061008).
|
|
|
|
You must link the resulting object file with libf2c:
|
|
|
|
on Microsoft Windows system, link with libf2c.lib;
|
|
|
|
on Linux or Unix systems, link with .../path/to/libf2c.a -lm
|
|
|
|
or, if you install libf2c.a in a standard place, with -lf2c -lm
|
|
|
|
-- in that order, at the end of the command line, as in
|
|
|
|
cc *.o -lf2c -lm
|
|
|
|
Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
|
|
|
|
|
|
|
|
http://www.netlib.org/f2c/libf2c.zip
|
|
|
|
*/
|
|
|
|
|
2010-05-11 19:44:00 +02:00
|
|
|
#include "clapack.h"
|
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
|
2010-05-11 19:44:00 +02:00
|
|
|
/* Subroutine */ int slasq3_(integer *i0, integer *n0, real *z__, integer *pp,
|
|
|
|
real *dmin__, real *sigma, real *desig, real *qmax, integer *nfail,
|
2010-07-16 14:54:53 +02:00
|
|
|
integer *iter, integer *ndiv, logical *ieee, integer *ttype, real *
|
|
|
|
dmin1, real *dmin2, real *dn, real *dn1, real *dn2, real *g, real *
|
|
|
|
tau)
|
2010-05-11 19:44:00 +02:00
|
|
|
{
|
|
|
|
/* System generated locals */
|
|
|
|
integer i__1;
|
|
|
|
real r__1, r__2;
|
|
|
|
|
|
|
|
/* Builtin functions */
|
|
|
|
double sqrt(doublereal);
|
|
|
|
|
|
|
|
/* Local variables */
|
|
|
|
real s, t;
|
|
|
|
integer j4, nn;
|
|
|
|
real eps, tol;
|
|
|
|
integer n0in, ipn4;
|
|
|
|
real tol2, temp;
|
|
|
|
extern /* Subroutine */ int slasq4_(integer *, integer *, real *, integer
|
|
|
|
*, integer *, real *, real *, real *, real *, real *, real *,
|
2010-07-16 14:54:53 +02:00
|
|
|
real *, integer *, real *), slasq5_(integer *, integer *, real *,
|
|
|
|
integer *, real *, real *, real *, real *, real *, real *, real *,
|
|
|
|
logical *), slasq6_(integer *, integer *, real *, integer *,
|
|
|
|
real *, real *, real *, real *, real *, real *);
|
2010-05-11 19:44:00 +02:00
|
|
|
extern doublereal slamch_(char *);
|
2010-07-16 14:54:53 +02:00
|
|
|
extern logical sisnan_(real *);
|
|
|
|
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
/* -- LAPACK routine (version 3.2) -- */
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
/* -- Contributed by Osni Marques of the Lawrence Berkeley National -- */
|
|
|
|
/* -- Laboratory and Beresford Parlett of the Univ. of California at -- */
|
|
|
|
/* -- Berkeley -- */
|
|
|
|
/* -- November 2008 -- */
|
|
|
|
|
|
|
|
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
|
|
|
|
/* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
|
2010-05-11 19:44:00 +02:00
|
|
|
|
|
|
|
/* .. Scalar Arguments .. */
|
|
|
|
/* .. */
|
|
|
|
/* .. Array Arguments .. */
|
|
|
|
/* .. */
|
|
|
|
|
|
|
|
/* Purpose */
|
|
|
|
/* ======= */
|
|
|
|
|
|
|
|
/* SLASQ3 checks for deflation, computes a shift (TAU) and calls dqds. */
|
|
|
|
/* In case of failure it changes shifts, and tries again until output */
|
|
|
|
/* is positive. */
|
|
|
|
|
|
|
|
/* Arguments */
|
|
|
|
/* ========= */
|
|
|
|
|
|
|
|
/* I0 (input) INTEGER */
|
|
|
|
/* First index. */
|
|
|
|
|
|
|
|
/* N0 (input) INTEGER */
|
|
|
|
/* Last index. */
|
|
|
|
|
|
|
|
/* Z (input) REAL array, dimension ( 4*N ) */
|
|
|
|
/* Z holds the qd array. */
|
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
/* PP (input/output) INTEGER */
|
2010-05-11 19:44:00 +02:00
|
|
|
/* PP=0 for ping, PP=1 for pong. */
|
2010-07-16 14:54:53 +02:00
|
|
|
/* PP=2 indicates that flipping was applied to the Z array */
|
|
|
|
/* and that the initial tests for deflation should not be */
|
|
|
|
/* performed. */
|
2010-05-11 19:44:00 +02:00
|
|
|
|
|
|
|
/* DMIN (output) REAL */
|
|
|
|
/* Minimum value of d. */
|
|
|
|
|
|
|
|
/* SIGMA (output) REAL */
|
|
|
|
/* Sum of shifts used in current segment. */
|
|
|
|
|
|
|
|
/* DESIG (input/output) REAL */
|
|
|
|
/* Lower order part of SIGMA */
|
|
|
|
|
|
|
|
/* QMAX (input) REAL */
|
|
|
|
/* Maximum value of q. */
|
|
|
|
|
|
|
|
/* NFAIL (output) INTEGER */
|
|
|
|
/* Number of times shift was too big. */
|
|
|
|
|
|
|
|
/* ITER (output) INTEGER */
|
|
|
|
/* Number of iterations. */
|
|
|
|
|
|
|
|
/* NDIV (output) INTEGER */
|
|
|
|
/* Number of divisions. */
|
|
|
|
|
|
|
|
/* IEEE (input) LOGICAL */
|
|
|
|
/* Flag for IEEE or non IEEE arithmetic (passed to SLASQ5). */
|
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
/* TTYPE (input/output) INTEGER */
|
|
|
|
/* Shift type. */
|
|
|
|
|
|
|
|
/* DMIN1, DMIN2, DN, DN1, DN2, G, TAU (input/output) REAL */
|
|
|
|
/* These are passed as arguments in order to save their values */
|
|
|
|
/* between calls to SLASQ3. */
|
|
|
|
|
2010-05-11 19:44:00 +02:00
|
|
|
/* ===================================================================== */
|
|
|
|
|
|
|
|
/* .. Parameters .. */
|
|
|
|
/* .. */
|
|
|
|
/* .. Local Scalars .. */
|
|
|
|
/* .. */
|
|
|
|
/* .. External Subroutines .. */
|
|
|
|
/* .. */
|
|
|
|
/* .. External Function .. */
|
|
|
|
/* .. */
|
|
|
|
/* .. Intrinsic Functions .. */
|
|
|
|
/* .. */
|
2010-07-16 14:54:53 +02:00
|
|
|
/* .. Executable Statements .. */
|
|
|
|
|
2010-05-11 19:44:00 +02:00
|
|
|
/* Parameter adjustments */
|
|
|
|
--z__;
|
|
|
|
|
|
|
|
/* Function Body */
|
|
|
|
n0in = *n0;
|
|
|
|
eps = slamch_("Precision");
|
|
|
|
tol = eps * 100.f;
|
|
|
|
/* Computing 2nd power */
|
|
|
|
r__1 = tol;
|
|
|
|
tol2 = r__1 * r__1;
|
|
|
|
|
|
|
|
/* Check for deflation. */
|
|
|
|
|
|
|
|
L10:
|
|
|
|
|
|
|
|
if (*n0 < *i0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (*n0 == *i0) {
|
|
|
|
goto L20;
|
|
|
|
}
|
|
|
|
nn = (*n0 << 2) + *pp;
|
|
|
|
if (*n0 == *i0 + 1) {
|
|
|
|
goto L40;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check whether E(N0-1) is negligible, 1 eigenvalue. */
|
|
|
|
|
|
|
|
if (z__[nn - 5] > tol2 * (*sigma + z__[nn - 3]) && z__[nn - (*pp << 1) -
|
|
|
|
4] > tol2 * z__[nn - 7]) {
|
|
|
|
goto L30;
|
|
|
|
}
|
|
|
|
|
|
|
|
L20:
|
|
|
|
|
|
|
|
z__[(*n0 << 2) - 3] = z__[(*n0 << 2) + *pp - 3] + *sigma;
|
|
|
|
--(*n0);
|
|
|
|
goto L10;
|
|
|
|
|
|
|
|
/* Check whether E(N0-2) is negligible, 2 eigenvalues. */
|
|
|
|
|
|
|
|
L30:
|
|
|
|
|
|
|
|
if (z__[nn - 9] > tol2 * *sigma && z__[nn - (*pp << 1) - 8] > tol2 * z__[
|
|
|
|
nn - 11]) {
|
|
|
|
goto L50;
|
|
|
|
}
|
|
|
|
|
|
|
|
L40:
|
|
|
|
|
|
|
|
if (z__[nn - 3] > z__[nn - 7]) {
|
|
|
|
s = z__[nn - 3];
|
|
|
|
z__[nn - 3] = z__[nn - 7];
|
|
|
|
z__[nn - 7] = s;
|
|
|
|
}
|
|
|
|
if (z__[nn - 5] > z__[nn - 3] * tol2) {
|
|
|
|
t = (z__[nn - 7] - z__[nn - 3] + z__[nn - 5]) * .5f;
|
|
|
|
s = z__[nn - 3] * (z__[nn - 5] / t);
|
|
|
|
if (s <= t) {
|
|
|
|
s = z__[nn - 3] * (z__[nn - 5] / (t * (sqrt(s / t + 1.f) + 1.f)));
|
|
|
|
} else {
|
|
|
|
s = z__[nn - 3] * (z__[nn - 5] / (t + sqrt(t) * sqrt(t + s)));
|
|
|
|
}
|
|
|
|
t = z__[nn - 7] + (s + z__[nn - 5]);
|
|
|
|
z__[nn - 3] *= z__[nn - 7] / t;
|
|
|
|
z__[nn - 7] = t;
|
|
|
|
}
|
|
|
|
z__[(*n0 << 2) - 7] = z__[nn - 7] + *sigma;
|
|
|
|
z__[(*n0 << 2) - 3] = z__[nn - 3] + *sigma;
|
|
|
|
*n0 += -2;
|
|
|
|
goto L10;
|
|
|
|
|
|
|
|
L50:
|
2010-07-16 14:54:53 +02:00
|
|
|
if (*pp == 2) {
|
|
|
|
*pp = 0;
|
|
|
|
}
|
2010-05-11 19:44:00 +02:00
|
|
|
|
|
|
|
/* Reverse the qd-array, if warranted. */
|
|
|
|
|
|
|
|
if (*dmin__ <= 0.f || *n0 < n0in) {
|
|
|
|
if (z__[(*i0 << 2) + *pp - 3] * 1.5f < z__[(*n0 << 2) + *pp - 3]) {
|
|
|
|
ipn4 = *i0 + *n0 << 2;
|
|
|
|
i__1 = *i0 + *n0 - 1 << 1;
|
|
|
|
for (j4 = *i0 << 2; j4 <= i__1; j4 += 4) {
|
|
|
|
temp = z__[j4 - 3];
|
|
|
|
z__[j4 - 3] = z__[ipn4 - j4 - 3];
|
|
|
|
z__[ipn4 - j4 - 3] = temp;
|
|
|
|
temp = z__[j4 - 2];
|
|
|
|
z__[j4 - 2] = z__[ipn4 - j4 - 2];
|
|
|
|
z__[ipn4 - j4 - 2] = temp;
|
|
|
|
temp = z__[j4 - 1];
|
|
|
|
z__[j4 - 1] = z__[ipn4 - j4 - 5];
|
|
|
|
z__[ipn4 - j4 - 5] = temp;
|
|
|
|
temp = z__[j4];
|
|
|
|
z__[j4] = z__[ipn4 - j4 - 4];
|
|
|
|
z__[ipn4 - j4 - 4] = temp;
|
|
|
|
/* L60: */
|
|
|
|
}
|
|
|
|
if (*n0 - *i0 <= 4) {
|
|
|
|
z__[(*n0 << 2) + *pp - 1] = z__[(*i0 << 2) + *pp - 1];
|
|
|
|
z__[(*n0 << 2) - *pp] = z__[(*i0 << 2) - *pp];
|
|
|
|
}
|
|
|
|
/* Computing MIN */
|
2010-07-16 14:54:53 +02:00
|
|
|
r__1 = *dmin2, r__2 = z__[(*n0 << 2) + *pp - 1];
|
|
|
|
*dmin2 = dmin(r__1,r__2);
|
2010-05-11 19:44:00 +02:00
|
|
|
/* Computing MIN */
|
|
|
|
r__1 = z__[(*n0 << 2) + *pp - 1], r__2 = z__[(*i0 << 2) + *pp - 1]
|
|
|
|
, r__1 = min(r__1,r__2), r__2 = z__[(*i0 << 2) + *pp + 3];
|
|
|
|
z__[(*n0 << 2) + *pp - 1] = dmin(r__1,r__2);
|
|
|
|
/* Computing MIN */
|
|
|
|
r__1 = z__[(*n0 << 2) - *pp], r__2 = z__[(*i0 << 2) - *pp], r__1 =
|
|
|
|
min(r__1,r__2), r__2 = z__[(*i0 << 2) - *pp + 4];
|
|
|
|
z__[(*n0 << 2) - *pp] = dmin(r__1,r__2);
|
|
|
|
/* Computing MAX */
|
|
|
|
r__1 = *qmax, r__2 = z__[(*i0 << 2) + *pp - 3], r__1 = max(r__1,
|
|
|
|
r__2), r__2 = z__[(*i0 << 2) + *pp + 1];
|
|
|
|
*qmax = dmax(r__1,r__2);
|
|
|
|
*dmin__ = -0.f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
/* Choose a shift. */
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
slasq4_(i0, n0, &z__[1], pp, &n0in, dmin__, dmin1, dmin2, dn, dn1, dn2,
|
|
|
|
tau, ttype, g);
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
/* Call dqds until DMIN > 0. */
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
L70:
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
slasq5_(i0, n0, &z__[1], pp, tau, dmin__, dmin1, dmin2, dn, dn1, dn2,
|
|
|
|
ieee);
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
*ndiv += *n0 - *i0 + 2;
|
|
|
|
++(*iter);
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
/* Check status. */
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
if (*dmin__ >= 0.f && *dmin1 > 0.f) {
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
/* Success. */
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
goto L90;
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
} else if (*dmin__ < 0.f && *dmin1 > 0.f && z__[(*n0 - 1 << 2) - *pp] <
|
|
|
|
tol * (*sigma + *dn1) && dabs(*dn) < tol * *sigma) {
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
/* Convergence hidden by negative DN. */
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
z__[(*n0 - 1 << 2) - *pp + 2] = 0.f;
|
|
|
|
*dmin__ = 0.f;
|
|
|
|
goto L90;
|
|
|
|
} else if (*dmin__ < 0.f) {
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
/* TAU too big. Select new TAU and try again. */
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
++(*nfail);
|
|
|
|
if (*ttype < -22) {
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
/* Failed twice. Play it safe. */
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
*tau = 0.f;
|
|
|
|
} else if (*dmin1 > 0.f) {
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
/* Late failure. Gives excellent shift. */
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
*tau = (*tau + *dmin__) * (1.f - eps * 2.f);
|
|
|
|
*ttype += -11;
|
|
|
|
} else {
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
/* Early failure. Divide by 4. */
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
*tau *= .25f;
|
|
|
|
*ttype += -12;
|
|
|
|
}
|
|
|
|
goto L70;
|
|
|
|
} else if (sisnan_(dmin__)) {
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
/* NaN. */
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
if (*tau == 0.f) {
|
2010-05-11 19:44:00 +02:00
|
|
|
goto L80;
|
|
|
|
} else {
|
2010-07-16 14:54:53 +02:00
|
|
|
*tau = 0.f;
|
|
|
|
goto L70;
|
|
|
|
}
|
|
|
|
} else {
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
/* Possible underflow. Play it safe. */
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
goto L80;
|
2010-05-11 19:44:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Risk of underflow. */
|
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
L80:
|
|
|
|
slasq6_(i0, n0, &z__[1], pp, dmin__, dmin1, dmin2, dn, dn1, dn2);
|
2010-05-11 19:44:00 +02:00
|
|
|
*ndiv += *n0 - *i0 + 2;
|
|
|
|
++(*iter);
|
2010-07-16 14:54:53 +02:00
|
|
|
*tau = 0.f;
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2010-07-16 14:54:53 +02:00
|
|
|
L90:
|
|
|
|
if (*tau < *sigma) {
|
|
|
|
*desig += *tau;
|
2010-05-11 19:44:00 +02:00
|
|
|
t = *sigma + *desig;
|
|
|
|
*desig -= t - *sigma;
|
|
|
|
} else {
|
2010-07-16 14:54:53 +02:00
|
|
|
t = *sigma + *tau;
|
|
|
|
*desig = *sigma - (t - *tau) + *desig;
|
2010-05-11 19:44:00 +02:00
|
|
|
}
|
|
|
|
*sigma = t;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* End of SLASQ3 */
|
|
|
|
|
|
|
|
} /* slasq3_ */
|