stpsv.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /* stpsv.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 stpsv_(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. /* STPSV solves one of the systems of equations */
  31. /* A*x = b, or A'*x = b, */
  32. /* where b and x are n element vectors and A is an n by n unit, or */
  33. /* non-unit, upper or lower triangular matrix, supplied in packed form. */
  34. /* No test for singularity or near-singularity is included in this */
  35. /* routine. Such tests must be performed before calling this routine. */
  36. /* Arguments */
  37. /* ========== */
  38. /* UPLO - CHARACTER*1. */
  39. /* On entry, UPLO specifies whether the matrix is an upper or */
  40. /* lower triangular matrix as follows: */
  41. /* UPLO = 'U' or 'u' A is an upper triangular matrix. */
  42. /* UPLO = 'L' or 'l' A is a lower triangular matrix. */
  43. /* Unchanged on exit. */
  44. /* TRANS - CHARACTER*1. */
  45. /* On entry, TRANS specifies the equations to be solved as */
  46. /* follows: */
  47. /* TRANS = 'N' or 'n' A*x = b. */
  48. /* TRANS = 'T' or 't' A'*x = b. */
  49. /* TRANS = 'C' or 'c' A'*x = b. */
  50. /* Unchanged on exit. */
  51. /* DIAG - CHARACTER*1. */
  52. /* On entry, DIAG specifies whether or not A is unit */
  53. /* triangular as follows: */
  54. /* DIAG = 'U' or 'u' A is assumed to be unit triangular. */
  55. /* DIAG = 'N' or 'n' A is not assumed to be unit */
  56. /* triangular. */
  57. /* Unchanged on exit. */
  58. /* N - INTEGER. */
  59. /* On entry, N specifies the order of the matrix A. */
  60. /* N must be at least zero. */
  61. /* Unchanged on exit. */
  62. /* AP - REAL array of DIMENSION at least */
  63. /* ( ( n*( n + 1 ) )/2 ). */
  64. /* Before entry with UPLO = 'U' or 'u', the array AP must */
  65. /* contain the upper triangular matrix packed sequentially, */
  66. /* column by column, so that AP( 1 ) contains a( 1, 1 ), */
  67. /* AP( 2 ) and AP( 3 ) contain a( 1, 2 ) and a( 2, 2 ) */
  68. /* respectively, and so on. */
  69. /* Before entry with UPLO = 'L' or 'l', the array AP must */
  70. /* contain the lower triangular matrix packed sequentially, */
  71. /* column by column, so that AP( 1 ) contains a( 1, 1 ), */
  72. /* AP( 2 ) and AP( 3 ) contain a( 2, 1 ) and a( 3, 1 ) */
  73. /* respectively, and so on. */
  74. /* Note that when DIAG = 'U' or 'u', the diagonal elements of */
  75. /* A are not referenced, but are assumed to be unity. */
  76. /* Unchanged on exit. */
  77. /* X - REAL array of dimension at least */
  78. /* ( 1 + ( n - 1 )*abs( INCX ) ). */
  79. /* Before entry, the incremented array X must contain the n */
  80. /* element right-hand side vector b. On exit, X is overwritten */
  81. /* with the solution vector x. */
  82. /* INCX - INTEGER. */
  83. /* On entry, INCX specifies the increment for the elements of */
  84. /* X. INCX must not be zero. */
  85. /* Unchanged on exit. */
  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. --x;
  103. --ap;
  104. /* Function Body */
  105. info = 0;
  106. if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
  107. info = 1;
  108. } else if (! lsame_(trans, "N") && ! lsame_(trans,
  109. "T") && ! lsame_(trans, "C")) {
  110. info = 2;
  111. } else if (! lsame_(diag, "U") && ! lsame_(diag,
  112. "N")) {
  113. info = 3;
  114. } else if (*n < 0) {
  115. info = 4;
  116. } else if (*incx == 0) {
  117. info = 7;
  118. }
  119. if (info != 0) {
  120. xerbla_("STPSV ", &info);
  121. return 0;
  122. }
  123. /* Quick return if possible. */
  124. if (*n == 0) {
  125. return 0;
  126. }
  127. nounit = lsame_(diag, "N");
  128. /* Set up the start point in X if the increment is not unity. This */
  129. /* will be ( N - 1 )*INCX too small for descending loops. */
  130. if (*incx <= 0) {
  131. kx = 1 - (*n - 1) * *incx;
  132. } else if (*incx != 1) {
  133. kx = 1;
  134. }
  135. /* Start the operations. In this version the elements of AP are */
  136. /* accessed sequentially with one pass through AP. */
  137. if (lsame_(trans, "N")) {
  138. /* Form x := inv( A )*x. */
  139. if (lsame_(uplo, "U")) {
  140. kk = *n * (*n + 1) / 2;
  141. if (*incx == 1) {
  142. for (j = *n; j >= 1; --j) {
  143. if (x[j] != 0.f) {
  144. if (nounit) {
  145. x[j] /= ap[kk];
  146. }
  147. temp = x[j];
  148. k = kk - 1;
  149. for (i__ = j - 1; i__ >= 1; --i__) {
  150. x[i__] -= temp * ap[k];
  151. --k;
  152. /* L10: */
  153. }
  154. }
  155. kk -= j;
  156. /* L20: */
  157. }
  158. } else {
  159. jx = kx + (*n - 1) * *incx;
  160. for (j = *n; j >= 1; --j) {
  161. if (x[jx] != 0.f) {
  162. if (nounit) {
  163. x[jx] /= ap[kk];
  164. }
  165. temp = x[jx];
  166. ix = jx;
  167. i__1 = kk - j + 1;
  168. for (k = kk - 1; k >= i__1; --k) {
  169. ix -= *incx;
  170. x[ix] -= temp * ap[k];
  171. /* L30: */
  172. }
  173. }
  174. jx -= *incx;
  175. kk -= j;
  176. /* L40: */
  177. }
  178. }
  179. } else {
  180. kk = 1;
  181. if (*incx == 1) {
  182. i__1 = *n;
  183. for (j = 1; j <= i__1; ++j) {
  184. if (x[j] != 0.f) {
  185. if (nounit) {
  186. x[j] /= ap[kk];
  187. }
  188. temp = x[j];
  189. k = kk + 1;
  190. i__2 = *n;
  191. for (i__ = j + 1; i__ <= i__2; ++i__) {
  192. x[i__] -= temp * ap[k];
  193. ++k;
  194. /* L50: */
  195. }
  196. }
  197. kk += *n - j + 1;
  198. /* L60: */
  199. }
  200. } else {
  201. jx = kx;
  202. i__1 = *n;
  203. for (j = 1; j <= i__1; ++j) {
  204. if (x[jx] != 0.f) {
  205. if (nounit) {
  206. x[jx] /= ap[kk];
  207. }
  208. temp = x[jx];
  209. ix = jx;
  210. i__2 = kk + *n - j;
  211. for (k = kk + 1; k <= i__2; ++k) {
  212. ix += *incx;
  213. x[ix] -= temp * ap[k];
  214. /* L70: */
  215. }
  216. }
  217. jx += *incx;
  218. kk += *n - j + 1;
  219. /* L80: */
  220. }
  221. }
  222. }
  223. } else {
  224. /* Form x := inv( A' )*x. */
  225. if (lsame_(uplo, "U")) {
  226. kk = 1;
  227. if (*incx == 1) {
  228. i__1 = *n;
  229. for (j = 1; j <= i__1; ++j) {
  230. temp = x[j];
  231. k = kk;
  232. i__2 = j - 1;
  233. for (i__ = 1; i__ <= i__2; ++i__) {
  234. temp -= ap[k] * x[i__];
  235. ++k;
  236. /* L90: */
  237. }
  238. if (nounit) {
  239. temp /= ap[kk + j - 1];
  240. }
  241. x[j] = temp;
  242. kk += j;
  243. /* L100: */
  244. }
  245. } else {
  246. jx = kx;
  247. i__1 = *n;
  248. for (j = 1; j <= i__1; ++j) {
  249. temp = x[jx];
  250. ix = kx;
  251. i__2 = kk + j - 2;
  252. for (k = kk; k <= i__2; ++k) {
  253. temp -= ap[k] * x[ix];
  254. ix += *incx;
  255. /* L110: */
  256. }
  257. if (nounit) {
  258. temp /= ap[kk + j - 1];
  259. }
  260. x[jx] = temp;
  261. jx += *incx;
  262. kk += j;
  263. /* L120: */
  264. }
  265. }
  266. } else {
  267. kk = *n * (*n + 1) / 2;
  268. if (*incx == 1) {
  269. for (j = *n; j >= 1; --j) {
  270. temp = x[j];
  271. k = kk;
  272. i__1 = j + 1;
  273. for (i__ = *n; i__ >= i__1; --i__) {
  274. temp -= ap[k] * x[i__];
  275. --k;
  276. /* L130: */
  277. }
  278. if (nounit) {
  279. temp /= ap[kk - *n + j];
  280. }
  281. x[j] = temp;
  282. kk -= *n - j + 1;
  283. /* L140: */
  284. }
  285. } else {
  286. kx += (*n - 1) * *incx;
  287. jx = kx;
  288. for (j = *n; j >= 1; --j) {
  289. temp = x[jx];
  290. ix = kx;
  291. i__1 = kk - (*n - (j + 1));
  292. for (k = kk; k >= i__1; --k) {
  293. temp -= ap[k] * x[ix];
  294. ix -= *incx;
  295. /* L150: */
  296. }
  297. if (nounit) {
  298. temp /= ap[kk - *n + j];
  299. }
  300. x[jx] = temp;
  301. jx -= *incx;
  302. kk -= *n - j + 1;
  303. /* L160: */
  304. }
  305. }
  306. }
  307. }
  308. return 0;
  309. /* End of STPSV . */
  310. } /* stpsv_ */