dlansy.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /* dlansy.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_dlansy_(char *norm, char *uplo, 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, absa, 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. /* DLANSY 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 symmetric matrix A. */
  42. /* Description */
  43. /* =========== */
  44. /* DLANSY returns the value */
  45. /* DLANSY = ( 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 DLANSY as described */
  60. /* above. */
  61. /* UPLO (input) CHARACTER*1 */
  62. /* Specifies whether the upper or lower triangular part of the */
  63. /* symmetric matrix A is to be referenced. */
  64. /* = 'U': Upper triangular part of A is referenced */
  65. /* = 'L': Lower triangular part of A is referenced */
  66. /* N (input) INTEGER */
  67. /* The order of the matrix A. N >= 0. When N = 0, DLANSY is */
  68. /* set to zero. */
  69. /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */
  70. /* The symmetric matrix A. If UPLO = 'U', the leading n by n */
  71. /* upper triangular part of A contains the upper triangular part */
  72. /* of the matrix A, and the strictly lower triangular part of A */
  73. /* is not referenced. If UPLO = 'L', the leading n by n lower */
  74. /* triangular part of A contains the lower triangular part of */
  75. /* the matrix A, and the strictly upper triangular part of A is */
  76. /* not referenced. */
  77. /* LDA (input) INTEGER */
  78. /* The leading dimension of the array A. LDA >= max(N,1). */
  79. /* WORK (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)), */
  80. /* where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise, */
  81. /* WORK is not referenced. */
  82. /* ===================================================================== */
  83. /* .. Parameters .. */
  84. /* .. */
  85. /* .. Local Scalars .. */
  86. /* .. */
  87. /* .. External Subroutines .. */
  88. /* .. */
  89. /* .. External Functions .. */
  90. /* .. */
  91. /* .. Intrinsic Functions .. */
  92. /* .. */
  93. /* .. Executable Statements .. */
  94. /* Parameter adjustments */
  95. a_dim1 = *lda;
  96. a_offset = 1 + a_dim1;
  97. a -= a_offset;
  98. --work;
  99. /* Function Body */
  100. if (*n == 0) {
  101. value = 0.;
  102. } else if (_starpu_lsame_(norm, "M")) {
  103. /* Find max(abs(A(i,j))). */
  104. value = 0.;
  105. if (_starpu_lsame_(uplo, "U")) {
  106. i__1 = *n;
  107. for (j = 1; j <= i__1; ++j) {
  108. i__2 = j;
  109. for (i__ = 1; i__ <= i__2; ++i__) {
  110. /* Computing MAX */
  111. d__2 = value, d__3 = (d__1 = a[i__ + j * a_dim1], abs(
  112. d__1));
  113. value = max(d__2,d__3);
  114. /* L10: */
  115. }
  116. /* L20: */
  117. }
  118. } else {
  119. i__1 = *n;
  120. for (j = 1; j <= i__1; ++j) {
  121. i__2 = *n;
  122. for (i__ = j; i__ <= i__2; ++i__) {
  123. /* Computing MAX */
  124. d__2 = value, d__3 = (d__1 = a[i__ + j * a_dim1], abs(
  125. d__1));
  126. value = max(d__2,d__3);
  127. /* L30: */
  128. }
  129. /* L40: */
  130. }
  131. }
  132. } else if (_starpu_lsame_(norm, "I") || _starpu_lsame_(norm, "O") || *(unsigned char *)norm == '1') {
  133. /* Find normI(A) ( = norm1(A), since A is symmetric). */
  134. value = 0.;
  135. if (_starpu_lsame_(uplo, "U")) {
  136. i__1 = *n;
  137. for (j = 1; j <= i__1; ++j) {
  138. sum = 0.;
  139. i__2 = j - 1;
  140. for (i__ = 1; i__ <= i__2; ++i__) {
  141. absa = (d__1 = a[i__ + j * a_dim1], abs(d__1));
  142. sum += absa;
  143. work[i__] += absa;
  144. /* L50: */
  145. }
  146. work[j] = sum + (d__1 = a[j + j * a_dim1], abs(d__1));
  147. /* L60: */
  148. }
  149. i__1 = *n;
  150. for (i__ = 1; i__ <= i__1; ++i__) {
  151. /* Computing MAX */
  152. d__1 = value, d__2 = work[i__];
  153. value = max(d__1,d__2);
  154. /* L70: */
  155. }
  156. } else {
  157. i__1 = *n;
  158. for (i__ = 1; i__ <= i__1; ++i__) {
  159. work[i__] = 0.;
  160. /* L80: */
  161. }
  162. i__1 = *n;
  163. for (j = 1; j <= i__1; ++j) {
  164. sum = work[j] + (d__1 = a[j + j * a_dim1], abs(d__1));
  165. i__2 = *n;
  166. for (i__ = j + 1; i__ <= i__2; ++i__) {
  167. absa = (d__1 = a[i__ + j * a_dim1], abs(d__1));
  168. sum += absa;
  169. work[i__] += absa;
  170. /* L90: */
  171. }
  172. value = max(value,sum);
  173. /* L100: */
  174. }
  175. }
  176. } else if (_starpu_lsame_(norm, "F") || _starpu_lsame_(norm, "E")) {
  177. /* Find normF(A). */
  178. scale = 0.;
  179. sum = 1.;
  180. if (_starpu_lsame_(uplo, "U")) {
  181. i__1 = *n;
  182. for (j = 2; j <= i__1; ++j) {
  183. i__2 = j - 1;
  184. _starpu_dlassq_(&i__2, &a[j * a_dim1 + 1], &c__1, &scale, &sum);
  185. /* L110: */
  186. }
  187. } else {
  188. i__1 = *n - 1;
  189. for (j = 1; j <= i__1; ++j) {
  190. i__2 = *n - j;
  191. _starpu_dlassq_(&i__2, &a[j + 1 + j * a_dim1], &c__1, &scale, &sum);
  192. /* L120: */
  193. }
  194. }
  195. sum *= 2;
  196. i__1 = *lda + 1;
  197. _starpu_dlassq_(n, &a[a_offset], &i__1, &scale, &sum);
  198. value = scale * sqrt(sum);
  199. }
  200. ret_val = value;
  201. return ret_val;
  202. /* End of DLANSY */
  203. } /* _starpu_dlansy_ */