ztpsv.c 14 KB

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