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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:46