ztrsv.c 14 KB

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