dtrttf.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. /* dtrttf.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 _starpu_dtrttf_(char *transr, char *uplo, integer *n, doublereal
  14. *a, integer *lda, doublereal *arf, integer *info)
  15. {
  16. /* System generated locals */
  17. integer a_dim1, a_offset, i__1, i__2;
  18. /* Local variables */
  19. integer i__, j, k, l, n1, n2, ij, nt, nx2, np1x2;
  20. logical normaltransr;
  21. extern logical _starpu_lsame_(char *, char *);
  22. logical lower;
  23. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  24. logical nisodd;
  25. /* -- LAPACK routine (version 3.2) -- */
  26. /* -- Contributed by Fred Gustavson of the IBM Watson Research Center -- */
  27. /* -- November 2008 -- */
  28. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  29. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  30. /* .. Scalar Arguments .. */
  31. /* .. */
  32. /* .. Array Arguments .. */
  33. /* .. */
  34. /* Purpose */
  35. /* ======= */
  36. /* DTRTTF copies a triangular matrix A from standard full format (TR) */
  37. /* to rectangular full packed format (TF) . */
  38. /* Arguments */
  39. /* ========= */
  40. /* TRANSR (input) CHARACTER */
  41. /* = 'N': ARF in Normal form is wanted; */
  42. /* = 'T': ARF in Transpose form is wanted. */
  43. /* UPLO (input) CHARACTER */
  44. /* = 'U': Upper triangle of A is stored; */
  45. /* = 'L': Lower triangle of A is stored. */
  46. /* N (input) INTEGER */
  47. /* The order of the matrix A. N >= 0. */
  48. /* A (input) DOUBLE PRECISION array, dimension (LDA,N). */
  49. /* On entry, the triangular matrix A. If UPLO = 'U', the */
  50. /* leading N-by-N upper triangular part of the array A contains */
  51. /* the upper triangular matrix, and the strictly lower */
  52. /* triangular part of A is not referenced. If UPLO = 'L', the */
  53. /* leading N-by-N lower triangular part of the array A contains */
  54. /* the lower triangular matrix, and the strictly upper */
  55. /* triangular part of A is not referenced. */
  56. /* LDA (input) INTEGER */
  57. /* The leading dimension of the matrix A. LDA >= max(1,N). */
  58. /* ARF (output) DOUBLE PRECISION array, dimension (NT). */
  59. /* NT=N*(N+1)/2. On exit, the triangular matrix A in RFP format. */
  60. /* INFO (output) INTEGER */
  61. /* = 0: successful exit */
  62. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  63. /* Notes */
  64. /* ===== */
  65. /* We first consider Rectangular Full Packed (RFP) Format when N is */
  66. /* even. We give an example where N = 6. */
  67. /* AP is Upper AP is Lower */
  68. /* 00 01 02 03 04 05 00 */
  69. /* 11 12 13 14 15 10 11 */
  70. /* 22 23 24 25 20 21 22 */
  71. /* 33 34 35 30 31 32 33 */
  72. /* 44 45 40 41 42 43 44 */
  73. /* 55 50 51 52 53 54 55 */
  74. /* Let TRANSR = 'N'. RFP holds AP as follows: */
  75. /* For UPLO = 'U' the upper trapezoid A(0:5,0:2) consists of the last */
  76. /* three columns of AP upper. The lower triangle A(4:6,0:2) consists of */
  77. /* the transpose of the first three columns of AP upper. */
  78. /* For UPLO = 'L' the lower trapezoid A(1:6,0:2) consists of the first */
  79. /* three columns of AP lower. The upper triangle A(0:2,0:2) consists of */
  80. /* the transpose of the last three columns of AP lower. */
  81. /* This covers the case N even and TRANSR = 'N'. */
  82. /* RFP A RFP A */
  83. /* 03 04 05 33 43 53 */
  84. /* 13 14 15 00 44 54 */
  85. /* 23 24 25 10 11 55 */
  86. /* 33 34 35 20 21 22 */
  87. /* 00 44 45 30 31 32 */
  88. /* 01 11 55 40 41 42 */
  89. /* 02 12 22 50 51 52 */
  90. /* Now let TRANSR = 'T'. RFP A in both UPLO cases is just the */
  91. /* transpose of RFP A above. One therefore gets: */
  92. /* RFP A RFP A */
  93. /* 03 13 23 33 00 01 02 33 00 10 20 30 40 50 */
  94. /* 04 14 24 34 44 11 12 43 44 11 21 31 41 51 */
  95. /* 05 15 25 35 45 55 22 53 54 55 22 32 42 52 */
  96. /* We first consider Rectangular Full Packed (RFP) Format when N is */
  97. /* odd. We give an example where N = 5. */
  98. /* AP is Upper AP is Lower */
  99. /* 00 01 02 03 04 00 */
  100. /* 11 12 13 14 10 11 */
  101. /* 22 23 24 20 21 22 */
  102. /* 33 34 30 31 32 33 */
  103. /* 44 40 41 42 43 44 */
  104. /* Let TRANSR = 'N'. RFP holds AP as follows: */
  105. /* For UPLO = 'U' the upper trapezoid A(0:4,0:2) consists of the last */
  106. /* three columns of AP upper. The lower triangle A(3:4,0:1) consists of */
  107. /* the transpose of the first two columns of AP upper. */
  108. /* For UPLO = 'L' the lower trapezoid A(0:4,0:2) consists of the first */
  109. /* three columns of AP lower. The upper triangle A(0:1,1:2) consists of */
  110. /* the transpose of the last two columns of AP lower. */
  111. /* This covers the case N odd and TRANSR = 'N'. */
  112. /* RFP A RFP A */
  113. /* 02 03 04 00 33 43 */
  114. /* 12 13 14 10 11 44 */
  115. /* 22 23 24 20 21 22 */
  116. /* 00 33 34 30 31 32 */
  117. /* 01 11 44 40 41 42 */
  118. /* Now let TRANSR = 'T'. RFP A in both UPLO cases is just the */
  119. /* transpose of RFP A above. One therefore gets: */
  120. /* RFP A RFP A */
  121. /* 02 12 22 00 01 00 10 20 30 40 50 */
  122. /* 03 13 23 33 11 33 11 21 31 41 51 */
  123. /* 04 14 24 34 44 43 44 22 32 42 52 */
  124. /* Reference */
  125. /* ========= */
  126. /* ===================================================================== */
  127. /* .. */
  128. /* .. Local Scalars .. */
  129. /* .. */
  130. /* .. External Functions .. */
  131. /* .. */
  132. /* .. External Subroutines .. */
  133. /* .. */
  134. /* .. Intrinsic Functions .. */
  135. /* .. */
  136. /* .. Executable Statements .. */
  137. /* Test the input parameters. */
  138. /* Parameter adjustments */
  139. a_dim1 = *lda - 1 - 0 + 1;
  140. a_offset = 0 + a_dim1 * 0;
  141. a -= a_offset;
  142. /* Function Body */
  143. *info = 0;
  144. normaltransr = _starpu_lsame_(transr, "N");
  145. lower = _starpu_lsame_(uplo, "L");
  146. if (! normaltransr && ! _starpu_lsame_(transr, "T")) {
  147. *info = -1;
  148. } else if (! lower && ! _starpu_lsame_(uplo, "U")) {
  149. *info = -2;
  150. } else if (*n < 0) {
  151. *info = -3;
  152. } else if (*lda < max(1,*n)) {
  153. *info = -5;
  154. }
  155. if (*info != 0) {
  156. i__1 = -(*info);
  157. _starpu_xerbla_("DTRTTF", &i__1);
  158. return 0;
  159. }
  160. /* Quick return if possible */
  161. if (*n <= 1) {
  162. if (*n == 1) {
  163. arf[0] = a[0];
  164. }
  165. return 0;
  166. }
  167. /* Size of array ARF(0:nt-1) */
  168. nt = *n * (*n + 1) / 2;
  169. /* Set N1 and N2 depending on LOWER: for N even N1=N2=K */
  170. if (lower) {
  171. n2 = *n / 2;
  172. n1 = *n - n2;
  173. } else {
  174. n1 = *n / 2;
  175. n2 = *n - n1;
  176. }
  177. /* If N is odd, set NISODD = .TRUE., LDA=N+1 and A is (N+1)--by--K2. */
  178. /* If N is even, set K = N/2 and NISODD = .FALSE., LDA=N and A is */
  179. /* N--by--(N+1)/2. */
  180. if (*n % 2 == 0) {
  181. k = *n / 2;
  182. nisodd = FALSE_;
  183. if (! lower) {
  184. np1x2 = *n + *n + 2;
  185. }
  186. } else {
  187. nisodd = TRUE_;
  188. if (! lower) {
  189. nx2 = *n + *n;
  190. }
  191. }
  192. if (nisodd) {
  193. /* N is odd */
  194. if (normaltransr) {
  195. /* N is odd and TRANSR = 'N' */
  196. if (lower) {
  197. /* N is odd, TRANSR = 'N', and UPLO = 'L' */
  198. ij = 0;
  199. i__1 = n2;
  200. for (j = 0; j <= i__1; ++j) {
  201. i__2 = n2 + j;
  202. for (i__ = n1; i__ <= i__2; ++i__) {
  203. arf[ij] = a[n2 + j + i__ * a_dim1];
  204. ++ij;
  205. }
  206. i__2 = *n - 1;
  207. for (i__ = j; i__ <= i__2; ++i__) {
  208. arf[ij] = a[i__ + j * a_dim1];
  209. ++ij;
  210. }
  211. }
  212. } else {
  213. /* N is odd, TRANSR = 'N', and UPLO = 'U' */
  214. ij = nt - *n;
  215. i__1 = n1;
  216. for (j = *n - 1; j >= i__1; --j) {
  217. i__2 = j;
  218. for (i__ = 0; i__ <= i__2; ++i__) {
  219. arf[ij] = a[i__ + j * a_dim1];
  220. ++ij;
  221. }
  222. i__2 = n1 - 1;
  223. for (l = j - n1; l <= i__2; ++l) {
  224. arf[ij] = a[j - n1 + l * a_dim1];
  225. ++ij;
  226. }
  227. ij -= nx2;
  228. }
  229. }
  230. } else {
  231. /* N is odd and TRANSR = 'T' */
  232. if (lower) {
  233. /* N is odd, TRANSR = 'T', and UPLO = 'L' */
  234. ij = 0;
  235. i__1 = n2 - 1;
  236. for (j = 0; j <= i__1; ++j) {
  237. i__2 = j;
  238. for (i__ = 0; i__ <= i__2; ++i__) {
  239. arf[ij] = a[j + i__ * a_dim1];
  240. ++ij;
  241. }
  242. i__2 = *n - 1;
  243. for (i__ = n1 + j; i__ <= i__2; ++i__) {
  244. arf[ij] = a[i__ + (n1 + j) * a_dim1];
  245. ++ij;
  246. }
  247. }
  248. i__1 = *n - 1;
  249. for (j = n2; j <= i__1; ++j) {
  250. i__2 = n1 - 1;
  251. for (i__ = 0; i__ <= i__2; ++i__) {
  252. arf[ij] = a[j + i__ * a_dim1];
  253. ++ij;
  254. }
  255. }
  256. } else {
  257. /* N is odd, TRANSR = 'T', and UPLO = 'U' */
  258. ij = 0;
  259. i__1 = n1;
  260. for (j = 0; j <= i__1; ++j) {
  261. i__2 = *n - 1;
  262. for (i__ = n1; i__ <= i__2; ++i__) {
  263. arf[ij] = a[j + i__ * a_dim1];
  264. ++ij;
  265. }
  266. }
  267. i__1 = n1 - 1;
  268. for (j = 0; j <= i__1; ++j) {
  269. i__2 = j;
  270. for (i__ = 0; i__ <= i__2; ++i__) {
  271. arf[ij] = a[i__ + j * a_dim1];
  272. ++ij;
  273. }
  274. i__2 = *n - 1;
  275. for (l = n2 + j; l <= i__2; ++l) {
  276. arf[ij] = a[n2 + j + l * a_dim1];
  277. ++ij;
  278. }
  279. }
  280. }
  281. }
  282. } else {
  283. /* N is even */
  284. if (normaltransr) {
  285. /* N is even and TRANSR = 'N' */
  286. if (lower) {
  287. /* N is even, TRANSR = 'N', and UPLO = 'L' */
  288. ij = 0;
  289. i__1 = k - 1;
  290. for (j = 0; j <= i__1; ++j) {
  291. i__2 = k + j;
  292. for (i__ = k; i__ <= i__2; ++i__) {
  293. arf[ij] = a[k + j + i__ * a_dim1];
  294. ++ij;
  295. }
  296. i__2 = *n - 1;
  297. for (i__ = j; i__ <= i__2; ++i__) {
  298. arf[ij] = a[i__ + j * a_dim1];
  299. ++ij;
  300. }
  301. }
  302. } else {
  303. /* N is even, TRANSR = 'N', and UPLO = 'U' */
  304. ij = nt - *n - 1;
  305. i__1 = k;
  306. for (j = *n - 1; j >= i__1; --j) {
  307. i__2 = j;
  308. for (i__ = 0; i__ <= i__2; ++i__) {
  309. arf[ij] = a[i__ + j * a_dim1];
  310. ++ij;
  311. }
  312. i__2 = k - 1;
  313. for (l = j - k; l <= i__2; ++l) {
  314. arf[ij] = a[j - k + l * a_dim1];
  315. ++ij;
  316. }
  317. ij -= np1x2;
  318. }
  319. }
  320. } else {
  321. /* N is even and TRANSR = 'T' */
  322. if (lower) {
  323. /* N is even, TRANSR = 'T', and UPLO = 'L' */
  324. ij = 0;
  325. j = k;
  326. i__1 = *n - 1;
  327. for (i__ = k; i__ <= i__1; ++i__) {
  328. arf[ij] = a[i__ + j * a_dim1];
  329. ++ij;
  330. }
  331. i__1 = k - 2;
  332. for (j = 0; j <= i__1; ++j) {
  333. i__2 = j;
  334. for (i__ = 0; i__ <= i__2; ++i__) {
  335. arf[ij] = a[j + i__ * a_dim1];
  336. ++ij;
  337. }
  338. i__2 = *n - 1;
  339. for (i__ = k + 1 + j; i__ <= i__2; ++i__) {
  340. arf[ij] = a[i__ + (k + 1 + j) * a_dim1];
  341. ++ij;
  342. }
  343. }
  344. i__1 = *n - 1;
  345. for (j = k - 1; j <= i__1; ++j) {
  346. i__2 = k - 1;
  347. for (i__ = 0; i__ <= i__2; ++i__) {
  348. arf[ij] = a[j + i__ * a_dim1];
  349. ++ij;
  350. }
  351. }
  352. } else {
  353. /* N is even, TRANSR = 'T', and UPLO = 'U' */
  354. ij = 0;
  355. i__1 = k;
  356. for (j = 0; j <= i__1; ++j) {
  357. i__2 = *n - 1;
  358. for (i__ = k; i__ <= i__2; ++i__) {
  359. arf[ij] = a[j + i__ * a_dim1];
  360. ++ij;
  361. }
  362. }
  363. i__1 = k - 2;
  364. for (j = 0; j <= i__1; ++j) {
  365. i__2 = j;
  366. for (i__ = 0; i__ <= i__2; ++i__) {
  367. arf[ij] = a[i__ + j * a_dim1];
  368. ++ij;
  369. }
  370. i__2 = *n - 1;
  371. for (l = k + 1 + j; l <= i__2; ++l) {
  372. arf[ij] = a[k + 1 + j + l * a_dim1];
  373. ++ij;
  374. }
  375. }
  376. /* Note that here, on exit of the loop, J = K-1 */
  377. i__1 = j;
  378. for (i__ = 0; i__ <= i__1; ++i__) {
  379. arf[ij] = a[i__ + j * a_dim1];
  380. ++ij;
  381. }
  382. }
  383. }
  384. }
  385. return 0;
  386. /* End of DTRTTF */
  387. } /* _starpu_dtrttf_ */