stbsv.c 11 KB

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