ztpmv.c 15 KB

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