dspr2.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* dspr2.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 dspr2_(char *uplo, integer *n, doublereal *alpha,
  14. doublereal *x, integer *incx, doublereal *y, integer *incy,
  15. doublereal *ap)
  16. {
  17. /* System generated locals */
  18. integer i__1, i__2;
  19. /* Local variables */
  20. integer i__, j, k, kk, ix, iy, jx, jy, kx, ky, info;
  21. doublereal temp1, temp2;
  22. extern logical lsame_(char *, char *);
  23. extern /* Subroutine */ int xerbla_(char *, integer *);
  24. /* .. Scalar Arguments .. */
  25. /* .. */
  26. /* .. Array Arguments .. */
  27. /* .. */
  28. /* Purpose */
  29. /* ======= */
  30. /* DSPR2 performs the symmetric rank 2 operation */
  31. /* A := alpha*x*y' + alpha*y*x' + A, */
  32. /* where alpha is a scalar, x and y are n element vectors and A is an */
  33. /* n by n symmetric matrix, supplied in packed form. */
  34. /* Arguments */
  35. /* ========== */
  36. /* UPLO - CHARACTER*1. */
  37. /* On entry, UPLO specifies whether the upper or lower */
  38. /* triangular part of the matrix A is supplied in the packed */
  39. /* array AP as follows: */
  40. /* UPLO = 'U' or 'u' The upper triangular part of A is */
  41. /* supplied in AP. */
  42. /* UPLO = 'L' or 'l' The lower triangular part of A is */
  43. /* supplied in AP. */
  44. /* Unchanged on exit. */
  45. /* N - INTEGER. */
  46. /* On entry, N specifies the order of the matrix A. */
  47. /* N must be at least zero. */
  48. /* Unchanged on exit. */
  49. /* ALPHA - DOUBLE PRECISION. */
  50. /* On entry, ALPHA specifies the scalar alpha. */
  51. /* Unchanged on exit. */
  52. /* X - DOUBLE PRECISION array of dimension at least */
  53. /* ( 1 + ( n - 1 )*abs( INCX ) ). */
  54. /* Before entry, the incremented array X must contain the n */
  55. /* element vector x. */
  56. /* Unchanged on exit. */
  57. /* INCX - INTEGER. */
  58. /* On entry, INCX specifies the increment for the elements of */
  59. /* X. INCX must not be zero. */
  60. /* Unchanged on exit. */
  61. /* Y - DOUBLE PRECISION array of dimension at least */
  62. /* ( 1 + ( n - 1 )*abs( INCY ) ). */
  63. /* Before entry, the incremented array Y must contain the n */
  64. /* element vector y. */
  65. /* Unchanged on exit. */
  66. /* INCY - INTEGER. */
  67. /* On entry, INCY specifies the increment for the elements of */
  68. /* Y. INCY must not be zero. */
  69. /* Unchanged on exit. */
  70. /* AP - DOUBLE PRECISION array of DIMENSION at least */
  71. /* ( ( n*( n + 1 ) )/2 ). */
  72. /* Before entry with UPLO = 'U' or 'u', the array AP must */
  73. /* contain the upper triangular part of the symmetric matrix */
  74. /* packed sequentially, column by column, so that AP( 1 ) */
  75. /* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 1, 2 ) */
  76. /* and a( 2, 2 ) respectively, and so on. On exit, the array */
  77. /* AP is overwritten by the upper triangular part of the */
  78. /* updated matrix. */
  79. /* Before entry with UPLO = 'L' or 'l', the array AP must */
  80. /* contain the lower triangular part of the symmetric matrix */
  81. /* packed sequentially, column by column, so that AP( 1 ) */
  82. /* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 2, 1 ) */
  83. /* and a( 3, 1 ) respectively, and so on. On exit, the array */
  84. /* AP is overwritten by the lower triangular part of the */
  85. /* updated matrix. */
  86. /* Level 2 Blas routine. */
  87. /* -- Written on 22-October-1986. */
  88. /* Jack Dongarra, Argonne National Lab. */
  89. /* Jeremy Du Croz, Nag Central Office. */
  90. /* Sven Hammarling, Nag Central Office. */
  91. /* Richard Hanson, Sandia National Labs. */
  92. /* .. Parameters .. */
  93. /* .. */
  94. /* .. Local Scalars .. */
  95. /* .. */
  96. /* .. External Functions .. */
  97. /* .. */
  98. /* .. External Subroutines .. */
  99. /* .. */
  100. /* Test the input parameters. */
  101. /* Parameter adjustments */
  102. --ap;
  103. --y;
  104. --x;
  105. /* Function Body */
  106. info = 0;
  107. if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
  108. info = 1;
  109. } else if (*n < 0) {
  110. info = 2;
  111. } else if (*incx == 0) {
  112. info = 5;
  113. } else if (*incy == 0) {
  114. info = 7;
  115. }
  116. if (info != 0) {
  117. xerbla_("DSPR2 ", &info);
  118. return 0;
  119. }
  120. /* Quick return if possible. */
  121. if (*n == 0 || *alpha == 0.) {
  122. return 0;
  123. }
  124. /* Set up the start points in X and Y if the increments are not both */
  125. /* unity. */
  126. if (*incx != 1 || *incy != 1) {
  127. if (*incx > 0) {
  128. kx = 1;
  129. } else {
  130. kx = 1 - (*n - 1) * *incx;
  131. }
  132. if (*incy > 0) {
  133. ky = 1;
  134. } else {
  135. ky = 1 - (*n - 1) * *incy;
  136. }
  137. jx = kx;
  138. jy = ky;
  139. }
  140. /* Start the operations. In this version the elements of the array AP */
  141. /* are accessed sequentially with one pass through AP. */
  142. kk = 1;
  143. if (lsame_(uplo, "U")) {
  144. /* Form A when upper triangle is stored in AP. */
  145. if (*incx == 1 && *incy == 1) {
  146. i__1 = *n;
  147. for (j = 1; j <= i__1; ++j) {
  148. if (x[j] != 0. || y[j] != 0.) {
  149. temp1 = *alpha * y[j];
  150. temp2 = *alpha * x[j];
  151. k = kk;
  152. i__2 = j;
  153. for (i__ = 1; i__ <= i__2; ++i__) {
  154. ap[k] = ap[k] + x[i__] * temp1 + y[i__] * temp2;
  155. ++k;
  156. /* L10: */
  157. }
  158. }
  159. kk += j;
  160. /* L20: */
  161. }
  162. } else {
  163. i__1 = *n;
  164. for (j = 1; j <= i__1; ++j) {
  165. if (x[jx] != 0. || y[jy] != 0.) {
  166. temp1 = *alpha * y[jy];
  167. temp2 = *alpha * x[jx];
  168. ix = kx;
  169. iy = ky;
  170. i__2 = kk + j - 1;
  171. for (k = kk; k <= i__2; ++k) {
  172. ap[k] = ap[k] + x[ix] * temp1 + y[iy] * temp2;
  173. ix += *incx;
  174. iy += *incy;
  175. /* L30: */
  176. }
  177. }
  178. jx += *incx;
  179. jy += *incy;
  180. kk += j;
  181. /* L40: */
  182. }
  183. }
  184. } else {
  185. /* Form A when lower triangle is stored in AP. */
  186. if (*incx == 1 && *incy == 1) {
  187. i__1 = *n;
  188. for (j = 1; j <= i__1; ++j) {
  189. if (x[j] != 0. || y[j] != 0.) {
  190. temp1 = *alpha * y[j];
  191. temp2 = *alpha * x[j];
  192. k = kk;
  193. i__2 = *n;
  194. for (i__ = j; i__ <= i__2; ++i__) {
  195. ap[k] = ap[k] + x[i__] * temp1 + y[i__] * temp2;
  196. ++k;
  197. /* L50: */
  198. }
  199. }
  200. kk = kk + *n - j + 1;
  201. /* L60: */
  202. }
  203. } else {
  204. i__1 = *n;
  205. for (j = 1; j <= i__1; ++j) {
  206. if (x[jx] != 0. || y[jy] != 0.) {
  207. temp1 = *alpha * y[jy];
  208. temp2 = *alpha * x[jx];
  209. ix = jx;
  210. iy = jy;
  211. i__2 = kk + *n - j;
  212. for (k = kk; k <= i__2; ++k) {
  213. ap[k] = ap[k] + x[ix] * temp1 + y[iy] * temp2;
  214. ix += *incx;
  215. iy += *incy;
  216. /* L70: */
  217. }
  218. }
  219. jx += *incx;
  220. jy += *incy;
  221. kk = kk + *n - j + 1;
  222. /* L80: */
  223. }
  224. }
  225. }
  226. return 0;
  227. /* End of DSPR2 . */
  228. } /* dspr2_ */