dppequ.c 5.4 KB

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