dlansp.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /* dlansp.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_dlansp_(char *norm, char *uplo, integer *n, doublereal *ap,
  16. doublereal *work)
  17. {
  18. /* System generated locals */
  19. integer 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, k;
  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. /* DLANSP 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, supplied in packed form. */
  42. /* Description */
  43. /* =========== */
  44. /* DLANSP returns the value */
  45. /* DLANSP = ( 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 DLANSP 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 supplied. */
  64. /* = 'U': Upper triangular part of A is supplied */
  65. /* = 'L': Lower triangular part of A is supplied */
  66. /* N (input) INTEGER */
  67. /* The order of the matrix A. N >= 0. When N = 0, DLANSP is */
  68. /* set to zero. */
  69. /* AP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
  70. /* The upper or lower triangle of the symmetric matrix A, packed */
  71. /* columnwise in a linear array. The j-th column of A is stored */
  72. /* in the array AP as follows: */
  73. /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
  74. /* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
  75. /* WORK (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)), */
  76. /* where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise, */
  77. /* WORK is not referenced. */
  78. /* ===================================================================== */
  79. /* .. Parameters .. */
  80. /* .. */
  81. /* .. Local Scalars .. */
  82. /* .. */
  83. /* .. External Subroutines .. */
  84. /* .. */
  85. /* .. External Functions .. */
  86. /* .. */
  87. /* .. Intrinsic Functions .. */
  88. /* .. */
  89. /* .. Executable Statements .. */
  90. /* Parameter adjustments */
  91. --work;
  92. --ap;
  93. /* Function Body */
  94. if (*n == 0) {
  95. value = 0.;
  96. } else if (_starpu_lsame_(norm, "M")) {
  97. /* Find max(abs(A(i,j))). */
  98. value = 0.;
  99. if (_starpu_lsame_(uplo, "U")) {
  100. k = 1;
  101. i__1 = *n;
  102. for (j = 1; j <= i__1; ++j) {
  103. i__2 = k + j - 1;
  104. for (i__ = k; i__ <= i__2; ++i__) {
  105. /* Computing MAX */
  106. d__2 = value, d__3 = (d__1 = ap[i__], abs(d__1));
  107. value = max(d__2,d__3);
  108. /* L10: */
  109. }
  110. k += j;
  111. /* L20: */
  112. }
  113. } else {
  114. k = 1;
  115. i__1 = *n;
  116. for (j = 1; j <= i__1; ++j) {
  117. i__2 = k + *n - j;
  118. for (i__ = k; i__ <= i__2; ++i__) {
  119. /* Computing MAX */
  120. d__2 = value, d__3 = (d__1 = ap[i__], abs(d__1));
  121. value = max(d__2,d__3);
  122. /* L30: */
  123. }
  124. k = k + *n - j + 1;
  125. /* L40: */
  126. }
  127. }
  128. } else if (_starpu_lsame_(norm, "I") || _starpu_lsame_(norm, "O") || *(unsigned char *)norm == '1') {
  129. /* Find normI(A) ( = norm1(A), since A is symmetric). */
  130. value = 0.;
  131. k = 1;
  132. if (_starpu_lsame_(uplo, "U")) {
  133. i__1 = *n;
  134. for (j = 1; j <= i__1; ++j) {
  135. sum = 0.;
  136. i__2 = j - 1;
  137. for (i__ = 1; i__ <= i__2; ++i__) {
  138. absa = (d__1 = ap[k], abs(d__1));
  139. sum += absa;
  140. work[i__] += absa;
  141. ++k;
  142. /* L50: */
  143. }
  144. work[j] = sum + (d__1 = ap[k], abs(d__1));
  145. ++k;
  146. /* L60: */
  147. }
  148. i__1 = *n;
  149. for (i__ = 1; i__ <= i__1; ++i__) {
  150. /* Computing MAX */
  151. d__1 = value, d__2 = work[i__];
  152. value = max(d__1,d__2);
  153. /* L70: */
  154. }
  155. } else {
  156. i__1 = *n;
  157. for (i__ = 1; i__ <= i__1; ++i__) {
  158. work[i__] = 0.;
  159. /* L80: */
  160. }
  161. i__1 = *n;
  162. for (j = 1; j <= i__1; ++j) {
  163. sum = work[j] + (d__1 = ap[k], abs(d__1));
  164. ++k;
  165. i__2 = *n;
  166. for (i__ = j + 1; i__ <= i__2; ++i__) {
  167. absa = (d__1 = ap[k], abs(d__1));
  168. sum += absa;
  169. work[i__] += absa;
  170. ++k;
  171. /* L90: */
  172. }
  173. value = max(value,sum);
  174. /* L100: */
  175. }
  176. }
  177. } else if (_starpu_lsame_(norm, "F") || _starpu_lsame_(norm, "E")) {
  178. /* Find normF(A). */
  179. scale = 0.;
  180. sum = 1.;
  181. k = 2;
  182. if (_starpu_lsame_(uplo, "U")) {
  183. i__1 = *n;
  184. for (j = 2; j <= i__1; ++j) {
  185. i__2 = j - 1;
  186. _starpu_dlassq_(&i__2, &ap[k], &c__1, &scale, &sum);
  187. k += j;
  188. /* L110: */
  189. }
  190. } else {
  191. i__1 = *n - 1;
  192. for (j = 1; j <= i__1; ++j) {
  193. i__2 = *n - j;
  194. _starpu_dlassq_(&i__2, &ap[k], &c__1, &scale, &sum);
  195. k = k + *n - j + 1;
  196. /* L120: */
  197. }
  198. }
  199. sum *= 2;
  200. k = 1;
  201. i__1 = *n;
  202. for (i__ = 1; i__ <= i__1; ++i__) {
  203. if (ap[k] != 0.) {
  204. absa = (d__1 = ap[k], abs(d__1));
  205. if (scale < absa) {
  206. /* Computing 2nd power */
  207. d__1 = scale / absa;
  208. sum = sum * (d__1 * d__1) + 1.;
  209. scale = absa;
  210. } else {
  211. /* Computing 2nd power */
  212. d__1 = absa / scale;
  213. sum += d__1 * d__1;
  214. }
  215. }
  216. if (_starpu_lsame_(uplo, "U")) {
  217. k = k + i__ + 1;
  218. } else {
  219. k = k + *n - i__ + 1;
  220. }
  221. /* L130: */
  222. }
  223. value = scale * sqrt(sum);
  224. }
  225. ret_val = value;
  226. return ret_val;
  227. /* End of DLANSP */
  228. } /* _starpu_dlansp_ */