/lib/perf/dtbmv.c

https://github.com/mattkoes/antelope_contrib · C · 348 lines · 213 code · 2 blank · 133 comment · 78 complexity · 6f3d194680e4fda5468d456a28dbbf8a MD5 · raw file

  1. #include "blaswrap.h"
  2. #include "f2c.h"
  3. /* Subroutine */ int dtbmv_(char *uplo, char *trans, char *diag, integer *n,
  4. integer *k, doublereal *a, integer *lda, doublereal *x, integer *incx)
  5. {
  6. /* System generated locals */
  7. integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
  8. /* Local variables */
  9. static integer info;
  10. static doublereal temp;
  11. static integer i__, j, l;
  12. extern logical lsame_(char *, char *);
  13. static integer kplus1, ix, jx, kx;
  14. extern /* Subroutine */ int xerbla_(char *, integer *);
  15. static logical nounit;
  16. #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1]
  17. /* Purpose
  18. =======
  19. DTBMV performs one of the matrix-vector operations
  20. x := A*x, or x := A'*x,
  21. where x is an n element vector and A is an n by n unit, or non-unit,
  22. upper or lower triangular band matrix, with ( k + 1 ) diagonals.
  23. Parameters
  24. ==========
  25. UPLO - CHARACTER*1.
  26. On entry, UPLO specifies whether the matrix is an upper or
  27. lower triangular matrix as follows:
  28. UPLO = 'U' or 'u' A is an upper triangular matrix.
  29. UPLO = 'L' or 'l' A is a lower triangular matrix.
  30. Unchanged on exit.
  31. TRANS - CHARACTER*1.
  32. On entry, TRANS specifies the operation to be performed as
  33. follows:
  34. TRANS = 'N' or 'n' x := A*x.
  35. TRANS = 'T' or 't' x := A'*x.
  36. TRANS = 'C' or 'c' x := A'*x.
  37. Unchanged on exit.
  38. DIAG - CHARACTER*1.
  39. On entry, DIAG specifies whether or not A is unit
  40. triangular as follows:
  41. DIAG = 'U' or 'u' A is assumed to be unit triangular.
  42. DIAG = 'N' or 'n' A is not assumed to be unit
  43. triangular.
  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. K - INTEGER.
  50. On entry with UPLO = 'U' or 'u', K specifies the number of
  51. super-diagonals of the matrix A.
  52. On entry with UPLO = 'L' or 'l', K specifies the number of
  53. sub-diagonals of the matrix A.
  54. K must satisfy 0 .le. K.
  55. Unchanged on exit.
  56. A - DOUBLE PRECISION array of DIMENSION ( LDA, n ).
  57. Before entry with UPLO = 'U' or 'u', the leading ( k + 1 )
  58. by n part of the array A must contain the upper triangular
  59. band part of the matrix of coefficients, supplied column by
  60. column, with the leading diagonal of the matrix in row
  61. ( k + 1 ) of the array, the first super-diagonal starting at
  62. position 2 in row k, and so on. The top left k by k triangle
  63. of the array A is not referenced.
  64. The following program segment will transfer an upper
  65. triangular band matrix from conventional full matrix storage
  66. to band storage:
  67. DO 20, J = 1, N
  68. M = K + 1 - J
  69. DO 10, I = MAX( 1, J - K ), J
  70. A( M + I, J ) = matrix( I, J )
  71. 10 CONTINUE
  72. 20 CONTINUE
  73. Before entry with UPLO = 'L' or 'l', the leading ( k + 1 )
  74. by n part of the array A must contain the lower triangular
  75. band part of the matrix of coefficients, supplied column by
  76. column, with the leading diagonal of the matrix in row 1 of
  77. the array, the first sub-diagonal starting at position 1 in
  78. row 2, and so on. The bottom right k by k triangle of the
  79. array A is not referenced.
  80. The following program segment will transfer a lower
  81. triangular band matrix from conventional full matrix storage
  82. to band storage:
  83. DO 20, J = 1, N
  84. M = 1 - J
  85. DO 10, I = J, MIN( N, J + K )
  86. A( M + I, J ) = matrix( I, J )
  87. 10 CONTINUE
  88. 20 CONTINUE
  89. Note that when DIAG = 'U' or 'u' the elements of the array A
  90. corresponding to the diagonal elements of the matrix are not
  91. referenced, but are assumed to be unity.
  92. Unchanged on exit.
  93. LDA - INTEGER.
  94. On entry, LDA specifies the first dimension of A as declared
  95. in the calling (sub) program. LDA must be at least
  96. ( k + 1 ).
  97. Unchanged on exit.
  98. X - DOUBLE PRECISION array of dimension at least
  99. ( 1 + ( n - 1 )*abs( INCX ) ).
  100. Before entry, the incremented array X must contain the n
  101. element vector x. On exit, X is overwritten with the
  102. tranformed vector x.
  103. INCX - INTEGER.
  104. On entry, INCX specifies the increment for the elements of
  105. X. INCX must not be zero.
  106. Unchanged on exit.
  107. Level 2 Blas routine.
  108. -- Written on 22-October-1986.
  109. Jack Dongarra, Argonne National Lab.
  110. Jeremy Du Croz, Nag Central Office.
  111. Sven Hammarling, Nag Central Office.
  112. Richard Hanson, Sandia National Labs.
  113. Test the input parameters.
  114. Parameter adjustments */
  115. a_dim1 = *lda;
  116. a_offset = 1 + a_dim1 * 1;
  117. a -= a_offset;
  118. --x;
  119. /* Function Body */
  120. info = 0;
  121. if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
  122. info = 1;
  123. } else if (! lsame_(trans, "N") && ! lsame_(trans,
  124. "T") && ! lsame_(trans, "C")) {
  125. info = 2;
  126. } else if (! lsame_(diag, "U") && ! lsame_(diag,
  127. "N")) {
  128. info = 3;
  129. } else if (*n < 0) {
  130. info = 4;
  131. } else if (*k < 0) {
  132. info = 5;
  133. } else if (*lda < *k + 1) {
  134. info = 7;
  135. } else if (*incx == 0) {
  136. info = 9;
  137. }
  138. if (info != 0) {
  139. xerbla_("DTBMV ", &info);
  140. return 0;
  141. }
  142. /* Quick return if possible. */
  143. if (*n == 0) {
  144. return 0;
  145. }
  146. nounit = lsame_(diag, "N");
  147. /* Set up the start point in X if the increment is not unity. This
  148. will be ( N - 1 )*INCX too small for descending loops. */
  149. if (*incx <= 0) {
  150. kx = 1 - (*n - 1) * *incx;
  151. } else if (*incx != 1) {
  152. kx = 1;
  153. }
  154. /* Start the operations. In this version the elements of A are
  155. accessed sequentially with one pass through A. */
  156. if (lsame_(trans, "N")) {
  157. /* Form x := A*x. */
  158. if (lsame_(uplo, "U")) {
  159. kplus1 = *k + 1;
  160. if (*incx == 1) {
  161. i__1 = *n;
  162. for (j = 1; j <= i__1; ++j) {
  163. if (x[j] != 0.) {
  164. temp = x[j];
  165. l = kplus1 - j;
  166. /* Computing MAX */
  167. i__2 = 1, i__3 = j - *k;
  168. i__4 = j - 1;
  169. for (i__ = max(i__2,i__3); i__ <= i__4; ++i__) {
  170. x[i__] += temp * a_ref(l + i__, j);
  171. /* L10: */
  172. }
  173. if (nounit) {
  174. x[j] *= a_ref(kplus1, j);
  175. }
  176. }
  177. /* L20: */
  178. }
  179. } else {
  180. jx = kx;
  181. i__1 = *n;
  182. for (j = 1; j <= i__1; ++j) {
  183. if (x[jx] != 0.) {
  184. temp = x[jx];
  185. ix = kx;
  186. l = kplus1 - j;
  187. /* Computing MAX */
  188. i__4 = 1, i__2 = j - *k;
  189. i__3 = j - 1;
  190. for (i__ = max(i__4,i__2); i__ <= i__3; ++i__) {
  191. x[ix] += temp * a_ref(l + i__, j);
  192. ix += *incx;
  193. /* L30: */
  194. }
  195. if (nounit) {
  196. x[jx] *= a_ref(kplus1, j);
  197. }
  198. }
  199. jx += *incx;
  200. if (j > *k) {
  201. kx += *incx;
  202. }
  203. /* L40: */
  204. }
  205. }
  206. } else {
  207. if (*incx == 1) {
  208. for (j = *n; j >= 1; --j) {
  209. if (x[j] != 0.) {
  210. temp = x[j];
  211. l = 1 - j;
  212. /* Computing MIN */
  213. i__1 = *n, i__3 = j + *k;
  214. i__4 = j + 1;
  215. for (i__ = min(i__1,i__3); i__ >= i__4; --i__) {
  216. x[i__] += temp * a_ref(l + i__, j);
  217. /* L50: */
  218. }
  219. if (nounit) {
  220. x[j] *= a_ref(1, j);
  221. }
  222. }
  223. /* L60: */
  224. }
  225. } else {
  226. kx += (*n - 1) * *incx;
  227. jx = kx;
  228. for (j = *n; j >= 1; --j) {
  229. if (x[jx] != 0.) {
  230. temp = x[jx];
  231. ix = kx;
  232. l = 1 - j;
  233. /* Computing MIN */
  234. i__4 = *n, i__1 = j + *k;
  235. i__3 = j + 1;
  236. for (i__ = min(i__4,i__1); i__ >= i__3; --i__) {
  237. x[ix] += temp * a_ref(l + i__, j);
  238. ix -= *incx;
  239. /* L70: */
  240. }
  241. if (nounit) {
  242. x[jx] *= a_ref(1, j);
  243. }
  244. }
  245. jx -= *incx;
  246. if (*n - j >= *k) {
  247. kx -= *incx;
  248. }
  249. /* L80: */
  250. }
  251. }
  252. }
  253. } else {
  254. /* Form x := A'*x. */
  255. if (lsame_(uplo, "U")) {
  256. kplus1 = *k + 1;
  257. if (*incx == 1) {
  258. for (j = *n; j >= 1; --j) {
  259. temp = x[j];
  260. l = kplus1 - j;
  261. if (nounit) {
  262. temp *= a_ref(kplus1, j);
  263. }
  264. /* Computing MAX */
  265. i__4 = 1, i__1 = j - *k;
  266. i__3 = max(i__4,i__1);
  267. for (i__ = j - 1; i__ >= i__3; --i__) {
  268. temp += a_ref(l + i__, j) * x[i__];
  269. /* L90: */
  270. }
  271. x[j] = temp;
  272. /* L100: */
  273. }
  274. } else {
  275. kx += (*n - 1) * *incx;
  276. jx = kx;
  277. for (j = *n; j >= 1; --j) {
  278. temp = x[jx];
  279. kx -= *incx;
  280. ix = kx;
  281. l = kplus1 - j;
  282. if (nounit) {
  283. temp *= a_ref(kplus1, j);
  284. }
  285. /* Computing MAX */
  286. i__4 = 1, i__1 = j - *k;
  287. i__3 = max(i__4,i__1);
  288. for (i__ = j - 1; i__ >= i__3; --i__) {
  289. temp += a_ref(l + i__, j) * x[ix];
  290. ix -= *incx;
  291. /* L110: */
  292. }
  293. x[jx] = temp;
  294. jx -= *incx;
  295. /* L120: */
  296. }
  297. }
  298. } else {
  299. if (*incx == 1) {
  300. i__3 = *n;
  301. for (j = 1; j <= i__3; ++j) {
  302. temp = x[j];
  303. l = 1 - j;
  304. if (nounit) {
  305. temp *= a_ref(1, j);
  306. }
  307. /* Computing MIN */
  308. i__1 = *n, i__2 = j + *k;
  309. i__4 = min(i__1,i__2);
  310. for (i__ = j + 1; i__ <= i__4; ++i__) {
  311. temp += a_ref(l + i__, j) * x[i__];
  312. /* L130: */
  313. }
  314. x[j] = temp;
  315. /* L140: */
  316. }
  317. } else {
  318. jx = kx;
  319. i__3 = *n;
  320. for (j = 1; j <= i__3; ++j) {
  321. temp = x[jx];
  322. kx += *incx;
  323. ix = kx;
  324. l = 1 - j;
  325. if (nounit) {
  326. temp *= a_ref(1, j);
  327. }
  328. /* Computing MIN */
  329. i__1 = *n, i__2 = j + *k;
  330. i__4 = min(i__1,i__2);
  331. for (i__ = j + 1; i__ <= i__4; ++i__) {
  332. temp += a_ref(l + i__, j) * x[ix];
  333. ix += *incx;
  334. /* L150: */
  335. }
  336. x[jx] = temp;
  337. jx += *incx;
  338. /* L160: */
  339. }
  340. }
  341. }
  342. }
  343. return 0;
  344. /* End of DTBMV . */
  345. } /* dtbmv_ */
  346. #undef a_ref