dgeequb.c 8.5 KB

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