strsv.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /* strsv.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 strsv_(char *uplo, char *trans, char *diag, integer *n,
  14. real *a, integer *lda, real *x, integer *incx)
  15. {
  16. /* System generated locals */
  17. integer a_dim1, a_offset, i__1, i__2;
  18. /* Local variables */
  19. integer i__, j, 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. /* STRSV 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. */
  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. /* A - REAL array of DIMENSION ( LDA, n ). */
  63. /* Before entry with UPLO = 'U' or 'u', the leading n by n */
  64. /* upper triangular part of the array A must contain the upper */
  65. /* triangular matrix and the strictly lower triangular part of */
  66. /* A is not referenced. */
  67. /* Before entry with UPLO = 'L' or 'l', the leading n by n */
  68. /* lower triangular part of the array A must contain the lower */
  69. /* triangular matrix and the strictly upper triangular part of */
  70. /* A is not referenced. */
  71. /* Note that when DIAG = 'U' or 'u', the diagonal elements of */
  72. /* A are not referenced either, but are assumed to be unity. */
  73. /* Unchanged on exit. */
  74. /* LDA - INTEGER. */
  75. /* On entry, LDA specifies the first dimension of A as declared */
  76. /* in the calling (sub) program. LDA must be at least */
  77. /* max( 1, n ). */
  78. /* Unchanged on exit. */
  79. /* X - REAL array of dimension at least */
  80. /* ( 1 + ( n - 1 )*abs( INCX ) ). */
  81. /* Before entry, the incremented array X must contain the n */
  82. /* element right-hand side vector b. On exit, X is overwritten */
  83. /* with the solution vector x. */
  84. /* INCX - INTEGER. */
  85. /* On entry, INCX specifies the increment for the elements of */
  86. /* X. INCX must not be zero. */
  87. /* Unchanged on exit. */
  88. /* Level 2 Blas routine. */
  89. /* -- Written on 22-October-1986. */
  90. /* Jack Dongarra, Argonne National Lab. */
  91. /* Jeremy Du Croz, Nag Central Office. */
  92. /* Sven Hammarling, Nag Central Office. */
  93. /* Richard Hanson, Sandia National Labs. */
  94. /* .. Parameters .. */
  95. /* .. */
  96. /* .. Local Scalars .. */
  97. /* .. */
  98. /* .. External Functions .. */
  99. /* .. */
  100. /* .. External Subroutines .. */
  101. /* .. */
  102. /* .. Intrinsic Functions .. */
  103. /* .. */
  104. /* Test the input parameters. */
  105. /* Parameter adjustments */
  106. a_dim1 = *lda;
  107. a_offset = 1 + a_dim1;
  108. a -= a_offset;
  109. --x;
  110. /* Function Body */
  111. info = 0;
  112. if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
  113. info = 1;
  114. } else if (! lsame_(trans, "N") && ! lsame_(trans,
  115. "T") && ! lsame_(trans, "C")) {
  116. info = 2;
  117. } else if (! lsame_(diag, "U") && ! lsame_(diag,
  118. "N")) {
  119. info = 3;
  120. } else if (*n < 0) {
  121. info = 4;
  122. } else if (*lda < max(1,*n)) {
  123. info = 6;
  124. } else if (*incx == 0) {
  125. info = 8;
  126. }
  127. if (info != 0) {
  128. xerbla_("STRSV ", &info);
  129. return 0;
  130. }
  131. /* Quick return if possible. */
  132. if (*n == 0) {
  133. return 0;
  134. }
  135. nounit = lsame_(diag, "N");
  136. /* Set up the start point in X if the increment is not unity. This */
  137. /* will be ( N - 1 )*INCX too small for descending loops. */
  138. if (*incx <= 0) {
  139. kx = 1 - (*n - 1) * *incx;
  140. } else if (*incx != 1) {
  141. kx = 1;
  142. }
  143. /* Start the operations. In this version the elements of A are */
  144. /* accessed sequentially with one pass through A. */
  145. if (lsame_(trans, "N")) {
  146. /* Form x := inv( A )*x. */
  147. if (lsame_(uplo, "U")) {
  148. if (*incx == 1) {
  149. for (j = *n; j >= 1; --j) {
  150. if (x[j] != 0.f) {
  151. if (nounit) {
  152. x[j] /= a[j + j * a_dim1];
  153. }
  154. temp = x[j];
  155. for (i__ = j - 1; i__ >= 1; --i__) {
  156. x[i__] -= temp * a[i__ + j * a_dim1];
  157. /* L10: */
  158. }
  159. }
  160. /* L20: */
  161. }
  162. } else {
  163. jx = kx + (*n - 1) * *incx;
  164. for (j = *n; j >= 1; --j) {
  165. if (x[jx] != 0.f) {
  166. if (nounit) {
  167. x[jx] /= a[j + j * a_dim1];
  168. }
  169. temp = x[jx];
  170. ix = jx;
  171. for (i__ = j - 1; i__ >= 1; --i__) {
  172. ix -= *incx;
  173. x[ix] -= temp * a[i__ + j * a_dim1];
  174. /* L30: */
  175. }
  176. }
  177. jx -= *incx;
  178. /* L40: */
  179. }
  180. }
  181. } else {
  182. if (*incx == 1) {
  183. i__1 = *n;
  184. for (j = 1; j <= i__1; ++j) {
  185. if (x[j] != 0.f) {
  186. if (nounit) {
  187. x[j] /= a[j + j * a_dim1];
  188. }
  189. temp = x[j];
  190. i__2 = *n;
  191. for (i__ = j + 1; i__ <= i__2; ++i__) {
  192. x[i__] -= temp * a[i__ + j * a_dim1];
  193. /* L50: */
  194. }
  195. }
  196. /* L60: */
  197. }
  198. } else {
  199. jx = kx;
  200. i__1 = *n;
  201. for (j = 1; j <= i__1; ++j) {
  202. if (x[jx] != 0.f) {
  203. if (nounit) {
  204. x[jx] /= a[j + j * a_dim1];
  205. }
  206. temp = x[jx];
  207. ix = jx;
  208. i__2 = *n;
  209. for (i__ = j + 1; i__ <= i__2; ++i__) {
  210. ix += *incx;
  211. x[ix] -= temp * a[i__ + j * a_dim1];
  212. /* L70: */
  213. }
  214. }
  215. jx += *incx;
  216. /* L80: */
  217. }
  218. }
  219. }
  220. } else {
  221. /* Form x := inv( A' )*x. */
  222. if (lsame_(uplo, "U")) {
  223. if (*incx == 1) {
  224. i__1 = *n;
  225. for (j = 1; j <= i__1; ++j) {
  226. temp = x[j];
  227. i__2 = j - 1;
  228. for (i__ = 1; i__ <= i__2; ++i__) {
  229. temp -= a[i__ + j * a_dim1] * x[i__];
  230. /* L90: */
  231. }
  232. if (nounit) {
  233. temp /= a[j + j * a_dim1];
  234. }
  235. x[j] = temp;
  236. /* L100: */
  237. }
  238. } else {
  239. jx = kx;
  240. i__1 = *n;
  241. for (j = 1; j <= i__1; ++j) {
  242. temp = x[jx];
  243. ix = kx;
  244. i__2 = j - 1;
  245. for (i__ = 1; i__ <= i__2; ++i__) {
  246. temp -= a[i__ + j * a_dim1] * x[ix];
  247. ix += *incx;
  248. /* L110: */
  249. }
  250. if (nounit) {
  251. temp /= a[j + j * a_dim1];
  252. }
  253. x[jx] = temp;
  254. jx += *incx;
  255. /* L120: */
  256. }
  257. }
  258. } else {
  259. if (*incx == 1) {
  260. for (j = *n; j >= 1; --j) {
  261. temp = x[j];
  262. i__1 = j + 1;
  263. for (i__ = *n; i__ >= i__1; --i__) {
  264. temp -= a[i__ + j * a_dim1] * x[i__];
  265. /* L130: */
  266. }
  267. if (nounit) {
  268. temp /= a[j + j * a_dim1];
  269. }
  270. x[j] = temp;
  271. /* L140: */
  272. }
  273. } else {
  274. kx += (*n - 1) * *incx;
  275. jx = kx;
  276. for (j = *n; j >= 1; --j) {
  277. temp = x[jx];
  278. ix = kx;
  279. i__1 = j + 1;
  280. for (i__ = *n; i__ >= i__1; --i__) {
  281. temp -= a[i__ + j * a_dim1] * x[ix];
  282. ix -= *incx;
  283. /* L150: */
  284. }
  285. if (nounit) {
  286. temp /= a[j + j * a_dim1];
  287. }
  288. x[jx] = temp;
  289. jx -= *incx;
  290. /* L160: */
  291. }
  292. }
  293. }
  294. }
  295. return 0;
  296. /* End of STRSV . */
  297. } /* strsv_ */