dlagtf.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /* dlagtf.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 _starpu_dlagtf_(integer *n, doublereal *a, doublereal *lambda,
  14. doublereal *b, doublereal *c__, doublereal *tol, doublereal *d__,
  15. integer *in, integer *info)
  16. {
  17. /* System generated locals */
  18. integer i__1;
  19. doublereal d__1, d__2;
  20. /* Local variables */
  21. integer k;
  22. doublereal tl, eps, piv1, piv2, temp, mult, scale1, scale2;
  23. extern doublereal _starpu_dlamch_(char *);
  24. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  25. /* -- LAPACK routine (version 3.2) -- */
  26. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  27. /* November 2006 */
  28. /* .. Scalar Arguments .. */
  29. /* .. */
  30. /* .. Array Arguments .. */
  31. /* .. */
  32. /* Purpose */
  33. /* ======= */
  34. /* DLAGTF factorizes the matrix (T - lambda*I), where T is an n by n */
  35. /* tridiagonal matrix and lambda is a scalar, as */
  36. /* T - lambda*I = PLU, */
  37. /* where P is a permutation matrix, L is a unit lower tridiagonal matrix */
  38. /* with at most one non-zero sub-diagonal elements per column and U is */
  39. /* an upper triangular matrix with at most two non-zero super-diagonal */
  40. /* elements per column. */
  41. /* The factorization is obtained by Gaussian elimination with partial */
  42. /* pivoting and implicit row scaling. */
  43. /* The parameter LAMBDA is included in the routine so that DLAGTF may */
  44. /* be used, in conjunction with DLAGTS, to obtain eigenvectors of T by */
  45. /* inverse iteration. */
  46. /* Arguments */
  47. /* ========= */
  48. /* N (input) INTEGER */
  49. /* The order of the matrix T. */
  50. /* A (input/output) DOUBLE PRECISION array, dimension (N) */
  51. /* On entry, A must contain the diagonal elements of T. */
  52. /* On exit, A is overwritten by the n diagonal elements of the */
  53. /* upper triangular matrix U of the factorization of T. */
  54. /* LAMBDA (input) DOUBLE PRECISION */
  55. /* On entry, the scalar lambda. */
  56. /* B (input/output) DOUBLE PRECISION array, dimension (N-1) */
  57. /* On entry, B must contain the (n-1) super-diagonal elements of */
  58. /* T. */
  59. /* On exit, B is overwritten by the (n-1) super-diagonal */
  60. /* elements of the matrix U of the factorization of T. */
  61. /* C (input/output) DOUBLE PRECISION array, dimension (N-1) */
  62. /* On entry, C must contain the (n-1) sub-diagonal elements of */
  63. /* T. */
  64. /* On exit, C is overwritten by the (n-1) sub-diagonal elements */
  65. /* of the matrix L of the factorization of T. */
  66. /* TOL (input) DOUBLE PRECISION */
  67. /* On entry, a relative tolerance used to indicate whether or */
  68. /* not the matrix (T - lambda*I) is nearly singular. TOL should */
  69. /* normally be chose as approximately the largest relative error */
  70. /* in the elements of T. For example, if the elements of T are */
  71. /* correct to about 4 significant figures, then TOL should be */
  72. /* set to about 5*10**(-4). If TOL is supplied as less than eps, */
  73. /* where eps is the relative machine precision, then the value */
  74. /* eps is used in place of TOL. */
  75. /* D (output) DOUBLE PRECISION array, dimension (N-2) */
  76. /* On exit, D is overwritten by the (n-2) second super-diagonal */
  77. /* elements of the matrix U of the factorization of T. */
  78. /* IN (output) INTEGER array, dimension (N) */
  79. /* On exit, IN contains details of the permutation matrix P. If */
  80. /* an interchange occurred at the kth step of the elimination, */
  81. /* then IN(k) = 1, otherwise IN(k) = 0. The element IN(n) */
  82. /* returns the smallest positive integer j such that */
  83. /* abs( u(j,j) ).le. norm( (T - lambda*I)(j) )*TOL, */
  84. /* where norm( A(j) ) denotes the sum of the absolute values of */
  85. /* the jth row of the matrix A. If no such j exists then IN(n) */
  86. /* is returned as zero. If IN(n) is returned as positive, then a */
  87. /* diagonal element of U is small, indicating that */
  88. /* (T - lambda*I) is singular or nearly singular, */
  89. /* INFO (output) INTEGER */
  90. /* = 0 : successful exit */
  91. /* .lt. 0: if INFO = -k, the kth argument had an illegal value */
  92. /* ===================================================================== */
  93. /* .. Parameters .. */
  94. /* .. */
  95. /* .. Local Scalars .. */
  96. /* .. */
  97. /* .. Intrinsic Functions .. */
  98. /* .. */
  99. /* .. External Functions .. */
  100. /* .. */
  101. /* .. External Subroutines .. */
  102. /* .. */
  103. /* .. Executable Statements .. */
  104. /* Parameter adjustments */
  105. --in;
  106. --d__;
  107. --c__;
  108. --b;
  109. --a;
  110. /* Function Body */
  111. *info = 0;
  112. if (*n < 0) {
  113. *info = -1;
  114. i__1 = -(*info);
  115. _starpu_xerbla_("DLAGTF", &i__1);
  116. return 0;
  117. }
  118. if (*n == 0) {
  119. return 0;
  120. }
  121. a[1] -= *lambda;
  122. in[*n] = 0;
  123. if (*n == 1) {
  124. if (a[1] == 0.) {
  125. in[1] = 1;
  126. }
  127. return 0;
  128. }
  129. eps = _starpu_dlamch_("Epsilon");
  130. tl = max(*tol,eps);
  131. scale1 = abs(a[1]) + abs(b[1]);
  132. i__1 = *n - 1;
  133. for (k = 1; k <= i__1; ++k) {
  134. a[k + 1] -= *lambda;
  135. scale2 = (d__1 = c__[k], abs(d__1)) + (d__2 = a[k + 1], abs(d__2));
  136. if (k < *n - 1) {
  137. scale2 += (d__1 = b[k + 1], abs(d__1));
  138. }
  139. if (a[k] == 0.) {
  140. piv1 = 0.;
  141. } else {
  142. piv1 = (d__1 = a[k], abs(d__1)) / scale1;
  143. }
  144. if (c__[k] == 0.) {
  145. in[k] = 0;
  146. piv2 = 0.;
  147. scale1 = scale2;
  148. if (k < *n - 1) {
  149. d__[k] = 0.;
  150. }
  151. } else {
  152. piv2 = (d__1 = c__[k], abs(d__1)) / scale2;
  153. if (piv2 <= piv1) {
  154. in[k] = 0;
  155. scale1 = scale2;
  156. c__[k] /= a[k];
  157. a[k + 1] -= c__[k] * b[k];
  158. if (k < *n - 1) {
  159. d__[k] = 0.;
  160. }
  161. } else {
  162. in[k] = 1;
  163. mult = a[k] / c__[k];
  164. a[k] = c__[k];
  165. temp = a[k + 1];
  166. a[k + 1] = b[k] - mult * temp;
  167. if (k < *n - 1) {
  168. d__[k] = b[k + 1];
  169. b[k + 1] = -mult * d__[k];
  170. }
  171. b[k] = temp;
  172. c__[k] = mult;
  173. }
  174. }
  175. if (max(piv1,piv2) <= tl && in[*n] == 0) {
  176. in[*n] = k;
  177. }
  178. /* L10: */
  179. }
  180. if ((d__1 = a[*n], abs(d__1)) <= scale1 * tl && in[*n] == 0) {
  181. in[*n] = *n;
  182. }
  183. return 0;
  184. /* End of DLAGTF */
  185. } /* _starpu_dlagtf_ */