dpftri.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. /* dpftri.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. /* Table of constant values */
  14. static doublereal c_b11 = 1.;
  15. /* Subroutine */ int _starpu_dpftri_(char *transr, char *uplo, integer *n, doublereal
  16. *a, integer *info)
  17. {
  18. /* System generated locals */
  19. integer i__1, i__2;
  20. /* Local variables */
  21. integer k, n1, n2;
  22. logical normaltransr;
  23. extern logical _starpu_lsame_(char *, char *);
  24. extern /* Subroutine */ int _starpu_dtrmm_(char *, char *, char *, char *,
  25. integer *, integer *, doublereal *, doublereal *, integer *,
  26. doublereal *, integer *);
  27. logical lower;
  28. extern /* Subroutine */ int _starpu_dsyrk_(char *, char *, integer *, integer *,
  29. doublereal *, doublereal *, integer *, doublereal *, doublereal *,
  30. integer *), _starpu_xerbla_(char *, integer *);
  31. logical nisodd;
  32. extern /* Subroutine */ int _starpu_dlauum_(char *, integer *, doublereal *,
  33. integer *, integer *), _starpu_dtftri_(char *, char *, char *,
  34. integer *, doublereal *, integer *);
  35. /* -- LAPACK routine (version 3.2) -- */
  36. /* -- Contributed by Fred Gustavson of the IBM Watson Research Center -- */
  37. /* -- November 2008 -- */
  38. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  39. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  40. /* .. Scalar Arguments .. */
  41. /* .. Array Arguments .. */
  42. /* .. */
  43. /* Purpose */
  44. /* ======= */
  45. /* DPFTRI computes the inverse of a (real) symmetric positive definite */
  46. /* matrix A using the Cholesky factorization A = U**T*U or A = L*L**T */
  47. /* computed by DPFTRF. */
  48. /* Arguments */
  49. /* ========= */
  50. /* TRANSR (input) CHARACTER */
  51. /* = 'N': The Normal TRANSR of RFP A is stored; */
  52. /* = 'T': The Transpose TRANSR of RFP A is stored. */
  53. /* UPLO (input) CHARACTER */
  54. /* = 'U': Upper triangle of A is stored; */
  55. /* = 'L': Lower triangle of A is stored. */
  56. /* N (input) INTEGER */
  57. /* The order of the matrix A. N >= 0. */
  58. /* A (input/output) DOUBLE PRECISION array, dimension ( N*(N+1)/2 ) */
  59. /* On entry, the symmetric matrix A in RFP format. RFP format is */
  60. /* described by TRANSR, UPLO, and N as follows: If TRANSR = 'N' */
  61. /* then RFP A is (0:N,0:k-1) when N is even; k=N/2. RFP A is */
  62. /* (0:N-1,0:k) when N is odd; k=N/2. IF TRANSR = 'T' then RFP is */
  63. /* the transpose of RFP A as defined when */
  64. /* TRANSR = 'N'. The contents of RFP A are defined by UPLO as */
  65. /* follows: If UPLO = 'U' the RFP A contains the nt elements of */
  66. /* upper packed A. If UPLO = 'L' the RFP A contains the elements */
  67. /* of lower packed A. The LDA of RFP A is (N+1)/2 when TRANSR = */
  68. /* 'T'. When TRANSR is 'N' the LDA is N+1 when N is even and N */
  69. /* is odd. See the Note below for more details. */
  70. /* On exit, the symmetric inverse of the original matrix, in the */
  71. /* same storage format. */
  72. /* INFO (output) INTEGER */
  73. /* = 0: successful exit */
  74. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  75. /* > 0: if INFO = i, the (i,i) element of the factor U or L is */
  76. /* zero, and the inverse could not be computed. */
  77. /* Notes */
  78. /* ===== */
  79. /* We first consider Rectangular Full Packed (RFP) Format when N is */
  80. /* even. We give an example where N = 6. */
  81. /* AP is Upper AP is Lower */
  82. /* 00 01 02 03 04 05 00 */
  83. /* 11 12 13 14 15 10 11 */
  84. /* 22 23 24 25 20 21 22 */
  85. /* 33 34 35 30 31 32 33 */
  86. /* 44 45 40 41 42 43 44 */
  87. /* 55 50 51 52 53 54 55 */
  88. /* Let TRANSR = 'N'. RFP holds AP as follows: */
  89. /* For UPLO = 'U' the upper trapezoid A(0:5,0:2) consists of the last */
  90. /* three columns of AP upper. The lower triangle A(4:6,0:2) consists of */
  91. /* the transpose of the first three columns of AP upper. */
  92. /* For UPLO = 'L' the lower trapezoid A(1:6,0:2) consists of the first */
  93. /* three columns of AP lower. The upper triangle A(0:2,0:2) consists of */
  94. /* the transpose of the last three columns of AP lower. */
  95. /* This covers the case N even and TRANSR = 'N'. */
  96. /* RFP A RFP A */
  97. /* 03 04 05 33 43 53 */
  98. /* 13 14 15 00 44 54 */
  99. /* 23 24 25 10 11 55 */
  100. /* 33 34 35 20 21 22 */
  101. /* 00 44 45 30 31 32 */
  102. /* 01 11 55 40 41 42 */
  103. /* 02 12 22 50 51 52 */
  104. /* Now let TRANSR = 'T'. RFP A in both UPLO cases is just the */
  105. /* transpose of RFP A above. One therefore gets: */
  106. /* RFP A RFP A */
  107. /* 03 13 23 33 00 01 02 33 00 10 20 30 40 50 */
  108. /* 04 14 24 34 44 11 12 43 44 11 21 31 41 51 */
  109. /* 05 15 25 35 45 55 22 53 54 55 22 32 42 52 */
  110. /* We first consider Rectangular Full Packed (RFP) Format when N is */
  111. /* odd. We give an example where N = 5. */
  112. /* AP is Upper AP is Lower */
  113. /* 00 01 02 03 04 00 */
  114. /* 11 12 13 14 10 11 */
  115. /* 22 23 24 20 21 22 */
  116. /* 33 34 30 31 32 33 */
  117. /* 44 40 41 42 43 44 */
  118. /* Let TRANSR = 'N'. RFP holds AP as follows: */
  119. /* For UPLO = 'U' the upper trapezoid A(0:4,0:2) consists of the last */
  120. /* three columns of AP upper. The lower triangle A(3:4,0:1) consists of */
  121. /* the transpose of the first two columns of AP upper. */
  122. /* For UPLO = 'L' the lower trapezoid A(0:4,0:2) consists of the first */
  123. /* three columns of AP lower. The upper triangle A(0:1,1:2) consists of */
  124. /* the transpose of the last two columns of AP lower. */
  125. /* This covers the case N odd and TRANSR = 'N'. */
  126. /* RFP A RFP A */
  127. /* 02 03 04 00 33 43 */
  128. /* 12 13 14 10 11 44 */
  129. /* 22 23 24 20 21 22 */
  130. /* 00 33 34 30 31 32 */
  131. /* 01 11 44 40 41 42 */
  132. /* Now let TRANSR = 'T'. RFP A in both UPLO cases is just the */
  133. /* transpose of RFP A above. One therefore gets: */
  134. /* RFP A RFP A */
  135. /* 02 12 22 00 01 00 10 20 30 40 50 */
  136. /* 03 13 23 33 11 33 11 21 31 41 51 */
  137. /* 04 14 24 34 44 43 44 22 32 42 52 */
  138. /* ===================================================================== */
  139. /* .. Parameters .. */
  140. /* .. */
  141. /* .. Local Scalars .. */
  142. /* .. */
  143. /* .. External Functions .. */
  144. /* .. */
  145. /* .. External Subroutines .. */
  146. /* .. */
  147. /* .. Intrinsic Functions .. */
  148. /* .. */
  149. /* .. Executable Statements .. */
  150. /* Test the input parameters. */
  151. *info = 0;
  152. normaltransr = _starpu_lsame_(transr, "N");
  153. lower = _starpu_lsame_(uplo, "L");
  154. if (! normaltransr && ! _starpu_lsame_(transr, "T")) {
  155. *info = -1;
  156. } else if (! lower && ! _starpu_lsame_(uplo, "U")) {
  157. *info = -2;
  158. } else if (*n < 0) {
  159. *info = -3;
  160. }
  161. if (*info != 0) {
  162. i__1 = -(*info);
  163. _starpu_xerbla_("DPFTRI", &i__1);
  164. return 0;
  165. }
  166. /* Quick return if possible */
  167. if (*n == 0) {
  168. return 0;
  169. }
  170. /* Invert the triangular Cholesky factor U or L. */
  171. _starpu_dtftri_(transr, uplo, "N", n, a, info);
  172. if (*info > 0) {
  173. return 0;
  174. }
  175. /* If N is odd, set NISODD = .TRUE. */
  176. /* If N is even, set K = N/2 and NISODD = .FALSE. */
  177. if (*n % 2 == 0) {
  178. k = *n / 2;
  179. nisodd = FALSE_;
  180. } else {
  181. nisodd = TRUE_;
  182. }
  183. /* Set N1 and N2 depending on LOWER */
  184. if (lower) {
  185. n2 = *n / 2;
  186. n1 = *n - n2;
  187. } else {
  188. n1 = *n / 2;
  189. n2 = *n - n1;
  190. }
  191. /* Start execution of triangular matrix multiply: inv(U)*inv(U)^C or */
  192. /* inv(L)^C*inv(L). There are eight cases. */
  193. if (nisodd) {
  194. /* N is odd */
  195. if (normaltransr) {
  196. /* N is odd and TRANSR = 'N' */
  197. if (lower) {
  198. /* SRPA for LOWER, NORMAL and N is odd ( a(0:n-1,0:N1-1) ) */
  199. /* T1 -> a(0,0), T2 -> a(0,1), S -> a(N1,0) */
  200. /* T1 -> a(0), T2 -> a(n), S -> a(N1) */
  201. _starpu_dlauum_("L", &n1, a, n, info);
  202. _starpu_dsyrk_("L", "T", &n1, &n2, &c_b11, &a[n1], n, &c_b11, a, n);
  203. _starpu_dtrmm_("L", "U", "N", "N", &n2, &n1, &c_b11, &a[*n], n, &a[n1]
  204. , n);
  205. _starpu_dlauum_("U", &n2, &a[*n], n, info);
  206. } else {
  207. /* SRPA for UPPER, NORMAL and N is odd ( a(0:n-1,0:N2-1) */
  208. /* T1 -> a(N1+1,0), T2 -> a(N1,0), S -> a(0,0) */
  209. /* T1 -> a(N2), T2 -> a(N1), S -> a(0) */
  210. _starpu_dlauum_("L", &n1, &a[n2], n, info);
  211. _starpu_dsyrk_("L", "N", &n1, &n2, &c_b11, a, n, &c_b11, &a[n2], n);
  212. _starpu_dtrmm_("R", "U", "T", "N", &n1, &n2, &c_b11, &a[n1], n, a, n);
  213. _starpu_dlauum_("U", &n2, &a[n1], n, info);
  214. }
  215. } else {
  216. /* N is odd and TRANSR = 'T' */
  217. if (lower) {
  218. /* SRPA for LOWER, TRANSPOSE, and N is odd */
  219. /* T1 -> a(0), T2 -> a(1), S -> a(0+N1*N1) */
  220. _starpu_dlauum_("U", &n1, a, &n1, info);
  221. _starpu_dsyrk_("U", "N", &n1, &n2, &c_b11, &a[n1 * n1], &n1, &c_b11,
  222. a, &n1);
  223. _starpu_dtrmm_("R", "L", "N", "N", &n1, &n2, &c_b11, &a[1], &n1, &a[
  224. n1 * n1], &n1);
  225. _starpu_dlauum_("L", &n2, &a[1], &n1, info);
  226. } else {
  227. /* SRPA for UPPER, TRANSPOSE, and N is odd */
  228. /* T1 -> a(0+N2*N2), T2 -> a(0+N1*N2), S -> a(0) */
  229. _starpu_dlauum_("U", &n1, &a[n2 * n2], &n2, info);
  230. _starpu_dsyrk_("U", "T", &n1, &n2, &c_b11, a, &n2, &c_b11, &a[n2 * n2]
  231. , &n2);
  232. _starpu_dtrmm_("L", "L", "T", "N", &n2, &n1, &c_b11, &a[n1 * n2], &n2,
  233. a, &n2);
  234. _starpu_dlauum_("L", &n2, &a[n1 * n2], &n2, info);
  235. }
  236. }
  237. } else {
  238. /* N is even */
  239. if (normaltransr) {
  240. /* N is even and TRANSR = 'N' */
  241. if (lower) {
  242. /* SRPA for LOWER, NORMAL, and N is even ( a(0:n,0:k-1) ) */
  243. /* T1 -> a(1,0), T2 -> a(0,0), S -> a(k+1,0) */
  244. /* T1 -> a(1), T2 -> a(0), S -> a(k+1) */
  245. i__1 = *n + 1;
  246. _starpu_dlauum_("L", &k, &a[1], &i__1, info);
  247. i__1 = *n + 1;
  248. i__2 = *n + 1;
  249. _starpu_dsyrk_("L", "T", &k, &k, &c_b11, &a[k + 1], &i__1, &c_b11, &a[
  250. 1], &i__2);
  251. i__1 = *n + 1;
  252. i__2 = *n + 1;
  253. _starpu_dtrmm_("L", "U", "N", "N", &k, &k, &c_b11, a, &i__1, &a[k + 1]
  254. , &i__2);
  255. i__1 = *n + 1;
  256. _starpu_dlauum_("U", &k, a, &i__1, info);
  257. } else {
  258. /* SRPA for UPPER, NORMAL, and N is even ( a(0:n,0:k-1) ) */
  259. /* T1 -> a(k+1,0) , T2 -> a(k,0), S -> a(0,0) */
  260. /* T1 -> a(k+1), T2 -> a(k), S -> a(0) */
  261. i__1 = *n + 1;
  262. _starpu_dlauum_("L", &k, &a[k + 1], &i__1, info);
  263. i__1 = *n + 1;
  264. i__2 = *n + 1;
  265. _starpu_dsyrk_("L", "N", &k, &k, &c_b11, a, &i__1, &c_b11, &a[k + 1],
  266. &i__2);
  267. i__1 = *n + 1;
  268. i__2 = *n + 1;
  269. _starpu_dtrmm_("R", "U", "T", "N", &k, &k, &c_b11, &a[k], &i__1, a, &
  270. i__2);
  271. i__1 = *n + 1;
  272. _starpu_dlauum_("U", &k, &a[k], &i__1, info);
  273. }
  274. } else {
  275. /* N is even and TRANSR = 'T' */
  276. if (lower) {
  277. /* SRPA for LOWER, TRANSPOSE, and N is even (see paper) */
  278. /* T1 -> B(0,1), T2 -> B(0,0), S -> B(0,k+1), */
  279. /* T1 -> a(0+k), T2 -> a(0+0), S -> a(0+k*(k+1)); lda=k */
  280. _starpu_dlauum_("U", &k, &a[k], &k, info);
  281. _starpu_dsyrk_("U", "N", &k, &k, &c_b11, &a[k * (k + 1)], &k, &c_b11,
  282. &a[k], &k);
  283. _starpu_dtrmm_("R", "L", "N", "N", &k, &k, &c_b11, a, &k, &a[k * (k +
  284. 1)], &k);
  285. _starpu_dlauum_("L", &k, a, &k, info);
  286. } else {
  287. /* SRPA for UPPER, TRANSPOSE, and N is even (see paper) */
  288. /* T1 -> B(0,k+1), T2 -> B(0,k), S -> B(0,0), */
  289. /* T1 -> a(0+k*(k+1)), T2 -> a(0+k*k), S -> a(0+0)); lda=k */
  290. _starpu_dlauum_("U", &k, &a[k * (k + 1)], &k, info);
  291. _starpu_dsyrk_("U", "T", &k, &k, &c_b11, a, &k, &c_b11, &a[k * (k + 1)
  292. ], &k);
  293. _starpu_dtrmm_("L", "L", "T", "N", &k, &k, &c_b11, &a[k * k], &k, a, &
  294. k);
  295. _starpu_dlauum_("L", &k, &a[k * k], &k, info);
  296. }
  297. }
  298. }
  299. return 0;
  300. /* End of DPFTRI */
  301. } /* _starpu_dpftri_ */