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


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