ctpsv.c 14 KB

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