dpbequ.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* dpbequ.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_dpbequ_(char *uplo, integer *n, integer *kd, doublereal *
  14. ab, integer *ldab, doublereal *s, doublereal *scond, doublereal *amax,
  15. integer *info)
  16. {
  17. /* System generated locals */
  18. integer ab_dim1, ab_offset, i__1;
  19. doublereal d__1, d__2;
  20. /* Builtin functions */
  21. double sqrt(doublereal);
  22. /* Local variables */
  23. integer i__, j;
  24. doublereal smin;
  25. extern logical _starpu_lsame_(char *, char *);
  26. logical upper;
  27. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  28. /* -- LAPACK routine (version 3.2) -- */
  29. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  30. /* November 2006 */
  31. /* .. Scalar Arguments .. */
  32. /* .. */
  33. /* .. Array Arguments .. */
  34. /* .. */
  35. /* Purpose */
  36. /* ======= */
  37. /* DPBEQU computes row and column scalings intended to equilibrate a */
  38. /* symmetric positive definite band matrix A and reduce its condition */
  39. /* number (with respect to the two-norm). S contains the scale factors, */
  40. /* S(i) = 1/sqrt(A(i,i)), chosen so that the scaled matrix B with */
  41. /* elements B(i,j) = S(i)*A(i,j)*S(j) has ones on the diagonal. This */
  42. /* choice of S puts the condition number of B within a factor N of the */
  43. /* smallest possible condition number over all possible diagonal */
  44. /* scalings. */
  45. /* Arguments */
  46. /* ========= */
  47. /* UPLO (input) CHARACTER*1 */
  48. /* = 'U': Upper triangular of A is stored; */
  49. /* = 'L': Lower triangular of A is stored. */
  50. /* N (input) INTEGER */
  51. /* The order of the matrix A. N >= 0. */
  52. /* KD (input) INTEGER */
  53. /* The number of superdiagonals of the matrix A if UPLO = 'U', */
  54. /* or the number of subdiagonals if UPLO = 'L'. KD >= 0. */
  55. /* AB (input) DOUBLE PRECISION array, dimension (LDAB,N) */
  56. /* The upper or lower triangle of the symmetric band matrix A, */
  57. /* stored in the first KD+1 rows of the array. The j-th column */
  58. /* of A is stored in the j-th column of the array AB as follows: */
  59. /* if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */
  60. /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). */
  61. /* LDAB (input) INTEGER */
  62. /* The leading dimension of the array A. LDAB >= KD+1. */
  63. /* S (output) DOUBLE PRECISION array, dimension (N) */
  64. /* If INFO = 0, S contains the scale factors for A. */
  65. /* SCOND (output) DOUBLE PRECISION */
  66. /* If INFO = 0, S contains the ratio of the smallest S(i) to */
  67. /* the largest S(i). If SCOND >= 0.1 and AMAX is neither too */
  68. /* large nor too small, it is not worth scaling by S. */
  69. /* AMAX (output) DOUBLE PRECISION */
  70. /* Absolute value of largest matrix element. If AMAX is very */
  71. /* close to overflow or very close to underflow, the matrix */
  72. /* should be scaled. */
  73. /* INFO (output) INTEGER */
  74. /* = 0: successful exit */
  75. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  76. /* > 0: if INFO = i, the i-th diagonal element is nonpositive. */
  77. /* ===================================================================== */
  78. /* .. Parameters .. */
  79. /* .. */
  80. /* .. Local Scalars .. */
  81. /* .. */
  82. /* .. External Functions .. */
  83. /* .. */
  84. /* .. External Subroutines .. */
  85. /* .. */
  86. /* .. Intrinsic Functions .. */
  87. /* .. */
  88. /* .. Executable Statements .. */
  89. /* Test the input parameters. */
  90. /* Parameter adjustments */
  91. ab_dim1 = *ldab;
  92. ab_offset = 1 + ab_dim1;
  93. ab -= ab_offset;
  94. --s;
  95. /* Function Body */
  96. *info = 0;
  97. upper = _starpu_lsame_(uplo, "U");
  98. if (! upper && ! _starpu_lsame_(uplo, "L")) {
  99. *info = -1;
  100. } else if (*n < 0) {
  101. *info = -2;
  102. } else if (*kd < 0) {
  103. *info = -3;
  104. } else if (*ldab < *kd + 1) {
  105. *info = -5;
  106. }
  107. if (*info != 0) {
  108. i__1 = -(*info);
  109. _starpu_xerbla_("DPBEQU", &i__1);
  110. return 0;
  111. }
  112. /* Quick return if possible */
  113. if (*n == 0) {
  114. *scond = 1.;
  115. *amax = 0.;
  116. return 0;
  117. }
  118. if (upper) {
  119. j = *kd + 1;
  120. } else {
  121. j = 1;
  122. }
  123. /* Initialize SMIN and AMAX. */
  124. s[1] = ab[j + ab_dim1];
  125. smin = s[1];
  126. *amax = s[1];
  127. /* Find the minimum and maximum diagonal elements. */
  128. i__1 = *n;
  129. for (i__ = 2; i__ <= i__1; ++i__) {
  130. s[i__] = ab[j + i__ * ab_dim1];
  131. /* Computing MIN */
  132. d__1 = smin, d__2 = s[i__];
  133. smin = min(d__1,d__2);
  134. /* Computing MAX */
  135. d__1 = *amax, d__2 = s[i__];
  136. *amax = max(d__1,d__2);
  137. /* L10: */
  138. }
  139. if (smin <= 0.) {
  140. /* Find the first non-positive diagonal element and return. */
  141. i__1 = *n;
  142. for (i__ = 1; i__ <= i__1; ++i__) {
  143. if (s[i__] <= 0.) {
  144. *info = i__;
  145. return 0;
  146. }
  147. /* L20: */
  148. }
  149. } else {
  150. /* Set the scale factors to the reciprocals */
  151. /* of the diagonal elements. */
  152. i__1 = *n;
  153. for (i__ = 1; i__ <= i__1; ++i__) {
  154. s[i__] = 1. / sqrt(s[i__]);
  155. /* L30: */
  156. }
  157. /* Compute SCOND = min(S(I)) / max(S(I)) */
  158. *scond = sqrt(smin) / sqrt(*amax);
  159. }
  160. return 0;
  161. /* End of DPBEQU */
  162. } /* _starpu_dpbequ_ */