slarfp.c
Go to the documentation of this file.
00001 /* slarfp.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 /* Subroutine */ int slarfp_(integer *n, real *alpha, real *x, integer *incx, 
00017         real *tau)
00018 {
00019     /* System generated locals */
00020     integer i__1;
00021     real r__1;
00022 
00023     /* Builtin functions */
00024     double r_sign(real *, real *);
00025 
00026     /* Local variables */
00027     integer j, knt;
00028     real beta;
00029     extern doublereal snrm2_(integer *, real *, integer *);
00030     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
00031     real xnorm;
00032     extern doublereal slapy2_(real *, real *), slamch_(char *);
00033     real safmin, rsafmn;
00034 
00035 
00036 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00037 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00038 /*     November 2006 */
00039 
00040 /*     .. Scalar Arguments .. */
00041 /*     .. */
00042 /*     .. Array Arguments .. */
00043 /*     .. */
00044 
00045 /*  Purpose */
00046 /*  ======= */
00047 
00048 /*  SLARFP generates a real elementary reflector H of order n, such */
00049 /*  that */
00050 
00051 /*        H * ( alpha ) = ( beta ),   H' * H = I. */
00052 /*            (   x   )   (   0  ) */
00053 
00054 /*  where alpha and beta are scalars, beta is non-negative, and x is */
00055 /*  an (n-1)-element real vector.  H is represented in the form */
00056 
00057 /*        H = I - tau * ( 1 ) * ( 1 v' ) , */
00058 /*                      ( v ) */
00059 
00060 /*  where tau is a real scalar and v is a real (n-1)-element */
00061 /*  vector. */
00062 
00063 /*  If the elements of x are all zero, then tau = 0 and H is taken to be */
00064 /*  the unit matrix. */
00065 
00066 /*  Otherwise  1 <= tau <= 2. */
00067 
00068 /*  Arguments */
00069 /*  ========= */
00070 
00071 /*  N       (input) INTEGER */
00072 /*          The order of the elementary reflector. */
00073 
00074 /*  ALPHA   (input/output) REAL */
00075 /*          On entry, the value alpha. */
00076 /*          On exit, it is overwritten with the value beta. */
00077 
00078 /*  X       (input/output) REAL array, dimension */
00079 /*                         (1+(N-2)*abs(INCX)) */
00080 /*          On entry, the vector x. */
00081 /*          On exit, it is overwritten with the vector v. */
00082 
00083 /*  INCX    (input) INTEGER */
00084 /*          The increment between elements of X. INCX > 0. */
00085 
00086 /*  TAU     (output) REAL */
00087 /*          The value tau. */
00088 
00089 /*  ===================================================================== */
00090 
00091 /*     .. Parameters .. */
00092 /*     .. */
00093 /*     .. Local Scalars .. */
00094 /*     .. */
00095 /*     .. External Functions .. */
00096 /*     .. */
00097 /*     .. Intrinsic Functions .. */
00098 /*     .. */
00099 /*     .. External Subroutines .. */
00100 /*     .. */
00101 /*     .. Executable Statements .. */
00102 
00103     /* Parameter adjustments */
00104     --x;
00105 
00106     /* Function Body */
00107     if (*n <= 0) {
00108         *tau = 0.f;
00109         return 0;
00110     }
00111 
00112     i__1 = *n - 1;
00113     xnorm = snrm2_(&i__1, &x[1], incx);
00114 
00115     if (xnorm == 0.f) {
00116 
00117 /*        H  =  [+/-1, 0; I], sign chosen so ALPHA >= 0. */
00118 
00119         if (*alpha >= 0.f) {
00120 /*           When TAU.eq.ZERO, the vector is special-cased to be */
00121 /*           all zeros in the application routines.  We do not need */
00122 /*           to clear it. */
00123             *tau = 0.f;
00124         } else {
00125 /*           However, the application routines rely on explicit */
00126 /*           zero checks when TAU.ne.ZERO, and we must clear X. */
00127             *tau = 2.f;
00128             i__1 = *n - 1;
00129             for (j = 1; j <= i__1; ++j) {
00130                 x[(j - 1) * *incx + 1] = 0.f;
00131             }
00132             *alpha = -(*alpha);
00133         }
00134     } else {
00135 
00136 /*        general case */
00137 
00138         r__1 = slapy2_(alpha, &xnorm);
00139         beta = r_sign(&r__1, alpha);
00140         safmin = slamch_("S") / slamch_("E");
00141         knt = 0;
00142         if (dabs(beta) < safmin) {
00143 
00144 /*           XNORM, BETA may be inaccurate; scale X and recompute them */
00145 
00146             rsafmn = 1.f / safmin;
00147 L10:
00148             ++knt;
00149             i__1 = *n - 1;
00150             sscal_(&i__1, &rsafmn, &x[1], incx);
00151             beta *= rsafmn;
00152             *alpha *= rsafmn;
00153             if (dabs(beta) < safmin) {
00154                 goto L10;
00155             }
00156 
00157 /*           New BETA is at most 1, at least SAFMIN */
00158 
00159             i__1 = *n - 1;
00160             xnorm = snrm2_(&i__1, &x[1], incx);
00161             r__1 = slapy2_(alpha, &xnorm);
00162             beta = r_sign(&r__1, alpha);
00163         }
00164         *alpha += beta;
00165         if (beta < 0.f) {
00166             beta = -beta;
00167             *tau = -(*alpha) / beta;
00168         } else {
00169             *alpha = xnorm * (xnorm / *alpha);
00170             *tau = *alpha / beta;
00171             *alpha = -(*alpha);
00172         }
00173         i__1 = *n - 1;
00174         r__1 = 1.f / *alpha;
00175         sscal_(&i__1, &r__1, &x[1], incx);
00176 
00177 /*        If BETA is subnormal, it may lose relative accuracy */
00178 
00179         i__1 = knt;
00180         for (j = 1; j <= i__1; ++j) {
00181             beta *= safmin;
00182 /* L20: */
00183         }
00184         *alpha = beta;
00185     }
00186 
00187     return 0;
00188 
00189 /*     End of SLARFP */
00190 
00191 } /* slarfp_ */


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