slacon.c
Go to the documentation of this file.
00001 /* slacon.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static integer c__1 = 1;
00019 static real c_b11 = 1.f;
00020 
00021 /* Subroutine */ int slacon_(integer *n, real *v, real *x, integer *isgn, 
00022         real *est, integer *kase)
00023 {
00024     /* System generated locals */
00025     integer i__1;
00026     real r__1;
00027 
00028     /* Builtin functions */
00029     double r_sign(real *, real *);
00030     integer i_nint(real *);
00031 
00032     /* Local variables */
00033     static integer i__, j, iter;
00034     static real temp;
00035     static integer jump, jlast;
00036     extern doublereal sasum_(integer *, real *, integer *);
00037     extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 
00038             integer *);
00039     extern integer isamax_(integer *, real *, integer *);
00040     static real altsgn, estold;
00041 
00042 
00043 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00044 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00045 /*     November 2006 */
00046 
00047 /*     .. Scalar Arguments .. */
00048 /*     .. */
00049 /*     .. Array Arguments .. */
00050 /*     .. */
00051 
00052 /*  Purpose */
00053 /*  ======= */
00054 
00055 /*  SLACON estimates the 1-norm of a square, real matrix A. */
00056 /*  Reverse communication is used for evaluating matrix-vector products. */
00057 
00058 /*  Arguments */
00059 /*  ========= */
00060 
00061 /*  N      (input) INTEGER */
00062 /*         The order of the matrix.  N >= 1. */
00063 
00064 /*  V      (workspace) REAL array, dimension (N) */
00065 /*         On the final return, V = A*W,  where  EST = norm(V)/norm(W) */
00066 /*         (W is not returned). */
00067 
00068 /*  X      (input/output) REAL array, dimension (N) */
00069 /*         On an intermediate return, X should be overwritten by */
00070 /*               A * X,   if KASE=1, */
00071 /*               A' * X,  if KASE=2, */
00072 /*         and SLACON must be re-called with all the other parameters */
00073 /*         unchanged. */
00074 
00075 /*  ISGN   (workspace) INTEGER array, dimension (N) */
00076 
00077 /*  EST    (input/output) REAL */
00078 /*         On entry with KASE = 1 or 2 and JUMP = 3, EST should be */
00079 /*         unchanged from the previous call to SLACON. */
00080 /*         On exit, EST is an estimate (a lower bound) for norm(A). */
00081 
00082 /*  KASE   (input/output) INTEGER */
00083 /*         On the initial call to SLACON, KASE should be 0. */
00084 /*         On an intermediate return, KASE will be 1 or 2, indicating */
00085 /*         whether X should be overwritten by A * X  or A' * X. */
00086 /*         On the final return from SLACON, KASE will again be 0. */
00087 
00088 /*  Further Details */
00089 /*  ======= ======= */
00090 
00091 /*  Contributed by Nick Higham, University of Manchester. */
00092 /*  Originally named SONEST, dated March 16, 1988. */
00093 
00094 /*  Reference: N.J. Higham, "FORTRAN codes for estimating the one-norm of */
00095 /*  a real or complex matrix, with applications to condition estimation", */
00096 /*  ACM Trans. Math. Soft., vol. 14, no. 4, pp. 381-396, December 1988. */
00097 
00098 /*  ===================================================================== */
00099 
00100 /*     .. Parameters .. */
00101 /*     .. */
00102 /*     .. Local Scalars .. */
00103 /*     .. */
00104 /*     .. External Functions .. */
00105 /*     .. */
00106 /*     .. External Subroutines .. */
00107 /*     .. */
00108 /*     .. Intrinsic Functions .. */
00109 /*     .. */
00110 /*     .. Save statement .. */
00111 /*     .. */
00112 /*     .. Executable Statements .. */
00113 
00114     /* Parameter adjustments */
00115     --isgn;
00116     --x;
00117     --v;
00118 
00119     /* Function Body */
00120     if (*kase == 0) {
00121         i__1 = *n;
00122         for (i__ = 1; i__ <= i__1; ++i__) {
00123             x[i__] = 1.f / (real) (*n);
00124 /* L10: */
00125         }
00126         *kase = 1;
00127         jump = 1;
00128         return 0;
00129     }
00130 
00131     switch (jump) {
00132         case 1:  goto L20;
00133         case 2:  goto L40;
00134         case 3:  goto L70;
00135         case 4:  goto L110;
00136         case 5:  goto L140;
00137     }
00138 
00139 /*     ................ ENTRY   (JUMP = 1) */
00140 /*     FIRST ITERATION.  X HAS BEEN OVERWRITTEN BY A*X. */
00141 
00142 L20:
00143     if (*n == 1) {
00144         v[1] = x[1];
00145         *est = dabs(v[1]);
00146 /*        ... QUIT */
00147         goto L150;
00148     }
00149     *est = sasum_(n, &x[1], &c__1);
00150 
00151     i__1 = *n;
00152     for (i__ = 1; i__ <= i__1; ++i__) {
00153         x[i__] = r_sign(&c_b11, &x[i__]);
00154         isgn[i__] = i_nint(&x[i__]);
00155 /* L30: */
00156     }
00157     *kase = 2;
00158     jump = 2;
00159     return 0;
00160 
00161 /*     ................ ENTRY   (JUMP = 2) */
00162 /*     FIRST ITERATION.  X HAS BEEN OVERWRITTEN BY TRANSPOSE(A)*X. */
00163 
00164 L40:
00165     j = isamax_(n, &x[1], &c__1);
00166     iter = 2;
00167 
00168 /*     MAIN LOOP - ITERATIONS 2,3,...,ITMAX. */
00169 
00170 L50:
00171     i__1 = *n;
00172     for (i__ = 1; i__ <= i__1; ++i__) {
00173         x[i__] = 0.f;
00174 /* L60: */
00175     }
00176     x[j] = 1.f;
00177     *kase = 1;
00178     jump = 3;
00179     return 0;
00180 
00181 /*     ................ ENTRY   (JUMP = 3) */
00182 /*     X HAS BEEN OVERWRITTEN BY A*X. */
00183 
00184 L70:
00185     scopy_(n, &x[1], &c__1, &v[1], &c__1);
00186     estold = *est;
00187     *est = sasum_(n, &v[1], &c__1);
00188     i__1 = *n;
00189     for (i__ = 1; i__ <= i__1; ++i__) {
00190         r__1 = r_sign(&c_b11, &x[i__]);
00191         if (i_nint(&r__1) != isgn[i__]) {
00192             goto L90;
00193         }
00194 /* L80: */
00195     }
00196 /*     REPEATED SIGN VECTOR DETECTED, HENCE ALGORITHM HAS CONVERGED. */
00197     goto L120;
00198 
00199 L90:
00200 /*     TEST FOR CYCLING. */
00201     if (*est <= estold) {
00202         goto L120;
00203     }
00204 
00205     i__1 = *n;
00206     for (i__ = 1; i__ <= i__1; ++i__) {
00207         x[i__] = r_sign(&c_b11, &x[i__]);
00208         isgn[i__] = i_nint(&x[i__]);
00209 /* L100: */
00210     }
00211     *kase = 2;
00212     jump = 4;
00213     return 0;
00214 
00215 /*     ................ ENTRY   (JUMP = 4) */
00216 /*     X HAS BEEN OVERWRITTEN BY TRANSPOSE(A)*X. */
00217 
00218 L110:
00219     jlast = j;
00220     j = isamax_(n, &x[1], &c__1);
00221     if (x[jlast] != (r__1 = x[j], dabs(r__1)) && iter < 5) {
00222         ++iter;
00223         goto L50;
00224     }
00225 
00226 /*     ITERATION COMPLETE.  FINAL STAGE. */
00227 
00228 L120:
00229     altsgn = 1.f;
00230     i__1 = *n;
00231     for (i__ = 1; i__ <= i__1; ++i__) {
00232         x[i__] = altsgn * ((real) (i__ - 1) / (real) (*n - 1) + 1.f);
00233         altsgn = -altsgn;
00234 /* L130: */
00235     }
00236     *kase = 1;
00237     jump = 5;
00238     return 0;
00239 
00240 /*     ................ ENTRY   (JUMP = 5) */
00241 /*     X HAS BEEN OVERWRITTEN BY A*X. */
00242 
00243 L140:
00244     temp = sasum_(n, &x[1], &c__1) / (real) (*n * 3) * 2.f;
00245     if (temp > *est) {
00246         scopy_(n, &x[1], &c__1, &v[1], &c__1);
00247         *est = temp;
00248     }
00249 
00250 L150:
00251     *kase = 0;
00252     return 0;
00253 
00254 /*     End of SLACON */
00255 
00256 } /* slacon_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:09