ctrsv.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. /* ctrsv.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 ctrsv_(char *uplo, char *trans, char *diag, integer *n,
  14. complex *a, integer *lda, complex *x, integer *incx)
  15. {
  16. /* System generated locals */
  17. integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
  18. complex q__1, q__2, q__3;
  19. /* Builtin functions */
  20. void c_div(complex *, complex *, complex *), r_cnjg(complex *, complex *);
  21. /* Local variables */
  22. integer i__, j, ix, jx, kx, info;
  23. complex temp;
  24. extern logical lsame_(char *, char *);
  25. extern /* Subroutine */ int xerbla_(char *, integer *);
  26. logical noconj, nounit;
  27. /* .. Scalar Arguments .. */
  28. /* .. */
  29. /* .. Array Arguments .. */
  30. /* .. */
  31. /* Purpose */
  32. /* ======= */
  33. /* CTRSV solves one of the systems of equations */
  34. /* A*x = b, or A'*x = b, or conjg( A' )*x = b, */
  35. /* where b and x are n element vectors and A is an n by n unit, or */
  36. /* non-unit, upper or lower triangular matrix. */
  37. /* No test for singularity or near-singularity is included in this */
  38. /* routine. Such tests must be performed before calling this routine. */
  39. /* Arguments */
  40. /* ========== */
  41. /* UPLO - CHARACTER*1. */
  42. /* On entry, UPLO specifies whether the matrix is an upper or */
  43. /* lower triangular matrix as follows: */
  44. /* UPLO = 'U' or 'u' A is an upper triangular matrix. */
  45. /* UPLO = 'L' or 'l' A is a lower triangular matrix. */
  46. /* Unchanged on exit. */
  47. /* TRANS - CHARACTER*1. */
  48. /* On entry, TRANS specifies the equations to be solved as */
  49. /* follows: */
  50. /* TRANS = 'N' or 'n' A*x = b. */
  51. /* TRANS = 'T' or 't' A'*x = b. */
  52. /* TRANS = 'C' or 'c' conjg( A' )*x = b. */
  53. /* Unchanged on exit. */
  54. /* DIAG - CHARACTER*1. */
  55. /* On entry, DIAG specifies whether or not A is unit */
  56. /* triangular as follows: */
  57. /* DIAG = 'U' or 'u' A is assumed to be unit triangular. */
  58. /* DIAG = 'N' or 'n' A is not assumed to be unit */
  59. /* triangular. */
  60. /* Unchanged on exit. */
  61. /* N - INTEGER. */
  62. /* On entry, N specifies the order of the matrix A. */
  63. /* N must be at least zero. */
  64. /* Unchanged on exit. */
  65. /* A - COMPLEX array of DIMENSION ( LDA, n ). */
  66. /* Before entry with UPLO = 'U' or 'u', the leading n by n */
  67. /* upper triangular part of the array A must contain the upper */
  68. /* triangular matrix and the strictly lower triangular part of */
  69. /* A is not referenced. */
  70. /* Before entry with UPLO = 'L' or 'l', the leading n by n */
  71. /* lower triangular part of the array A must contain the lower */
  72. /* triangular matrix and the strictly upper triangular part of */
  73. /* A is not referenced. */
  74. /* Note that when DIAG = 'U' or 'u', the diagonal elements of */
  75. /* A are not referenced either, but are assumed to be unity. */
  76. /* Unchanged on exit. */
  77. /* LDA - INTEGER. */
  78. /* On entry, LDA specifies the first dimension of A as declared */
  79. /* in the calling (sub) program. LDA must be at least */
  80. /* max( 1, n ). */
  81. /* Unchanged on exit. */
  82. /* X - COMPLEX array of dimension at least */
  83. /* ( 1 + ( n - 1 )*abs( INCX ) ). */
  84. /* Before entry, the incremented array X must contain the n */
  85. /* element right-hand side vector b. On exit, X is overwritten */
  86. /* with the solution vector x. */
  87. /* INCX - INTEGER. */
  88. /* On entry, INCX specifies the increment for the elements of */
  89. /* X. INCX must not be zero. */
  90. /* Unchanged on exit. */
  91. /* Level 2 Blas routine. */
  92. /* -- Written on 22-October-1986. */
  93. /* Jack Dongarra, Argonne National Lab. */
  94. /* Jeremy Du Croz, Nag Central Office. */
  95. /* Sven Hammarling, Nag Central Office. */
  96. /* Richard Hanson, Sandia National Labs. */
  97. /* .. Parameters .. */
  98. /* .. */
  99. /* .. Local Scalars .. */
  100. /* .. */
  101. /* .. External Functions .. */
  102. /* .. */
  103. /* .. External Subroutines .. */
  104. /* .. */
  105. /* .. Intrinsic Functions .. */
  106. /* .. */
  107. /* Test the input parameters. */
  108. /* Parameter adjustments */
  109. a_dim1 = *lda;
  110. a_offset = 1 + a_dim1;
  111. a -= a_offset;
  112. --x;
  113. /* Function Body */
  114. info = 0;
  115. if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
  116. info = 1;
  117. } else if (! lsame_(trans, "N") && ! lsame_(trans,
  118. "T") && ! lsame_(trans, "C")) {
  119. info = 2;
  120. } else if (! lsame_(diag, "U") && ! lsame_(diag,
  121. "N")) {
  122. info = 3;
  123. } else if (*n < 0) {
  124. info = 4;
  125. } else if (*lda < max(1,*n)) {
  126. info = 6;
  127. } else if (*incx == 0) {
  128. info = 8;
  129. }
  130. if (info != 0) {
  131. xerbla_("CTRSV ", &info);
  132. return 0;
  133. }
  134. /* Quick return if possible. */
  135. if (*n == 0) {
  136. return 0;
  137. }
  138. noconj = lsame_(trans, "T");
  139. nounit = lsame_(diag, "N");
  140. /* Set up the start point in X if the increment is not unity. This */
  141. /* will be ( N - 1 )*INCX too small for descending loops. */
  142. if (*incx <= 0) {
  143. kx = 1 - (*n - 1) * *incx;
  144. } else if (*incx != 1) {
  145. kx = 1;
  146. }
  147. /* Start the operations. In this version the elements of A are */
  148. /* accessed sequentially with one pass through A. */
  149. if (lsame_(trans, "N")) {
  150. /* Form x := inv( A )*x. */
  151. if (lsame_(uplo, "U")) {
  152. if (*incx == 1) {
  153. for (j = *n; j >= 1; --j) {
  154. i__1 = j;
  155. if (x[i__1].r != 0.f || x[i__1].i != 0.f) {
  156. if (nounit) {
  157. i__1 = j;
  158. c_div(&q__1, &x[j], &a[j + j * a_dim1]);
  159. x[i__1].r = q__1.r, x[i__1].i = q__1.i;
  160. }
  161. i__1 = j;
  162. temp.r = x[i__1].r, temp.i = x[i__1].i;
  163. for (i__ = j - 1; i__ >= 1; --i__) {
  164. i__1 = i__;
  165. i__2 = i__;
  166. i__3 = i__ + j * a_dim1;
  167. q__2.r = temp.r * a[i__3].r - temp.i * a[i__3].i,
  168. q__2.i = temp.r * a[i__3].i + temp.i * a[
  169. i__3].r;
  170. q__1.r = x[i__2].r - q__2.r, q__1.i = x[i__2].i -
  171. q__2.i;
  172. x[i__1].r = q__1.r, x[i__1].i = q__1.i;
  173. /* L10: */
  174. }
  175. }
  176. /* L20: */
  177. }
  178. } else {
  179. jx = kx + (*n - 1) * *incx;
  180. for (j = *n; j >= 1; --j) {
  181. i__1 = jx;
  182. if (x[i__1].r != 0.f || x[i__1].i != 0.f) {
  183. if (nounit) {
  184. i__1 = jx;
  185. c_div(&q__1, &x[jx], &a[j + j * a_dim1]);
  186. x[i__1].r = q__1.r, x[i__1].i = q__1.i;
  187. }
  188. i__1 = jx;
  189. temp.r = x[i__1].r, temp.i = x[i__1].i;
  190. ix = jx;
  191. for (i__ = j - 1; i__ >= 1; --i__) {
  192. ix -= *incx;
  193. i__1 = ix;
  194. i__2 = ix;
  195. i__3 = i__ + j * a_dim1;
  196. q__2.r = temp.r * a[i__3].r - temp.i * a[i__3].i,
  197. q__2.i = temp.r * a[i__3].i + temp.i * a[
  198. i__3].r;
  199. q__1.r = x[i__2].r - q__2.r, q__1.i = x[i__2].i -
  200. q__2.i;
  201. x[i__1].r = q__1.r, x[i__1].i = q__1.i;
  202. /* L30: */
  203. }
  204. }
  205. jx -= *incx;
  206. /* L40: */
  207. }
  208. }
  209. } else {
  210. if (*incx == 1) {
  211. i__1 = *n;
  212. for (j = 1; j <= i__1; ++j) {
  213. i__2 = j;
  214. if (x[i__2].r != 0.f || x[i__2].i != 0.f) {
  215. if (nounit) {
  216. i__2 = j;
  217. c_div(&q__1, &x[j], &a[j + j * a_dim1]);
  218. x[i__2].r = q__1.r, x[i__2].i = q__1.i;
  219. }
  220. i__2 = j;
  221. temp.r = x[i__2].r, temp.i = x[i__2].i;
  222. i__2 = *n;
  223. for (i__ = j + 1; i__ <= i__2; ++i__) {
  224. i__3 = i__;
  225. i__4 = i__;
  226. i__5 = i__ + j * a_dim1;
  227. q__2.r = temp.r * a[i__5].r - temp.i * a[i__5].i,
  228. q__2.i = temp.r * a[i__5].i + temp.i * a[
  229. i__5].r;
  230. q__1.r = x[i__4].r - q__2.r, q__1.i = x[i__4].i -
  231. q__2.i;
  232. x[i__3].r = q__1.r, x[i__3].i = q__1.i;
  233. /* L50: */
  234. }
  235. }
  236. /* L60: */
  237. }
  238. } else {
  239. jx = kx;
  240. i__1 = *n;
  241. for (j = 1; j <= i__1; ++j) {
  242. i__2 = jx;
  243. if (x[i__2].r != 0.f || x[i__2].i != 0.f) {
  244. if (nounit) {
  245. i__2 = jx;
  246. c_div(&q__1, &x[jx], &a[j + j * a_dim1]);
  247. x[i__2].r = q__1.r, x[i__2].i = q__1.i;
  248. }
  249. i__2 = jx;
  250. temp.r = x[i__2].r, temp.i = x[i__2].i;
  251. ix = jx;
  252. i__2 = *n;
  253. for (i__ = j + 1; i__ <= i__2; ++i__) {
  254. ix += *incx;
  255. i__3 = ix;
  256. i__4 = ix;
  257. i__5 = i__ + j * a_dim1;
  258. q__2.r = temp.r * a[i__5].r - temp.i * a[i__5].i,
  259. q__2.i = temp.r * a[i__5].i + temp.i * a[
  260. i__5].r;
  261. q__1.r = x[i__4].r - q__2.r, q__1.i = x[i__4].i -
  262. q__2.i;
  263. x[i__3].r = q__1.r, x[i__3].i = q__1.i;
  264. /* L70: */
  265. }
  266. }
  267. jx += *incx;
  268. /* L80: */
  269. }
  270. }
  271. }
  272. } else {
  273. /* Form x := inv( A' )*x or x := inv( conjg( A' ) )*x. */
  274. if (lsame_(uplo, "U")) {
  275. if (*incx == 1) {
  276. i__1 = *n;
  277. for (j = 1; j <= i__1; ++j) {
  278. i__2 = j;
  279. temp.r = x[i__2].r, temp.i = x[i__2].i;
  280. if (noconj) {
  281. i__2 = j - 1;
  282. for (i__ = 1; i__ <= i__2; ++i__) {
  283. i__3 = i__ + j * a_dim1;
  284. i__4 = i__;
  285. q__2.r = a[i__3].r * x[i__4].r - a[i__3].i * x[
  286. i__4].i, q__2.i = a[i__3].r * x[i__4].i +
  287. a[i__3].i * x[i__4].r;
  288. q__1.r = temp.r - q__2.r, q__1.i = temp.i -
  289. q__2.i;
  290. temp.r = q__1.r, temp.i = q__1.i;
  291. /* L90: */
  292. }
  293. if (nounit) {
  294. c_div(&q__1, &temp, &a[j + j * a_dim1]);
  295. temp.r = q__1.r, temp.i = q__1.i;
  296. }
  297. } else {
  298. i__2 = j - 1;
  299. for (i__ = 1; i__ <= i__2; ++i__) {
  300. r_cnjg(&q__3, &a[i__ + j * a_dim1]);
  301. i__3 = i__;
  302. q__2.r = q__3.r * x[i__3].r - q__3.i * x[i__3].i,
  303. q__2.i = q__3.r * x[i__3].i + q__3.i * x[
  304. i__3].r;
  305. q__1.r = temp.r - q__2.r, q__1.i = temp.i -
  306. q__2.i;
  307. temp.r = q__1.r, temp.i = q__1.i;
  308. /* L100: */
  309. }
  310. if (nounit) {
  311. r_cnjg(&q__2, &a[j + j * a_dim1]);
  312. c_div(&q__1, &temp, &q__2);
  313. temp.r = q__1.r, temp.i = q__1.i;
  314. }
  315. }
  316. i__2 = j;
  317. x[i__2].r = temp.r, x[i__2].i = temp.i;
  318. /* L110: */
  319. }
  320. } else {
  321. jx = kx;
  322. i__1 = *n;
  323. for (j = 1; j <= i__1; ++j) {
  324. ix = kx;
  325. i__2 = jx;
  326. temp.r = x[i__2].r, temp.i = x[i__2].i;
  327. if (noconj) {
  328. i__2 = j - 1;
  329. for (i__ = 1; i__ <= i__2; ++i__) {
  330. i__3 = i__ + j * a_dim1;
  331. i__4 = ix;
  332. q__2.r = a[i__3].r * x[i__4].r - a[i__3].i * x[
  333. i__4].i, q__2.i = a[i__3].r * x[i__4].i +
  334. a[i__3].i * x[i__4].r;
  335. q__1.r = temp.r - q__2.r, q__1.i = temp.i -
  336. q__2.i;
  337. temp.r = q__1.r, temp.i = q__1.i;
  338. ix += *incx;
  339. /* L120: */
  340. }
  341. if (nounit) {
  342. c_div(&q__1, &temp, &a[j + j * a_dim1]);
  343. temp.r = q__1.r, temp.i = q__1.i;
  344. }
  345. } else {
  346. i__2 = j - 1;
  347. for (i__ = 1; i__ <= i__2; ++i__) {
  348. r_cnjg(&q__3, &a[i__ + j * a_dim1]);
  349. i__3 = ix;
  350. q__2.r = q__3.r * x[i__3].r - q__3.i * x[i__3].i,
  351. q__2.i = q__3.r * x[i__3].i + q__3.i * x[
  352. i__3].r;
  353. q__1.r = temp.r - q__2.r, q__1.i = temp.i -
  354. q__2.i;
  355. temp.r = q__1.r, temp.i = q__1.i;
  356. ix += *incx;
  357. /* L130: */
  358. }
  359. if (nounit) {
  360. r_cnjg(&q__2, &a[j + j * a_dim1]);
  361. c_div(&q__1, &temp, &q__2);
  362. temp.r = q__1.r, temp.i = q__1.i;
  363. }
  364. }
  365. i__2 = jx;
  366. x[i__2].r = temp.r, x[i__2].i = temp.i;
  367. jx += *incx;
  368. /* L140: */
  369. }
  370. }
  371. } else {
  372. if (*incx == 1) {
  373. for (j = *n; j >= 1; --j) {
  374. i__1 = j;
  375. temp.r = x[i__1].r, temp.i = x[i__1].i;
  376. if (noconj) {
  377. i__1 = j + 1;
  378. for (i__ = *n; i__ >= i__1; --i__) {
  379. i__2 = i__ + j * a_dim1;
  380. i__3 = i__;
  381. q__2.r = a[i__2].r * x[i__3].r - a[i__2].i * x[
  382. i__3].i, q__2.i = a[i__2].r * x[i__3].i +
  383. a[i__2].i * x[i__3].r;
  384. q__1.r = temp.r - q__2.r, q__1.i = temp.i -
  385. q__2.i;
  386. temp.r = q__1.r, temp.i = q__1.i;
  387. /* L150: */
  388. }
  389. if (nounit) {
  390. c_div(&q__1, &temp, &a[j + j * a_dim1]);
  391. temp.r = q__1.r, temp.i = q__1.i;
  392. }
  393. } else {
  394. i__1 = j + 1;
  395. for (i__ = *n; i__ >= i__1; --i__) {
  396. r_cnjg(&q__3, &a[i__ + j * a_dim1]);
  397. i__2 = i__;
  398. q__2.r = q__3.r * x[i__2].r - q__3.i * x[i__2].i,
  399. q__2.i = q__3.r * x[i__2].i + q__3.i * x[
  400. i__2].r;
  401. q__1.r = temp.r - q__2.r, q__1.i = temp.i -
  402. q__2.i;
  403. temp.r = q__1.r, temp.i = q__1.i;
  404. /* L160: */
  405. }
  406. if (nounit) {
  407. r_cnjg(&q__2, &a[j + j * a_dim1]);
  408. c_div(&q__1, &temp, &q__2);
  409. temp.r = q__1.r, temp.i = q__1.i;
  410. }
  411. }
  412. i__1 = j;
  413. x[i__1].r = temp.r, x[i__1].i = temp.i;
  414. /* L170: */
  415. }
  416. } else {
  417. kx += (*n - 1) * *incx;
  418. jx = kx;
  419. for (j = *n; j >= 1; --j) {
  420. ix = kx;
  421. i__1 = jx;
  422. temp.r = x[i__1].r, temp.i = x[i__1].i;
  423. if (noconj) {
  424. i__1 = j + 1;
  425. for (i__ = *n; i__ >= i__1; --i__) {
  426. i__2 = i__ + j * a_dim1;
  427. i__3 = ix;
  428. q__2.r = a[i__2].r * x[i__3].r - a[i__2].i * x[
  429. i__3].i, q__2.i = a[i__2].r * x[i__3].i +
  430. a[i__2].i * x[i__3].r;
  431. q__1.r = temp.r - q__2.r, q__1.i = temp.i -
  432. q__2.i;
  433. temp.r = q__1.r, temp.i = q__1.i;
  434. ix -= *incx;
  435. /* L180: */
  436. }
  437. if (nounit) {
  438. c_div(&q__1, &temp, &a[j + j * a_dim1]);
  439. temp.r = q__1.r, temp.i = q__1.i;
  440. }
  441. } else {
  442. i__1 = j + 1;
  443. for (i__ = *n; i__ >= i__1; --i__) {
  444. r_cnjg(&q__3, &a[i__ + j * a_dim1]);
  445. i__2 = ix;
  446. q__2.r = q__3.r * x[i__2].r - q__3.i * x[i__2].i,
  447. q__2.i = q__3.r * x[i__2].i + q__3.i * x[
  448. i__2].r;
  449. q__1.r = temp.r - q__2.r, q__1.i = temp.i -
  450. q__2.i;
  451. temp.r = q__1.r, temp.i = q__1.i;
  452. ix -= *incx;
  453. /* L190: */
  454. }
  455. if (nounit) {
  456. r_cnjg(&q__2, &a[j + j * a_dim1]);
  457. c_div(&q__1, &temp, &q__2);
  458. temp.r = q__1.r, temp.i = q__1.i;
  459. }
  460. }
  461. i__1 = jx;
  462. x[i__1].r = temp.r, x[i__1].i = temp.i;
  463. jx -= *incx;
  464. /* L200: */
  465. }
  466. }
  467. }
  468. }
  469. return 0;
  470. /* End of CTRSV . */
  471. } /* ctrsv_ */