dlange.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* dlange.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. /* Table of constant values */
  14. static integer c__1 = 1;
  15. doublereal _starpu_dlange_(char *norm, integer *m, integer *n, doublereal *a, integer
  16. *lda, doublereal *work)
  17. {
  18. /* System generated locals */
  19. integer a_dim1, a_offset, i__1, i__2;
  20. doublereal ret_val, d__1, d__2, d__3;
  21. /* Builtin functions */
  22. double sqrt(doublereal);
  23. /* Local variables */
  24. integer i__, j;
  25. doublereal sum, scale;
  26. extern logical _starpu_lsame_(char *, char *);
  27. doublereal value;
  28. extern /* Subroutine */ int _starpu_dlassq_(integer *, doublereal *, integer *,
  29. doublereal *, doublereal *);
  30. /* -- LAPACK auxiliary routine (version 3.2) -- */
  31. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  32. /* November 2006 */
  33. /* .. Scalar Arguments .. */
  34. /* .. */
  35. /* .. Array Arguments .. */
  36. /* .. */
  37. /* Purpose */
  38. /* ======= */
  39. /* DLANGE returns the value of the one norm, or the Frobenius norm, or */
  40. /* the infinity norm, or the element of largest absolute value of a */
  41. /* real matrix A. */
  42. /* Description */
  43. /* =========== */
  44. /* DLANGE returns the value */
  45. /* DLANGE = ( max(abs(A(i,j))), NORM = 'M' or 'm' */
  46. /* ( */
  47. /* ( norm1(A), NORM = '1', 'O' or 'o' */
  48. /* ( */
  49. /* ( normI(A), NORM = 'I' or 'i' */
  50. /* ( */
  51. /* ( normF(A), NORM = 'F', 'f', 'E' or 'e' */
  52. /* where norm1 denotes the one norm of a matrix (maximum column sum), */
  53. /* normI denotes the infinity norm of a matrix (maximum row sum) and */
  54. /* normF denotes the Frobenius norm of a matrix (square root of sum of */
  55. /* squares). Note that max(abs(A(i,j))) is not a consistent matrix norm. */
  56. /* Arguments */
  57. /* ========= */
  58. /* NORM (input) CHARACTER*1 */
  59. /* Specifies the value to be returned in DLANGE as described */
  60. /* above. */
  61. /* M (input) INTEGER */
  62. /* The number of rows of the matrix A. M >= 0. When M = 0, */
  63. /* DLANGE is set to zero. */
  64. /* N (input) INTEGER */
  65. /* The number of columns of the matrix A. N >= 0. When N = 0, */
  66. /* DLANGE is set to zero. */
  67. /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */
  68. /* The m by n matrix A. */
  69. /* LDA (input) INTEGER */
  70. /* The leading dimension of the array A. LDA >= max(M,1). */
  71. /* WORK (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)), */
  72. /* where LWORK >= M when NORM = 'I'; otherwise, WORK is not */
  73. /* referenced. */
  74. /* ===================================================================== */
  75. /* .. Parameters .. */
  76. /* .. */
  77. /* .. Local Scalars .. */
  78. /* .. */
  79. /* .. External Subroutines .. */
  80. /* .. */
  81. /* .. External Functions .. */
  82. /* .. */
  83. /* .. Intrinsic Functions .. */
  84. /* .. */
  85. /* .. Executable Statements .. */
  86. /* Parameter adjustments */
  87. a_dim1 = *lda;
  88. a_offset = 1 + a_dim1;
  89. a -= a_offset;
  90. --work;
  91. /* Function Body */
  92. if (min(*m,*n) == 0) {
  93. value = 0.;
  94. } else if (_starpu_lsame_(norm, "M")) {
  95. /* Find max(abs(A(i,j))). */
  96. value = 0.;
  97. i__1 = *n;
  98. for (j = 1; j <= i__1; ++j) {
  99. i__2 = *m;
  100. for (i__ = 1; i__ <= i__2; ++i__) {
  101. /* Computing MAX */
  102. d__2 = value, d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1));
  103. value = max(d__2,d__3);
  104. /* L10: */
  105. }
  106. /* L20: */
  107. }
  108. } else if (_starpu_lsame_(norm, "O") || *(unsigned char *)
  109. norm == '1') {
  110. /* Find norm1(A). */
  111. value = 0.;
  112. i__1 = *n;
  113. for (j = 1; j <= i__1; ++j) {
  114. sum = 0.;
  115. i__2 = *m;
  116. for (i__ = 1; i__ <= i__2; ++i__) {
  117. sum += (d__1 = a[i__ + j * a_dim1], abs(d__1));
  118. /* L30: */
  119. }
  120. value = max(value,sum);
  121. /* L40: */
  122. }
  123. } else if (_starpu_lsame_(norm, "I")) {
  124. /* Find normI(A). */
  125. i__1 = *m;
  126. for (i__ = 1; i__ <= i__1; ++i__) {
  127. work[i__] = 0.;
  128. /* L50: */
  129. }
  130. i__1 = *n;
  131. for (j = 1; j <= i__1; ++j) {
  132. i__2 = *m;
  133. for (i__ = 1; i__ <= i__2; ++i__) {
  134. work[i__] += (d__1 = a[i__ + j * a_dim1], abs(d__1));
  135. /* L60: */
  136. }
  137. /* L70: */
  138. }
  139. value = 0.;
  140. i__1 = *m;
  141. for (i__ = 1; i__ <= i__1; ++i__) {
  142. /* Computing MAX */
  143. d__1 = value, d__2 = work[i__];
  144. value = max(d__1,d__2);
  145. /* L80: */
  146. }
  147. } else if (_starpu_lsame_(norm, "F") || _starpu_lsame_(norm, "E")) {
  148. /* Find normF(A). */
  149. scale = 0.;
  150. sum = 1.;
  151. i__1 = *n;
  152. for (j = 1; j <= i__1; ++j) {
  153. _starpu_dlassq_(m, &a[j * a_dim1 + 1], &c__1, &scale, &sum);
  154. /* L90: */
  155. }
  156. value = scale * sqrt(sum);
  157. }
  158. ret_val = value;
  159. return ret_val;
  160. /* End of DLANGE */
  161. } /* _starpu_dlange_ */