stpmv.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /* stpmv.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 stpmv_(char *uplo, char *trans, char *diag, integer *n,
  14. real *ap, real *x, integer *incx)
  15. {
  16. /* System generated locals */
  17. integer i__1, i__2;
  18. /* Local variables */
  19. integer i__, j, k, kk, ix, jx, kx, info;
  20. real temp;
  21. extern logical lsame_(char *, char *);
  22. extern /* Subroutine */ int xerbla_(char *, integer *);
  23. logical nounit;
  24. /* .. Scalar Arguments .. */
  25. /* .. */
  26. /* .. Array Arguments .. */
  27. /* .. */
  28. /* Purpose */
  29. /* ======= */
  30. /* STPMV performs one of the matrix-vector operations */
  31. /* x := A*x, or x := A'*x, */
  32. /* where x is an n element vector and A is an n by n unit, or non-unit, */
  33. /* upper or lower triangular matrix, supplied in packed form. */
  34. /* Arguments */
  35. /* ========== */
  36. /* UPLO - CHARACTER*1. */
  37. /* On entry, UPLO specifies whether the matrix is an upper or */
  38. /* lower triangular matrix as follows: */
  39. /* UPLO = 'U' or 'u' A is an upper triangular matrix. */
  40. /* UPLO = 'L' or 'l' A is a lower triangular matrix. */
  41. /* Unchanged on exit. */
  42. /* TRANS - CHARACTER*1. */
  43. /* On entry, TRANS specifies the operation to be performed as */
  44. /* follows: */
  45. /* TRANS = 'N' or 'n' x := A*x. */
  46. /* TRANS = 'T' or 't' x := A'*x. */
  47. /* TRANS = 'C' or 'c' x := A'*x. */
  48. /* Unchanged on exit. */
  49. /* DIAG - CHARACTER*1. */
  50. /* On entry, DIAG specifies whether or not A is unit */
  51. /* triangular as follows: */
  52. /* DIAG = 'U' or 'u' A is assumed to be unit triangular. */
  53. /* DIAG = 'N' or 'n' A is not assumed to be unit */
  54. /* triangular. */
  55. /* Unchanged on exit. */
  56. /* N - INTEGER. */
  57. /* On entry, N specifies the order of the matrix A. */
  58. /* N must be at least zero. */
  59. /* Unchanged on exit. */
  60. /* AP - REAL array of DIMENSION at least */
  61. /* ( ( n*( n + 1 ) )/2 ). */
  62. /* Before entry with UPLO = 'U' or 'u', the array AP must */
  63. /* contain the upper triangular matrix packed sequentially, */
  64. /* column by column, so that AP( 1 ) contains a( 1, 1 ), */
  65. /* AP( 2 ) and AP( 3 ) contain a( 1, 2 ) and a( 2, 2 ) */
  66. /* respectively, and so on. */
  67. /* Before entry with UPLO = 'L' or 'l', the array AP must */
  68. /* contain the lower triangular matrix packed sequentially, */
  69. /* column by column, so that AP( 1 ) contains a( 1, 1 ), */
  70. /* AP( 2 ) and AP( 3 ) contain a( 2, 1 ) and a( 3, 1 ) */
  71. /* respectively, and so on. */
  72. /* Note that when DIAG = 'U' or 'u', the diagonal elements of */
  73. /* A are not referenced, but are assumed to be unity. */
  74. /* Unchanged on exit. */
  75. /* X - REAL array of dimension at least */
  76. /* ( 1 + ( n - 1 )*abs( INCX ) ). */
  77. /* Before entry, the incremented array X must contain the n */
  78. /* element vector x. On exit, X is overwritten with the */
  79. /* tranformed vector x. */
  80. /* INCX - INTEGER. */
  81. /* On entry, INCX specifies the increment for the elements of */
  82. /* X. INCX must not be zero. */
  83. /* Unchanged on exit. */
  84. /* Level 2 Blas routine. */
  85. /* -- Written on 22-October-1986. */
  86. /* Jack Dongarra, Argonne National Lab. */
  87. /* Jeremy Du Croz, Nag Central Office. */
  88. /* Sven Hammarling, Nag Central Office. */
  89. /* Richard Hanson, Sandia National Labs. */
  90. /* .. Parameters .. */
  91. /* .. */
  92. /* .. Local Scalars .. */
  93. /* .. */
  94. /* .. External Functions .. */
  95. /* .. */
  96. /* .. External Subroutines .. */
  97. /* .. */
  98. /* Test the input parameters. */
  99. /* Parameter adjustments */
  100. --x;
  101. --ap;
  102. /* Function Body */
  103. info = 0;
  104. if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
  105. info = 1;
  106. } else if (! lsame_(trans, "N") && ! lsame_(trans,
  107. "T") && ! lsame_(trans, "C")) {
  108. info = 2;
  109. } else if (! lsame_(diag, "U") && ! lsame_(diag,
  110. "N")) {
  111. info = 3;
  112. } else if (*n < 0) {
  113. info = 4;
  114. } else if (*incx == 0) {
  115. info = 7;
  116. }
  117. if (info != 0) {
  118. xerbla_("STPMV ", &info);
  119. return 0;
  120. }
  121. /* Quick return if possible. */
  122. if (*n == 0) {
  123. return 0;
  124. }
  125. nounit = lsame_(diag, "N");
  126. /* Set up the start point in X if the increment is not unity. This */
  127. /* will be ( N - 1 )*INCX too small for descending loops. */
  128. if (*incx <= 0) {
  129. kx = 1 - (*n - 1) * *incx;
  130. } else if (*incx != 1) {
  131. kx = 1;
  132. }
  133. /* Start the operations. In this version the elements of AP are */
  134. /* accessed sequentially with one pass through AP. */
  135. if (lsame_(trans, "N")) {
  136. /* Form x:= A*x. */
  137. if (lsame_(uplo, "U")) {
  138. kk = 1;
  139. if (*incx == 1) {
  140. i__1 = *n;
  141. for (j = 1; j <= i__1; ++j) {
  142. if (x[j] != 0.f) {
  143. temp = x[j];
  144. k = kk;
  145. i__2 = j - 1;
  146. for (i__ = 1; i__ <= i__2; ++i__) {
  147. x[i__] += temp * ap[k];
  148. ++k;
  149. /* L10: */
  150. }
  151. if (nounit) {
  152. x[j] *= ap[kk + j - 1];
  153. }
  154. }
  155. kk += j;
  156. /* L20: */
  157. }
  158. } else {
  159. jx = kx;
  160. i__1 = *n;
  161. for (j = 1; j <= i__1; ++j) {
  162. if (x[jx] != 0.f) {
  163. temp = x[jx];
  164. ix = kx;
  165. i__2 = kk + j - 2;
  166. for (k = kk; k <= i__2; ++k) {
  167. x[ix] += temp * ap[k];
  168. ix += *incx;
  169. /* L30: */
  170. }
  171. if (nounit) {
  172. x[jx] *= ap[kk + j - 1];
  173. }
  174. }
  175. jx += *incx;
  176. kk += j;
  177. /* L40: */
  178. }
  179. }
  180. } else {
  181. kk = *n * (*n + 1) / 2;
  182. if (*incx == 1) {
  183. for (j = *n; j >= 1; --j) {
  184. if (x[j] != 0.f) {
  185. temp = x[j];
  186. k = kk;
  187. i__1 = j + 1;
  188. for (i__ = *n; i__ >= i__1; --i__) {
  189. x[i__] += temp * ap[k];
  190. --k;
  191. /* L50: */
  192. }
  193. if (nounit) {
  194. x[j] *= ap[kk - *n + j];
  195. }
  196. }
  197. kk -= *n - j + 1;
  198. /* L60: */
  199. }
  200. } else {
  201. kx += (*n - 1) * *incx;
  202. jx = kx;
  203. for (j = *n; j >= 1; --j) {
  204. if (x[jx] != 0.f) {
  205. temp = x[jx];
  206. ix = kx;
  207. i__1 = kk - (*n - (j + 1));
  208. for (k = kk; k >= i__1; --k) {
  209. x[ix] += temp * ap[k];
  210. ix -= *incx;
  211. /* L70: */
  212. }
  213. if (nounit) {
  214. x[jx] *= ap[kk - *n + j];
  215. }
  216. }
  217. jx -= *incx;
  218. kk -= *n - j + 1;
  219. /* L80: */
  220. }
  221. }
  222. }
  223. } else {
  224. /* Form x := A'*x. */
  225. if (lsame_(uplo, "U")) {
  226. kk = *n * (*n + 1) / 2;
  227. if (*incx == 1) {
  228. for (j = *n; j >= 1; --j) {
  229. temp = x[j];
  230. if (nounit) {
  231. temp *= ap[kk];
  232. }
  233. k = kk - 1;
  234. for (i__ = j - 1; i__ >= 1; --i__) {
  235. temp += ap[k] * x[i__];
  236. --k;
  237. /* L90: */
  238. }
  239. x[j] = temp;
  240. kk -= j;
  241. /* L100: */
  242. }
  243. } else {
  244. jx = kx + (*n - 1) * *incx;
  245. for (j = *n; j >= 1; --j) {
  246. temp = x[jx];
  247. ix = jx;
  248. if (nounit) {
  249. temp *= ap[kk];
  250. }
  251. i__1 = kk - j + 1;
  252. for (k = kk - 1; k >= i__1; --k) {
  253. ix -= *incx;
  254. temp += ap[k] * x[ix];
  255. /* L110: */
  256. }
  257. x[jx] = temp;
  258. jx -= *incx;
  259. kk -= j;
  260. /* L120: */
  261. }
  262. }
  263. } else {
  264. kk = 1;
  265. if (*incx == 1) {
  266. i__1 = *n;
  267. for (j = 1; j <= i__1; ++j) {
  268. temp = x[j];
  269. if (nounit) {
  270. temp *= ap[kk];
  271. }
  272. k = kk + 1;
  273. i__2 = *n;
  274. for (i__ = j + 1; i__ <= i__2; ++i__) {
  275. temp += ap[k] * x[i__];
  276. ++k;
  277. /* L130: */
  278. }
  279. x[j] = temp;
  280. kk += *n - j + 1;
  281. /* L140: */
  282. }
  283. } else {
  284. jx = kx;
  285. i__1 = *n;
  286. for (j = 1; j <= i__1; ++j) {
  287. temp = x[jx];
  288. ix = jx;
  289. if (nounit) {
  290. temp *= ap[kk];
  291. }
  292. i__2 = kk + *n - j;
  293. for (k = kk + 1; k <= i__2; ++k) {
  294. ix += *incx;
  295. temp += ap[k] * x[ix];
  296. /* L150: */
  297. }
  298. x[jx] = temp;
  299. jx += *incx;
  300. kk += *n - j + 1;
  301. /* L160: */
  302. }
  303. }
  304. }
  305. }
  306. return 0;
  307. /* End of STPMV . */
  308. } /* stpmv_ */