dsptri.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /* dsptri.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 integer c__1 = 1;
  15. static doublereal c_b11 = -1.;
  16. static doublereal c_b13 = 0.;
  17. /* Subroutine */ int _starpu_dsptri_(char *uplo, integer *n, doublereal *ap, integer *
  18. ipiv, doublereal *work, integer *info)
  19. {
  20. /* System generated locals */
  21. integer i__1;
  22. doublereal d__1;
  23. /* Local variables */
  24. doublereal d__;
  25. integer j, k;
  26. doublereal t, ak;
  27. integer kc, kp, kx, kpc, npp;
  28. doublereal akp1;
  29. extern doublereal _starpu_ddot_(integer *, doublereal *, integer *, doublereal *,
  30. integer *);
  31. doublereal temp, akkp1;
  32. extern logical _starpu_lsame_(char *, char *);
  33. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  34. doublereal *, integer *), _starpu_dswap_(integer *, doublereal *, integer
  35. *, doublereal *, integer *);
  36. integer kstep;
  37. extern /* Subroutine */ int _starpu_dspmv_(char *, integer *, doublereal *,
  38. doublereal *, doublereal *, integer *, doublereal *, doublereal *,
  39. integer *);
  40. logical upper;
  41. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  42. integer kcnext;
  43. /* -- LAPACK routine (version 3.2) -- */
  44. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  45. /* November 2006 */
  46. /* .. Scalar Arguments .. */
  47. /* .. */
  48. /* .. Array Arguments .. */
  49. /* .. */
  50. /* Purpose */
  51. /* ======= */
  52. /* DSPTRI computes the inverse of a real symmetric indefinite matrix */
  53. /* A in packed storage using the factorization A = U*D*U**T or */
  54. /* A = L*D*L**T computed by DSPTRF. */
  55. /* Arguments */
  56. /* ========= */
  57. /* UPLO (input) CHARACTER*1 */
  58. /* Specifies whether the details of the factorization are stored */
  59. /* as an upper or lower triangular matrix. */
  60. /* = 'U': Upper triangular, form is A = U*D*U**T; */
  61. /* = 'L': Lower triangular, form is A = L*D*L**T. */
  62. /* N (input) INTEGER */
  63. /* The order of the matrix A. N >= 0. */
  64. /* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
  65. /* On entry, the block diagonal matrix D and the multipliers */
  66. /* used to obtain the factor U or L as computed by DSPTRF, */
  67. /* stored as a packed triangular matrix. */
  68. /* On exit, if INFO = 0, the (symmetric) inverse of the original */
  69. /* matrix, stored as a packed triangular matrix. The j-th column */
  70. /* of inv(A) is stored in the array AP as follows: */
  71. /* if UPLO = 'U', AP(i + (j-1)*j/2) = inv(A)(i,j) for 1<=i<=j; */
  72. /* if UPLO = 'L', */
  73. /* AP(i + (j-1)*(2n-j)/2) = inv(A)(i,j) for j<=i<=n. */
  74. /* IPIV (input) INTEGER array, dimension (N) */
  75. /* Details of the interchanges and the block structure of D */
  76. /* as determined by DSPTRF. */
  77. /* WORK (workspace) DOUBLE PRECISION array, dimension (N) */
  78. /* INFO (output) INTEGER */
  79. /* = 0: successful exit */
  80. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  81. /* > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its */
  82. /* inverse could not be computed. */
  83. /* ===================================================================== */
  84. /* .. Parameters .. */
  85. /* .. */
  86. /* .. Local Scalars .. */
  87. /* .. */
  88. /* .. External Functions .. */
  89. /* .. */
  90. /* .. External Subroutines .. */
  91. /* .. */
  92. /* .. Intrinsic Functions .. */
  93. /* .. */
  94. /* .. Executable Statements .. */
  95. /* Test the input parameters. */
  96. /* Parameter adjustments */
  97. --work;
  98. --ipiv;
  99. --ap;
  100. /* Function Body */
  101. *info = 0;
  102. upper = _starpu_lsame_(uplo, "U");
  103. if (! upper && ! _starpu_lsame_(uplo, "L")) {
  104. *info = -1;
  105. } else if (*n < 0) {
  106. *info = -2;
  107. }
  108. if (*info != 0) {
  109. i__1 = -(*info);
  110. _starpu_xerbla_("DSPTRI", &i__1);
  111. return 0;
  112. }
  113. /* Quick return if possible */
  114. if (*n == 0) {
  115. return 0;
  116. }
  117. /* Check that the diagonal matrix D is nonsingular. */
  118. if (upper) {
  119. /* Upper triangular storage: examine D from bottom to top */
  120. kp = *n * (*n + 1) / 2;
  121. for (*info = *n; *info >= 1; --(*info)) {
  122. if (ipiv[*info] > 0 && ap[kp] == 0.) {
  123. return 0;
  124. }
  125. kp -= *info;
  126. /* L10: */
  127. }
  128. } else {
  129. /* Lower triangular storage: examine D from top to bottom. */
  130. kp = 1;
  131. i__1 = *n;
  132. for (*info = 1; *info <= i__1; ++(*info)) {
  133. if (ipiv[*info] > 0 && ap[kp] == 0.) {
  134. return 0;
  135. }
  136. kp = kp + *n - *info + 1;
  137. /* L20: */
  138. }
  139. }
  140. *info = 0;
  141. if (upper) {
  142. /* Compute inv(A) from the factorization A = U*D*U'. */
  143. /* K is the main loop index, increasing from 1 to N in steps of */
  144. /* 1 or 2, depending on the size of the diagonal blocks. */
  145. k = 1;
  146. kc = 1;
  147. L30:
  148. /* If K > N, exit from loop. */
  149. if (k > *n) {
  150. goto L50;
  151. }
  152. kcnext = kc + k;
  153. if (ipiv[k] > 0) {
  154. /* 1 x 1 diagonal block */
  155. /* Invert the diagonal block. */
  156. ap[kc + k - 1] = 1. / ap[kc + k - 1];
  157. /* Compute column K of the inverse. */
  158. if (k > 1) {
  159. i__1 = k - 1;
  160. _starpu_dcopy_(&i__1, &ap[kc], &c__1, &work[1], &c__1);
  161. i__1 = k - 1;
  162. _starpu_dspmv_(uplo, &i__1, &c_b11, &ap[1], &work[1], &c__1, &c_b13, &
  163. ap[kc], &c__1);
  164. i__1 = k - 1;
  165. ap[kc + k - 1] -= _starpu_ddot_(&i__1, &work[1], &c__1, &ap[kc], &
  166. c__1);
  167. }
  168. kstep = 1;
  169. } else {
  170. /* 2 x 2 diagonal block */
  171. /* Invert the diagonal block. */
  172. t = (d__1 = ap[kcnext + k - 1], abs(d__1));
  173. ak = ap[kc + k - 1] / t;
  174. akp1 = ap[kcnext + k] / t;
  175. akkp1 = ap[kcnext + k - 1] / t;
  176. d__ = t * (ak * akp1 - 1.);
  177. ap[kc + k - 1] = akp1 / d__;
  178. ap[kcnext + k] = ak / d__;
  179. ap[kcnext + k - 1] = -akkp1 / d__;
  180. /* Compute columns K and K+1 of the inverse. */
  181. if (k > 1) {
  182. i__1 = k - 1;
  183. _starpu_dcopy_(&i__1, &ap[kc], &c__1, &work[1], &c__1);
  184. i__1 = k - 1;
  185. _starpu_dspmv_(uplo, &i__1, &c_b11, &ap[1], &work[1], &c__1, &c_b13, &
  186. ap[kc], &c__1);
  187. i__1 = k - 1;
  188. ap[kc + k - 1] -= _starpu_ddot_(&i__1, &work[1], &c__1, &ap[kc], &
  189. c__1);
  190. i__1 = k - 1;
  191. ap[kcnext + k - 1] -= _starpu_ddot_(&i__1, &ap[kc], &c__1, &ap[kcnext]
  192. , &c__1);
  193. i__1 = k - 1;
  194. _starpu_dcopy_(&i__1, &ap[kcnext], &c__1, &work[1], &c__1);
  195. i__1 = k - 1;
  196. _starpu_dspmv_(uplo, &i__1, &c_b11, &ap[1], &work[1], &c__1, &c_b13, &
  197. ap[kcnext], &c__1);
  198. i__1 = k - 1;
  199. ap[kcnext + k] -= _starpu_ddot_(&i__1, &work[1], &c__1, &ap[kcnext], &
  200. c__1);
  201. }
  202. kstep = 2;
  203. kcnext = kcnext + k + 1;
  204. }
  205. kp = (i__1 = ipiv[k], abs(i__1));
  206. if (kp != k) {
  207. /* Interchange rows and columns K and KP in the leading */
  208. /* submatrix A(1:k+1,1:k+1) */
  209. kpc = (kp - 1) * kp / 2 + 1;
  210. i__1 = kp - 1;
  211. _starpu_dswap_(&i__1, &ap[kc], &c__1, &ap[kpc], &c__1);
  212. kx = kpc + kp - 1;
  213. i__1 = k - 1;
  214. for (j = kp + 1; j <= i__1; ++j) {
  215. kx = kx + j - 1;
  216. temp = ap[kc + j - 1];
  217. ap[kc + j - 1] = ap[kx];
  218. ap[kx] = temp;
  219. /* L40: */
  220. }
  221. temp = ap[kc + k - 1];
  222. ap[kc + k - 1] = ap[kpc + kp - 1];
  223. ap[kpc + kp - 1] = temp;
  224. if (kstep == 2) {
  225. temp = ap[kc + k + k - 1];
  226. ap[kc + k + k - 1] = ap[kc + k + kp - 1];
  227. ap[kc + k + kp - 1] = temp;
  228. }
  229. }
  230. k += kstep;
  231. kc = kcnext;
  232. goto L30;
  233. L50:
  234. ;
  235. } else {
  236. /* Compute inv(A) from the factorization A = L*D*L'. */
  237. /* K is the main loop index, increasing from 1 to N in steps of */
  238. /* 1 or 2, depending on the size of the diagonal blocks. */
  239. npp = *n * (*n + 1) / 2;
  240. k = *n;
  241. kc = npp;
  242. L60:
  243. /* If K < 1, exit from loop. */
  244. if (k < 1) {
  245. goto L80;
  246. }
  247. kcnext = kc - (*n - k + 2);
  248. if (ipiv[k] > 0) {
  249. /* 1 x 1 diagonal block */
  250. /* Invert the diagonal block. */
  251. ap[kc] = 1. / ap[kc];
  252. /* Compute column K of the inverse. */
  253. if (k < *n) {
  254. i__1 = *n - k;
  255. _starpu_dcopy_(&i__1, &ap[kc + 1], &c__1, &work[1], &c__1);
  256. i__1 = *n - k;
  257. _starpu_dspmv_(uplo, &i__1, &c_b11, &ap[kc + *n - k + 1], &work[1], &
  258. c__1, &c_b13, &ap[kc + 1], &c__1);
  259. i__1 = *n - k;
  260. ap[kc] -= _starpu_ddot_(&i__1, &work[1], &c__1, &ap[kc + 1], &c__1);
  261. }
  262. kstep = 1;
  263. } else {
  264. /* 2 x 2 diagonal block */
  265. /* Invert the diagonal block. */
  266. t = (d__1 = ap[kcnext + 1], abs(d__1));
  267. ak = ap[kcnext] / t;
  268. akp1 = ap[kc] / t;
  269. akkp1 = ap[kcnext + 1] / t;
  270. d__ = t * (ak * akp1 - 1.);
  271. ap[kcnext] = akp1 / d__;
  272. ap[kc] = ak / d__;
  273. ap[kcnext + 1] = -akkp1 / d__;
  274. /* Compute columns K-1 and K of the inverse. */
  275. if (k < *n) {
  276. i__1 = *n - k;
  277. _starpu_dcopy_(&i__1, &ap[kc + 1], &c__1, &work[1], &c__1);
  278. i__1 = *n - k;
  279. _starpu_dspmv_(uplo, &i__1, &c_b11, &ap[kc + (*n - k + 1)], &work[1],
  280. &c__1, &c_b13, &ap[kc + 1], &c__1);
  281. i__1 = *n - k;
  282. ap[kc] -= _starpu_ddot_(&i__1, &work[1], &c__1, &ap[kc + 1], &c__1);
  283. i__1 = *n - k;
  284. ap[kcnext + 1] -= _starpu_ddot_(&i__1, &ap[kc + 1], &c__1, &ap[kcnext
  285. + 2], &c__1);
  286. i__1 = *n - k;
  287. _starpu_dcopy_(&i__1, &ap[kcnext + 2], &c__1, &work[1], &c__1);
  288. i__1 = *n - k;
  289. _starpu_dspmv_(uplo, &i__1, &c_b11, &ap[kc + (*n - k + 1)], &work[1],
  290. &c__1, &c_b13, &ap[kcnext + 2], &c__1);
  291. i__1 = *n - k;
  292. ap[kcnext] -= _starpu_ddot_(&i__1, &work[1], &c__1, &ap[kcnext + 2], &
  293. c__1);
  294. }
  295. kstep = 2;
  296. kcnext -= *n - k + 3;
  297. }
  298. kp = (i__1 = ipiv[k], abs(i__1));
  299. if (kp != k) {
  300. /* Interchange rows and columns K and KP in the trailing */
  301. /* submatrix A(k-1:n,k-1:n) */
  302. kpc = npp - (*n - kp + 1) * (*n - kp + 2) / 2 + 1;
  303. if (kp < *n) {
  304. i__1 = *n - kp;
  305. _starpu_dswap_(&i__1, &ap[kc + kp - k + 1], &c__1, &ap[kpc + 1], &
  306. c__1);
  307. }
  308. kx = kc + kp - k;
  309. i__1 = kp - 1;
  310. for (j = k + 1; j <= i__1; ++j) {
  311. kx = kx + *n - j + 1;
  312. temp = ap[kc + j - k];
  313. ap[kc + j - k] = ap[kx];
  314. ap[kx] = temp;
  315. /* L70: */
  316. }
  317. temp = ap[kc];
  318. ap[kc] = ap[kpc];
  319. ap[kpc] = temp;
  320. if (kstep == 2) {
  321. temp = ap[kc - *n + k - 1];
  322. ap[kc - *n + k - 1] = ap[kc - *n + kp - 1];
  323. ap[kc - *n + kp - 1] = temp;
  324. }
  325. }
  326. k -= kstep;
  327. kc = kcnext;
  328. goto L60;
  329. L80:
  330. ;
  331. }
  332. return 0;
  333. /* End of DSPTRI */
  334. } /* _starpu_dsptri_ */