dlarfg.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* dlarfg.f -- translated by f2c (version 20061008).
  2. You must link the resulting object file with libf2c:
  3. on Microsoft Windows system, link with libf2c.lib;
  4. on Linux or Unix systems, link with .../path/to/libf2c.a -lm
  5. or, if you install libf2c.a in a standard place, with -lf2c -lm
  6. -- in that order, at the end of the command line, as in
  7. cc *.o -lf2c -lm
  8. Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
  9. http://www.netlib.org/f2c/libf2c.zip
  10. */
  11. #include "f2c.h"
  12. #include "blaswrap.h"
  13. /* Subroutine */ int dlarfg_(integer *n, doublereal *alpha, doublereal *x,
  14. integer *incx, doublereal *tau)
  15. {
  16. /* System generated locals */
  17. integer i__1;
  18. doublereal d__1;
  19. /* Builtin functions */
  20. double d_sign(doublereal *, doublereal *);
  21. /* Local variables */
  22. integer j, knt;
  23. doublereal beta;
  24. extern doublereal dnrm2_(integer *, doublereal *, integer *);
  25. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  26. integer *);
  27. doublereal xnorm;
  28. extern doublereal dlapy2_(doublereal *, doublereal *), dlamch_(char *);
  29. doublereal safmin, rsafmn;
  30. /* -- LAPACK auxiliary routine (version 3.2) -- */
  31. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  32. /* November 2006 */
  33. /* .. Scalar Arguments .. */
  34. /* .. */
  35. /* .. Array Arguments .. */
  36. /* .. */
  37. /* Purpose */
  38. /* ======= */
  39. /* DLARFG generates a real elementary reflector H of order n, such */
  40. /* that */
  41. /* H * ( alpha ) = ( beta ), H' * H = I. */
  42. /* ( x ) ( 0 ) */
  43. /* where alpha and beta are scalars, and x is an (n-1)-element real */
  44. /* vector. H is represented in the form */
  45. /* H = I - tau * ( 1 ) * ( 1 v' ) , */
  46. /* ( v ) */
  47. /* where tau is a real scalar and v is a real (n-1)-element */
  48. /* vector. */
  49. /* If the elements of x are all zero, then tau = 0 and H is taken to be */
  50. /* the unit matrix. */
  51. /* Otherwise 1 <= tau <= 2. */
  52. /* Arguments */
  53. /* ========= */
  54. /* N (input) INTEGER */
  55. /* The order of the elementary reflector. */
  56. /* ALPHA (input/output) DOUBLE PRECISION */
  57. /* On entry, the value alpha. */
  58. /* On exit, it is overwritten with the value beta. */
  59. /* X (input/output) DOUBLE PRECISION array, dimension */
  60. /* (1+(N-2)*abs(INCX)) */
  61. /* On entry, the vector x. */
  62. /* On exit, it is overwritten with the vector v. */
  63. /* INCX (input) INTEGER */
  64. /* The increment between elements of X. INCX > 0. */
  65. /* TAU (output) DOUBLE PRECISION */
  66. /* The value tau. */
  67. /* ===================================================================== */
  68. /* .. Parameters .. */
  69. /* .. */
  70. /* .. Local Scalars .. */
  71. /* .. */
  72. /* .. External Functions .. */
  73. /* .. */
  74. /* .. Intrinsic Functions .. */
  75. /* .. */
  76. /* .. External Subroutines .. */
  77. /* .. */
  78. /* .. Executable Statements .. */
  79. /* Parameter adjustments */
  80. --x;
  81. /* Function Body */
  82. if (*n <= 1) {
  83. *tau = 0.;
  84. return 0;
  85. }
  86. i__1 = *n - 1;
  87. xnorm = dnrm2_(&i__1, &x[1], incx);
  88. if (xnorm == 0.) {
  89. /* H = I */
  90. *tau = 0.;
  91. } else {
  92. /* general case */
  93. d__1 = dlapy2_(alpha, &xnorm);
  94. beta = -d_sign(&d__1, alpha);
  95. safmin = dlamch_("S") / dlamch_("E");
  96. knt = 0;
  97. if (abs(beta) < safmin) {
  98. /* XNORM, BETA may be inaccurate; scale X and recompute them */
  99. rsafmn = 1. / safmin;
  100. L10:
  101. ++knt;
  102. i__1 = *n - 1;
  103. dscal_(&i__1, &rsafmn, &x[1], incx);
  104. beta *= rsafmn;
  105. *alpha *= rsafmn;
  106. if (abs(beta) < safmin) {
  107. goto L10;
  108. }
  109. /* New BETA is at most 1, at least SAFMIN */
  110. i__1 = *n - 1;
  111. xnorm = dnrm2_(&i__1, &x[1], incx);
  112. d__1 = dlapy2_(alpha, &xnorm);
  113. beta = -d_sign(&d__1, alpha);
  114. }
  115. *tau = (beta - *alpha) / beta;
  116. i__1 = *n - 1;
  117. d__1 = 1. / (*alpha - beta);
  118. dscal_(&i__1, &d__1, &x[1], incx);
  119. /* If ALPHA is subnormal, it may lose relative accuracy */
  120. i__1 = knt;
  121. for (j = 1; j <= i__1; ++j) {
  122. beta *= safmin;
  123. /* L20: */
  124. }
  125. *alpha = beta;
  126. }
  127. return 0;
  128. /* End of DLARFG */
  129. } /* dlarfg_ */