dgeequ.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /* dgeequ.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_dgeequ_(integer *m, integer *n, doublereal *a, integer *
  14. lda, doublereal *r__, doublereal *c__, doublereal *rowcnd, doublereal
  15. *colcnd, doublereal *amax, integer *info)
  16. {
  17. /* System generated locals */
  18. integer a_dim1, a_offset, i__1, i__2;
  19. doublereal d__1, d__2, d__3;
  20. /* Local variables */
  21. integer i__, j;
  22. doublereal rcmin, rcmax;
  23. extern doublereal _starpu_dlamch_(char *);
  24. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  25. doublereal bignum, smlnum;
  26. /* -- LAPACK routine (version 3.2) -- */
  27. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  28. /* November 2006 */
  29. /* .. Scalar Arguments .. */
  30. /* .. */
  31. /* .. Array Arguments .. */
  32. /* .. */
  33. /* Purpose */
  34. /* ======= */
  35. /* DGEEQU computes row and column scalings intended to equilibrate an */
  36. /* M-by-N matrix A and reduce its condition number. R returns the row */
  37. /* scale factors and C the column scale factors, chosen to try to make */
  38. /* the largest element in each row and column of the matrix B with */
  39. /* elements B(i,j)=R(i)*A(i,j)*C(j) have absolute value 1. */
  40. /* R(i) and C(j) are restricted to be between SMLNUM = smallest safe */
  41. /* number and BIGNUM = largest safe number. Use of these scaling */
  42. /* factors is not guaranteed to reduce the condition number of A but */
  43. /* works well in practice. */
  44. /* Arguments */
  45. /* ========= */
  46. /* M (input) INTEGER */
  47. /* The number of rows of the matrix A. M >= 0. */
  48. /* N (input) INTEGER */
  49. /* The number of columns of the matrix A. N >= 0. */
  50. /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */
  51. /* The M-by-N matrix whose equilibration factors are */
  52. /* to be computed. */
  53. /* LDA (input) INTEGER */
  54. /* The leading dimension of the array A. LDA >= max(1,M). */
  55. /* R (output) DOUBLE PRECISION array, dimension (M) */
  56. /* If INFO = 0 or INFO > M, R contains the row scale factors */
  57. /* for A. */
  58. /* C (output) DOUBLE PRECISION array, dimension (N) */
  59. /* If INFO = 0, C contains the column scale factors for A. */
  60. /* ROWCND (output) DOUBLE PRECISION */
  61. /* If INFO = 0 or INFO > M, ROWCND contains the ratio of the */
  62. /* smallest R(i) to the largest R(i). If ROWCND >= 0.1 and */
  63. /* AMAX is neither too large nor too small, it is not worth */
  64. /* scaling by R. */
  65. /* COLCND (output) DOUBLE PRECISION */
  66. /* If INFO = 0, COLCND contains the ratio of the smallest */
  67. /* C(i) to the largest C(i). If COLCND >= 0.1, it is not */
  68. /* worth scaling by C. */
  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, and i is */
  77. /* <= M: the i-th row of A is exactly zero */
  78. /* > M: the (i-M)-th column of A is exactly zero */
  79. /* ===================================================================== */
  80. /* .. Parameters .. */
  81. /* .. */
  82. /* .. Local Scalars .. */
  83. /* .. */
  84. /* .. External Functions .. */
  85. /* .. */
  86. /* .. External Subroutines .. */
  87. /* .. */
  88. /* .. Intrinsic Functions .. */
  89. /* .. */
  90. /* .. Executable Statements .. */
  91. /* Test the input parameters. */
  92. /* Parameter adjustments */
  93. a_dim1 = *lda;
  94. a_offset = 1 + a_dim1;
  95. a -= a_offset;
  96. --r__;
  97. --c__;
  98. /* Function Body */
  99. *info = 0;
  100. if (*m < 0) {
  101. *info = -1;
  102. } else if (*n < 0) {
  103. *info = -2;
  104. } else if (*lda < max(1,*m)) {
  105. *info = -4;
  106. }
  107. if (*info != 0) {
  108. i__1 = -(*info);
  109. _starpu_xerbla_("DGEEQU", &i__1);
  110. return 0;
  111. }
  112. /* Quick return if possible */
  113. if (*m == 0 || *n == 0) {
  114. *rowcnd = 1.;
  115. *colcnd = 1.;
  116. *amax = 0.;
  117. return 0;
  118. }
  119. /* Get machine constants. */
  120. smlnum = _starpu_dlamch_("S");
  121. bignum = 1. / smlnum;
  122. /* Compute row scale factors. */
  123. i__1 = *m;
  124. for (i__ = 1; i__ <= i__1; ++i__) {
  125. r__[i__] = 0.;
  126. /* L10: */
  127. }
  128. /* Find the maximum element in each row. */
  129. i__1 = *n;
  130. for (j = 1; j <= i__1; ++j) {
  131. i__2 = *m;
  132. for (i__ = 1; i__ <= i__2; ++i__) {
  133. /* Computing MAX */
  134. d__2 = r__[i__], d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1));
  135. r__[i__] = max(d__2,d__3);
  136. /* L20: */
  137. }
  138. /* L30: */
  139. }
  140. /* Find the maximum and minimum scale factors. */
  141. rcmin = bignum;
  142. rcmax = 0.;
  143. i__1 = *m;
  144. for (i__ = 1; i__ <= i__1; ++i__) {
  145. /* Computing MAX */
  146. d__1 = rcmax, d__2 = r__[i__];
  147. rcmax = max(d__1,d__2);
  148. /* Computing MIN */
  149. d__1 = rcmin, d__2 = r__[i__];
  150. rcmin = min(d__1,d__2);
  151. /* L40: */
  152. }
  153. *amax = rcmax;
  154. if (rcmin == 0.) {
  155. /* Find the first zero scale factor and return an error code. */
  156. i__1 = *m;
  157. for (i__ = 1; i__ <= i__1; ++i__) {
  158. if (r__[i__] == 0.) {
  159. *info = i__;
  160. return 0;
  161. }
  162. /* L50: */
  163. }
  164. } else {
  165. /* Invert the scale factors. */
  166. i__1 = *m;
  167. for (i__ = 1; i__ <= i__1; ++i__) {
  168. /* Computing MIN */
  169. /* Computing MAX */
  170. d__2 = r__[i__];
  171. d__1 = max(d__2,smlnum);
  172. r__[i__] = 1. / min(d__1,bignum);
  173. /* L60: */
  174. }
  175. /* Compute ROWCND = min(R(I)) / max(R(I)) */
  176. *rowcnd = max(rcmin,smlnum) / min(rcmax,bignum);
  177. }
  178. /* Compute column scale factors */
  179. i__1 = *n;
  180. for (j = 1; j <= i__1; ++j) {
  181. c__[j] = 0.;
  182. /* L70: */
  183. }
  184. /* Find the maximum element in each column, */
  185. /* assuming the row scaling computed above. */
  186. i__1 = *n;
  187. for (j = 1; j <= i__1; ++j) {
  188. i__2 = *m;
  189. for (i__ = 1; i__ <= i__2; ++i__) {
  190. /* Computing MAX */
  191. d__2 = c__[j], d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1)) *
  192. r__[i__];
  193. c__[j] = max(d__2,d__3);
  194. /* L80: */
  195. }
  196. /* L90: */
  197. }
  198. /* Find the maximum and minimum scale factors. */
  199. rcmin = bignum;
  200. rcmax = 0.;
  201. i__1 = *n;
  202. for (j = 1; j <= i__1; ++j) {
  203. /* Computing MIN */
  204. d__1 = rcmin, d__2 = c__[j];
  205. rcmin = min(d__1,d__2);
  206. /* Computing MAX */
  207. d__1 = rcmax, d__2 = c__[j];
  208. rcmax = max(d__1,d__2);
  209. /* L100: */
  210. }
  211. if (rcmin == 0.) {
  212. /* Find the first zero scale factor and return an error code. */
  213. i__1 = *n;
  214. for (j = 1; j <= i__1; ++j) {
  215. if (c__[j] == 0.) {
  216. *info = *m + j;
  217. return 0;
  218. }
  219. /* L110: */
  220. }
  221. } else {
  222. /* Invert the scale factors. */
  223. i__1 = *n;
  224. for (j = 1; j <= i__1; ++j) {
  225. /* Computing MIN */
  226. /* Computing MAX */
  227. d__2 = c__[j];
  228. d__1 = max(d__2,smlnum);
  229. c__[j] = 1. / min(d__1,bignum);
  230. /* L120: */
  231. }
  232. /* Compute COLCND = min(C(J)) / max(C(J)) */
  233. *colcnd = max(rcmin,smlnum) / min(rcmax,bignum);
  234. }
  235. return 0;
  236. /* End of DGEEQU */
  237. } /* _starpu_dgeequ_ */