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


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