dsyrk.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. /* dsyrk.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 dsyrk_(char *uplo, char *trans, integer *n, integer *k,
  14. doublereal *alpha, doublereal *a, integer *lda, doublereal *beta,
  15. doublereal *c__, integer *ldc)
  16. {
  17. /* System generated locals */
  18. integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3;
  19. /* Local variables */
  20. integer i__, j, l, info;
  21. doublereal temp;
  22. extern logical lsame_(char *, char *);
  23. integer nrowa;
  24. logical upper;
  25. extern /* Subroutine */ int xerbla_(char *, integer *);
  26. /* .. Scalar Arguments .. */
  27. /* .. */
  28. /* .. Array Arguments .. */
  29. /* .. */
  30. /* Purpose */
  31. /* ======= */
  32. /* DSYRK performs one of the symmetric rank k operations */
  33. /* C := alpha*A*A' + beta*C, */
  34. /* or */
  35. /* C := alpha*A'*A + beta*C, */
  36. /* where alpha and beta are scalars, C is an n by n symmetric matrix */
  37. /* and A is an n by k matrix in the first case and a k by n matrix */
  38. /* in the second case. */
  39. /* Arguments */
  40. /* ========== */
  41. /* UPLO - CHARACTER*1. */
  42. /* On entry, UPLO specifies whether the upper or lower */
  43. /* triangular part of the array C is to be referenced as */
  44. /* follows: */
  45. /* UPLO = 'U' or 'u' Only the upper triangular part of C */
  46. /* is to be referenced. */
  47. /* UPLO = 'L' or 'l' Only the lower triangular part of C */
  48. /* is to be referenced. */
  49. /* Unchanged on exit. */
  50. /* TRANS - CHARACTER*1. */
  51. /* On entry, TRANS specifies the operation to be performed as */
  52. /* follows: */
  53. /* TRANS = 'N' or 'n' C := alpha*A*A' + beta*C. */
  54. /* TRANS = 'T' or 't' C := alpha*A'*A + beta*C. */
  55. /* TRANS = 'C' or 'c' C := alpha*A'*A + beta*C. */
  56. /* Unchanged on exit. */
  57. /* N - INTEGER. */
  58. /* On entry, N specifies the order of the matrix C. N must be */
  59. /* at least zero. */
  60. /* Unchanged on exit. */
  61. /* K - INTEGER. */
  62. /* On entry with TRANS = 'N' or 'n', K specifies the number */
  63. /* of columns of the matrix A, and on entry with */
  64. /* TRANS = 'T' or 't' or 'C' or 'c', K specifies the number */
  65. /* of rows of the matrix A. K must be at least zero. */
  66. /* Unchanged on exit. */
  67. /* ALPHA - DOUBLE PRECISION. */
  68. /* On entry, ALPHA specifies the scalar alpha. */
  69. /* Unchanged on exit. */
  70. /* A - DOUBLE PRECISION array of DIMENSION ( LDA, ka ), where ka is */
  71. /* k when TRANS = 'N' or 'n', and is n otherwise. */
  72. /* Before entry with TRANS = 'N' or 'n', the leading n by k */
  73. /* part of the array A must contain the matrix A, otherwise */
  74. /* the leading k by n part of the array A must contain the */
  75. /* matrix A. */
  76. /* Unchanged on exit. */
  77. /* LDA - INTEGER. */
  78. /* On entry, LDA specifies the first dimension of A as declared */
  79. /* in the calling (sub) program. When TRANS = 'N' or 'n' */
  80. /* then LDA must be at least max( 1, n ), otherwise LDA must */
  81. /* be at least max( 1, k ). */
  82. /* Unchanged on exit. */
  83. /* BETA - DOUBLE PRECISION. */
  84. /* On entry, BETA specifies the scalar beta. */
  85. /* Unchanged on exit. */
  86. /* C - DOUBLE PRECISION array of DIMENSION ( LDC, n ). */
  87. /* Before entry with UPLO = 'U' or 'u', the leading n by n */
  88. /* upper triangular part of the array C must contain the upper */
  89. /* triangular part of the symmetric matrix and the strictly */
  90. /* lower triangular part of C is not referenced. On exit, the */
  91. /* upper triangular part of the array C is overwritten by the */
  92. /* upper triangular part of the updated matrix. */
  93. /* Before entry with UPLO = 'L' or 'l', the leading n by n */
  94. /* lower triangular part of the array C must contain the lower */
  95. /* triangular part of the symmetric matrix and the strictly */
  96. /* upper triangular part of C is not referenced. On exit, the */
  97. /* lower triangular part of the array C is overwritten by the */
  98. /* lower triangular part of the updated matrix. */
  99. /* LDC - INTEGER. */
  100. /* On entry, LDC specifies the first dimension of C as declared */
  101. /* in the calling (sub) program. LDC must be at least */
  102. /* max( 1, n ). */
  103. /* Unchanged on exit. */
  104. /* Level 3 Blas routine. */
  105. /* -- Written on 8-February-1989. */
  106. /* Jack Dongarra, Argonne National Laboratory. */
  107. /* Iain Duff, AERE Harwell. */
  108. /* Jeremy Du Croz, Numerical Algorithms Group Ltd. */
  109. /* Sven Hammarling, Numerical Algorithms Group Ltd. */
  110. /* .. External Functions .. */
  111. /* .. */
  112. /* .. External Subroutines .. */
  113. /* .. */
  114. /* .. Intrinsic Functions .. */
  115. /* .. */
  116. /* .. Local Scalars .. */
  117. /* .. */
  118. /* .. Parameters .. */
  119. /* .. */
  120. /* Test the input parameters. */
  121. /* Parameter adjustments */
  122. a_dim1 = *lda;
  123. a_offset = 1 + a_dim1;
  124. a -= a_offset;
  125. c_dim1 = *ldc;
  126. c_offset = 1 + c_dim1;
  127. c__ -= c_offset;
  128. /* Function Body */
  129. if (lsame_(trans, "N")) {
  130. nrowa = *n;
  131. } else {
  132. nrowa = *k;
  133. }
  134. upper = lsame_(uplo, "U");
  135. info = 0;
  136. if (! upper && ! lsame_(uplo, "L")) {
  137. info = 1;
  138. } else if (! lsame_(trans, "N") && ! lsame_(trans,
  139. "T") && ! lsame_(trans, "C")) {
  140. info = 2;
  141. } else if (*n < 0) {
  142. info = 3;
  143. } else if (*k < 0) {
  144. info = 4;
  145. } else if (*lda < max(1,nrowa)) {
  146. info = 7;
  147. } else if (*ldc < max(1,*n)) {
  148. info = 10;
  149. }
  150. if (info != 0) {
  151. xerbla_("DSYRK ", &info);
  152. return 0;
  153. }
  154. /* Quick return if possible. */
  155. if (*n == 0 || (*alpha == 0. || *k == 0) && *beta == 1.) {
  156. return 0;
  157. }
  158. /* And when alpha.eq.zero. */
  159. if (*alpha == 0.) {
  160. if (upper) {
  161. if (*beta == 0.) {
  162. i__1 = *n;
  163. for (j = 1; j <= i__1; ++j) {
  164. i__2 = j;
  165. for (i__ = 1; i__ <= i__2; ++i__) {
  166. c__[i__ + j * c_dim1] = 0.;
  167. /* L10: */
  168. }
  169. /* L20: */
  170. }
  171. } else {
  172. i__1 = *n;
  173. for (j = 1; j <= i__1; ++j) {
  174. i__2 = j;
  175. for (i__ = 1; i__ <= i__2; ++i__) {
  176. c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
  177. /* L30: */
  178. }
  179. /* L40: */
  180. }
  181. }
  182. } else {
  183. if (*beta == 0.) {
  184. i__1 = *n;
  185. for (j = 1; j <= i__1; ++j) {
  186. i__2 = *n;
  187. for (i__ = j; i__ <= i__2; ++i__) {
  188. c__[i__ + j * c_dim1] = 0.;
  189. /* L50: */
  190. }
  191. /* L60: */
  192. }
  193. } else {
  194. i__1 = *n;
  195. for (j = 1; j <= i__1; ++j) {
  196. i__2 = *n;
  197. for (i__ = j; i__ <= i__2; ++i__) {
  198. c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
  199. /* L70: */
  200. }
  201. /* L80: */
  202. }
  203. }
  204. }
  205. return 0;
  206. }
  207. /* Start the operations. */
  208. if (lsame_(trans, "N")) {
  209. /* Form C := alpha*A*A' + beta*C. */
  210. if (upper) {
  211. i__1 = *n;
  212. for (j = 1; j <= i__1; ++j) {
  213. if (*beta == 0.) {
  214. i__2 = j;
  215. for (i__ = 1; i__ <= i__2; ++i__) {
  216. c__[i__ + j * c_dim1] = 0.;
  217. /* L90: */
  218. }
  219. } else if (*beta != 1.) {
  220. i__2 = j;
  221. for (i__ = 1; i__ <= i__2; ++i__) {
  222. c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
  223. /* L100: */
  224. }
  225. }
  226. i__2 = *k;
  227. for (l = 1; l <= i__2; ++l) {
  228. if (a[j + l * a_dim1] != 0.) {
  229. temp = *alpha * a[j + l * a_dim1];
  230. i__3 = j;
  231. for (i__ = 1; i__ <= i__3; ++i__) {
  232. c__[i__ + j * c_dim1] += temp * a[i__ + l *
  233. a_dim1];
  234. /* L110: */
  235. }
  236. }
  237. /* L120: */
  238. }
  239. /* L130: */
  240. }
  241. } else {
  242. i__1 = *n;
  243. for (j = 1; j <= i__1; ++j) {
  244. if (*beta == 0.) {
  245. i__2 = *n;
  246. for (i__ = j; i__ <= i__2; ++i__) {
  247. c__[i__ + j * c_dim1] = 0.;
  248. /* L140: */
  249. }
  250. } else if (*beta != 1.) {
  251. i__2 = *n;
  252. for (i__ = j; i__ <= i__2; ++i__) {
  253. c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
  254. /* L150: */
  255. }
  256. }
  257. i__2 = *k;
  258. for (l = 1; l <= i__2; ++l) {
  259. if (a[j + l * a_dim1] != 0.) {
  260. temp = *alpha * a[j + l * a_dim1];
  261. i__3 = *n;
  262. for (i__ = j; i__ <= i__3; ++i__) {
  263. c__[i__ + j * c_dim1] += temp * a[i__ + l *
  264. a_dim1];
  265. /* L160: */
  266. }
  267. }
  268. /* L170: */
  269. }
  270. /* L180: */
  271. }
  272. }
  273. } else {
  274. /* Form C := alpha*A'*A + beta*C. */
  275. if (upper) {
  276. i__1 = *n;
  277. for (j = 1; j <= i__1; ++j) {
  278. i__2 = j;
  279. for (i__ = 1; i__ <= i__2; ++i__) {
  280. temp = 0.;
  281. i__3 = *k;
  282. for (l = 1; l <= i__3; ++l) {
  283. temp += a[l + i__ * a_dim1] * a[l + j * a_dim1];
  284. /* L190: */
  285. }
  286. if (*beta == 0.) {
  287. c__[i__ + j * c_dim1] = *alpha * temp;
  288. } else {
  289. c__[i__ + j * c_dim1] = *alpha * temp + *beta * c__[
  290. i__ + j * c_dim1];
  291. }
  292. /* L200: */
  293. }
  294. /* L210: */
  295. }
  296. } else {
  297. i__1 = *n;
  298. for (j = 1; j <= i__1; ++j) {
  299. i__2 = *n;
  300. for (i__ = j; i__ <= i__2; ++i__) {
  301. temp = 0.;
  302. i__3 = *k;
  303. for (l = 1; l <= i__3; ++l) {
  304. temp += a[l + i__ * a_dim1] * a[l + j * a_dim1];
  305. /* L220: */
  306. }
  307. if (*beta == 0.) {
  308. c__[i__ + j * c_dim1] = *alpha * temp;
  309. } else {
  310. c__[i__ + j * c_dim1] = *alpha * temp + *beta * c__[
  311. i__ + j * c_dim1];
  312. }
  313. /* L230: */
  314. }
  315. /* L240: */
  316. }
  317. }
  318. }
  319. return 0;
  320. /* End of DSYRK . */
  321. } /* dsyrk_ */