dsytri.c 11 KB

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