slacn2.c
Go to the documentation of this file.
00001 /* slacn2.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 slacn2_(integer *n, real *v, real *x, integer *isgn, 
00022         real *est, integer *kase, integer *isave)
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     integer i__;
00034     real temp;
00035     integer 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     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 /*  SLACN2 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 SLACN2 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 ISAVE(1) = 3, EST should be */
00079 /*         unchanged from the previous call to SLACN2. */
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 SLACN2, 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 SLACN2, KASE will again be 0. */
00087 
00088 /*  ISAVE  (input/output) INTEGER array, dimension (3) */
00089 /*         ISAVE is used to save variables between calls to SLACN2 */
00090 
00091 /*  Further Details */
00092 /*  ======= ======= */
00093 
00094 /*  Contributed by Nick Higham, University of Manchester. */
00095 /*  Originally named SONEST, dated March 16, 1988. */
00096 
00097 /*  Reference: N.J. Higham, "FORTRAN codes for estimating the one-norm of */
00098 /*  a real or complex matrix, with applications to condition estimation", */
00099 /*  ACM Trans. Math. Soft., vol. 14, no. 4, pp. 381-396, December 1988. */
00100 
00101 /*  This is a thread safe version of SLACON, which uses the array ISAVE */
00102 /*  in place of a SAVE statement, as follows: */
00103 
00104 /*     SLACON     SLACN2 */
00105 /*      JUMP     ISAVE(1) */
00106 /*      J        ISAVE(2) */
00107 /*      ITER     ISAVE(3) */
00108 
00109 /*  ===================================================================== */
00110 
00111 /*     .. Parameters .. */
00112 /*     .. */
00113 /*     .. Local Scalars .. */
00114 /*     .. */
00115 /*     .. External Functions .. */
00116 /*     .. */
00117 /*     .. External Subroutines .. */
00118 /*     .. */
00119 /*     .. Intrinsic Functions .. */
00120 /*     .. */
00121 /*     .. Executable Statements .. */
00122 
00123     /* Parameter adjustments */
00124     --isave;
00125     --isgn;
00126     --x;
00127     --v;
00128 
00129     /* Function Body */
00130     if (*kase == 0) {
00131         i__1 = *n;
00132         for (i__ = 1; i__ <= i__1; ++i__) {
00133             x[i__] = 1.f / (real) (*n);
00134 /* L10: */
00135         }
00136         *kase = 1;
00137         isave[1] = 1;
00138         return 0;
00139     }
00140 
00141     switch (isave[1]) {
00142         case 1:  goto L20;
00143         case 2:  goto L40;
00144         case 3:  goto L70;
00145         case 4:  goto L110;
00146         case 5:  goto L140;
00147     }
00148 
00149 /*     ................ ENTRY   (ISAVE( 1 ) = 1) */
00150 /*     FIRST ITERATION.  X HAS BEEN OVERWRITTEN BY A*X. */
00151 
00152 L20:
00153     if (*n == 1) {
00154         v[1] = x[1];
00155         *est = dabs(v[1]);
00156 /*        ... QUIT */
00157         goto L150;
00158     }
00159     *est = sasum_(n, &x[1], &c__1);
00160 
00161     i__1 = *n;
00162     for (i__ = 1; i__ <= i__1; ++i__) {
00163         x[i__] = r_sign(&c_b11, &x[i__]);
00164         isgn[i__] = i_nint(&x[i__]);
00165 /* L30: */
00166     }
00167     *kase = 2;
00168     isave[1] = 2;
00169     return 0;
00170 
00171 /*     ................ ENTRY   (ISAVE( 1 ) = 2) */
00172 /*     FIRST ITERATION.  X HAS BEEN OVERWRITTEN BY TRANSPOSE(A)*X. */
00173 
00174 L40:
00175     isave[2] = isamax_(n, &x[1], &c__1);
00176     isave[3] = 2;
00177 
00178 /*     MAIN LOOP - ITERATIONS 2,3,...,ITMAX. */
00179 
00180 L50:
00181     i__1 = *n;
00182     for (i__ = 1; i__ <= i__1; ++i__) {
00183         x[i__] = 0.f;
00184 /* L60: */
00185     }
00186     x[isave[2]] = 1.f;
00187     *kase = 1;
00188     isave[1] = 3;
00189     return 0;
00190 
00191 /*     ................ ENTRY   (ISAVE( 1 ) = 3) */
00192 /*     X HAS BEEN OVERWRITTEN BY A*X. */
00193 
00194 L70:
00195     scopy_(n, &x[1], &c__1, &v[1], &c__1);
00196     estold = *est;
00197     *est = sasum_(n, &v[1], &c__1);
00198     i__1 = *n;
00199     for (i__ = 1; i__ <= i__1; ++i__) {
00200         r__1 = r_sign(&c_b11, &x[i__]);
00201         if (i_nint(&r__1) != isgn[i__]) {
00202             goto L90;
00203         }
00204 /* L80: */
00205     }
00206 /*     REPEATED SIGN VECTOR DETECTED, HENCE ALGORITHM HAS CONVERGED. */
00207     goto L120;
00208 
00209 L90:
00210 /*     TEST FOR CYCLING. */
00211     if (*est <= estold) {
00212         goto L120;
00213     }
00214 
00215     i__1 = *n;
00216     for (i__ = 1; i__ <= i__1; ++i__) {
00217         x[i__] = r_sign(&c_b11, &x[i__]);
00218         isgn[i__] = i_nint(&x[i__]);
00219 /* L100: */
00220     }
00221     *kase = 2;
00222     isave[1] = 4;
00223     return 0;
00224 
00225 /*     ................ ENTRY   (ISAVE( 1 ) = 4) */
00226 /*     X HAS BEEN OVERWRITTEN BY TRANSPOSE(A)*X. */
00227 
00228 L110:
00229     jlast = isave[2];
00230     isave[2] = isamax_(n, &x[1], &c__1);
00231     if (x[jlast] != (r__1 = x[isave[2]], dabs(r__1)) && isave[3] < 5) {
00232         ++isave[3];
00233         goto L50;
00234     }
00235 
00236 /*     ITERATION COMPLETE.  FINAL STAGE. */
00237 
00238 L120:
00239     altsgn = 1.f;
00240     i__1 = *n;
00241     for (i__ = 1; i__ <= i__1; ++i__) {
00242         x[i__] = altsgn * ((real) (i__ - 1) / (real) (*n - 1) + 1.f);
00243         altsgn = -altsgn;
00244 /* L130: */
00245     }
00246     *kase = 1;
00247     isave[1] = 5;
00248     return 0;
00249 
00250 /*     ................ ENTRY   (ISAVE( 1 ) = 5) */
00251 /*     X HAS BEEN OVERWRITTEN BY A*X. */
00252 
00253 L140:
00254     temp = sasum_(n, &x[1], &c__1) / (real) (*n * 3) * 2.f;
00255     if (temp > *est) {
00256         scopy_(n, &x[1], &c__1, &v[1], &c__1);
00257         *est = temp;
00258     }
00259 
00260 L150:
00261     *kase = 0;
00262     return 0;
00263 
00264 /*     End of SLACN2 */
00265 
00266 } /* slacn2_ */


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