dsytrs.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. /* dsytrs.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_b7 = -1.;
  15. static integer c__1 = 1;
  16. static doublereal c_b19 = 1.;
  17. /* Subroutine */ int dsytrs_(char *uplo, integer *n, integer *nrhs,
  18. doublereal *a, integer *lda, integer *ipiv, doublereal *b, integer *
  19. ldb, integer *info)
  20. {
  21. /* System generated locals */
  22. integer a_dim1, a_offset, b_dim1, b_offset, i__1;
  23. doublereal d__1;
  24. /* Local variables */
  25. integer j, k;
  26. doublereal ak, bk;
  27. integer kp;
  28. doublereal akm1, bkm1;
  29. extern /* Subroutine */ int dger_(integer *, integer *, doublereal *,
  30. doublereal *, integer *, doublereal *, integer *, doublereal *,
  31. integer *);
  32. doublereal akm1k;
  33. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  34. integer *);
  35. extern logical lsame_(char *, char *);
  36. doublereal denom;
  37. extern /* Subroutine */ int dgemv_(char *, integer *, integer *,
  38. doublereal *, doublereal *, integer *, doublereal *, integer *,
  39. doublereal *, doublereal *, integer *), dswap_(integer *,
  40. doublereal *, integer *, doublereal *, integer *);
  41. logical upper;
  42. extern /* Subroutine */ int xerbla_(char *, integer *);
  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. /* DSYTRS solves a system of linear equations A*X = B with a real */
  53. /* symmetric matrix A using the factorization A = U*D*U**T or */
  54. /* A = L*D*L**T computed by DSYTRF. */
  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. /* NRHS (input) INTEGER */
  65. /* The number of right hand sides, i.e., the number of columns */
  66. /* of the matrix B. NRHS >= 0. */
  67. /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */
  68. /* The block diagonal matrix D and the multipliers used to */
  69. /* obtain the factor U or L as computed by DSYTRF. */
  70. /* LDA (input) INTEGER */
  71. /* The leading dimension of the array A. LDA >= max(1,N). */
  72. /* IPIV (input) INTEGER array, dimension (N) */
  73. /* Details of the interchanges and the block structure of D */
  74. /* as determined by DSYTRF. */
  75. /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */
  76. /* On entry, the right hand side matrix B. */
  77. /* On exit, the solution matrix X. */
  78. /* LDB (input) INTEGER */
  79. /* The leading dimension of the array B. LDB >= max(1,N). */
  80. /* INFO (output) INTEGER */
  81. /* = 0: successful exit */
  82. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  83. /* ===================================================================== */
  84. /* .. Parameters .. */
  85. /* .. */
  86. /* .. Local Scalars .. */
  87. /* .. */
  88. /* .. External Functions .. */
  89. /* .. */
  90. /* .. External Subroutines .. */
  91. /* .. */
  92. /* .. Intrinsic Functions .. */
  93. /* .. */
  94. /* .. Executable Statements .. */
  95. /* Parameter adjustments */
  96. a_dim1 = *lda;
  97. a_offset = 1 + a_dim1;
  98. a -= a_offset;
  99. --ipiv;
  100. b_dim1 = *ldb;
  101. b_offset = 1 + b_dim1;
  102. b -= b_offset;
  103. /* Function Body */
  104. *info = 0;
  105. upper = lsame_(uplo, "U");
  106. if (! upper && ! lsame_(uplo, "L")) {
  107. *info = -1;
  108. } else if (*n < 0) {
  109. *info = -2;
  110. } else if (*nrhs < 0) {
  111. *info = -3;
  112. } else if (*lda < max(1,*n)) {
  113. *info = -5;
  114. } else if (*ldb < max(1,*n)) {
  115. *info = -8;
  116. }
  117. if (*info != 0) {
  118. i__1 = -(*info);
  119. xerbla_("DSYTRS", &i__1);
  120. return 0;
  121. }
  122. /* Quick return if possible */
  123. if (*n == 0 || *nrhs == 0) {
  124. return 0;
  125. }
  126. if (upper) {
  127. /* Solve A*X = B, where A = U*D*U'. */
  128. /* First solve U*D*X = B, overwriting B with X. */
  129. /* K is the main loop index, decreasing from N to 1 in steps of */
  130. /* 1 or 2, depending on the size of the diagonal blocks. */
  131. k = *n;
  132. L10:
  133. /* If K < 1, exit from loop. */
  134. if (k < 1) {
  135. goto L30;
  136. }
  137. if (ipiv[k] > 0) {
  138. /* 1 x 1 diagonal block */
  139. /* Interchange rows K and IPIV(K). */
  140. kp = ipiv[k];
  141. if (kp != k) {
  142. dswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb);
  143. }
  144. /* Multiply by inv(U(K)), where U(K) is the transformation */
  145. /* stored in column K of A. */
  146. i__1 = k - 1;
  147. dger_(&i__1, nrhs, &c_b7, &a[k * a_dim1 + 1], &c__1, &b[k +
  148. b_dim1], ldb, &b[b_dim1 + 1], ldb);
  149. /* Multiply by the inverse of the diagonal block. */
  150. d__1 = 1. / a[k + k * a_dim1];
  151. dscal_(nrhs, &d__1, &b[k + b_dim1], ldb);
  152. --k;
  153. } else {
  154. /* 2 x 2 diagonal block */
  155. /* Interchange rows K-1 and -IPIV(K). */
  156. kp = -ipiv[k];
  157. if (kp != k - 1) {
  158. dswap_(nrhs, &b[k - 1 + b_dim1], ldb, &b[kp + b_dim1], ldb);
  159. }
  160. /* Multiply by inv(U(K)), where U(K) is the transformation */
  161. /* stored in columns K-1 and K of A. */
  162. i__1 = k - 2;
  163. dger_(&i__1, nrhs, &c_b7, &a[k * a_dim1 + 1], &c__1, &b[k +
  164. b_dim1], ldb, &b[b_dim1 + 1], ldb);
  165. i__1 = k - 2;
  166. dger_(&i__1, nrhs, &c_b7, &a[(k - 1) * a_dim1 + 1], &c__1, &b[k -
  167. 1 + b_dim1], ldb, &b[b_dim1 + 1], ldb);
  168. /* Multiply by the inverse of the diagonal block. */
  169. akm1k = a[k - 1 + k * a_dim1];
  170. akm1 = a[k - 1 + (k - 1) * a_dim1] / akm1k;
  171. ak = a[k + k * a_dim1] / akm1k;
  172. denom = akm1 * ak - 1.;
  173. i__1 = *nrhs;
  174. for (j = 1; j <= i__1; ++j) {
  175. bkm1 = b[k - 1 + j * b_dim1] / akm1k;
  176. bk = b[k + j * b_dim1] / akm1k;
  177. b[k - 1 + j * b_dim1] = (ak * bkm1 - bk) / denom;
  178. b[k + j * b_dim1] = (akm1 * bk - bkm1) / denom;
  179. /* L20: */
  180. }
  181. k += -2;
  182. }
  183. goto L10;
  184. L30:
  185. /* Next solve U'*X = B, overwriting B with X. */
  186. /* K is the main loop index, increasing from 1 to N in steps of */
  187. /* 1 or 2, depending on the size of the diagonal blocks. */
  188. k = 1;
  189. L40:
  190. /* If K > N, exit from loop. */
  191. if (k > *n) {
  192. goto L50;
  193. }
  194. if (ipiv[k] > 0) {
  195. /* 1 x 1 diagonal block */
  196. /* Multiply by inv(U'(K)), where U(K) is the transformation */
  197. /* stored in column K of A. */
  198. i__1 = k - 1;
  199. dgemv_("Transpose", &i__1, nrhs, &c_b7, &b[b_offset], ldb, &a[k *
  200. a_dim1 + 1], &c__1, &c_b19, &b[k + b_dim1], ldb);
  201. /* Interchange rows K and IPIV(K). */
  202. kp = ipiv[k];
  203. if (kp != k) {
  204. dswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb);
  205. }
  206. ++k;
  207. } else {
  208. /* 2 x 2 diagonal block */
  209. /* Multiply by inv(U'(K+1)), where U(K+1) is the transformation */
  210. /* stored in columns K and K+1 of A. */
  211. i__1 = k - 1;
  212. dgemv_("Transpose", &i__1, nrhs, &c_b7, &b[b_offset], ldb, &a[k *
  213. a_dim1 + 1], &c__1, &c_b19, &b[k + b_dim1], ldb);
  214. i__1 = k - 1;
  215. dgemv_("Transpose", &i__1, nrhs, &c_b7, &b[b_offset], ldb, &a[(k
  216. + 1) * a_dim1 + 1], &c__1, &c_b19, &b[k + 1 + b_dim1],
  217. ldb);
  218. /* Interchange rows K and -IPIV(K). */
  219. kp = -ipiv[k];
  220. if (kp != k) {
  221. dswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb);
  222. }
  223. k += 2;
  224. }
  225. goto L40;
  226. L50:
  227. ;
  228. } else {
  229. /* Solve A*X = B, where A = L*D*L'. */
  230. /* First solve L*D*X = B, overwriting B with X. */
  231. /* K is the main loop index, increasing from 1 to N in steps of */
  232. /* 1 or 2, depending on the size of the diagonal blocks. */
  233. k = 1;
  234. L60:
  235. /* If K > N, exit from loop. */
  236. if (k > *n) {
  237. goto L80;
  238. }
  239. if (ipiv[k] > 0) {
  240. /* 1 x 1 diagonal block */
  241. /* Interchange rows K and IPIV(K). */
  242. kp = ipiv[k];
  243. if (kp != k) {
  244. dswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb);
  245. }
  246. /* Multiply by inv(L(K)), where L(K) is the transformation */
  247. /* stored in column K of A. */
  248. if (k < *n) {
  249. i__1 = *n - k;
  250. dger_(&i__1, nrhs, &c_b7, &a[k + 1 + k * a_dim1], &c__1, &b[k
  251. + b_dim1], ldb, &b[k + 1 + b_dim1], ldb);
  252. }
  253. /* Multiply by the inverse of the diagonal block. */
  254. d__1 = 1. / a[k + k * a_dim1];
  255. dscal_(nrhs, &d__1, &b[k + b_dim1], ldb);
  256. ++k;
  257. } else {
  258. /* 2 x 2 diagonal block */
  259. /* Interchange rows K+1 and -IPIV(K). */
  260. kp = -ipiv[k];
  261. if (kp != k + 1) {
  262. dswap_(nrhs, &b[k + 1 + b_dim1], ldb, &b[kp + b_dim1], ldb);
  263. }
  264. /* Multiply by inv(L(K)), where L(K) is the transformation */
  265. /* stored in columns K and K+1 of A. */
  266. if (k < *n - 1) {
  267. i__1 = *n - k - 1;
  268. dger_(&i__1, nrhs, &c_b7, &a[k + 2 + k * a_dim1], &c__1, &b[k
  269. + b_dim1], ldb, &b[k + 2 + b_dim1], ldb);
  270. i__1 = *n - k - 1;
  271. dger_(&i__1, nrhs, &c_b7, &a[k + 2 + (k + 1) * a_dim1], &c__1,
  272. &b[k + 1 + b_dim1], ldb, &b[k + 2 + b_dim1], ldb);
  273. }
  274. /* Multiply by the inverse of the diagonal block. */
  275. akm1k = a[k + 1 + k * a_dim1];
  276. akm1 = a[k + k * a_dim1] / akm1k;
  277. ak = a[k + 1 + (k + 1) * a_dim1] / akm1k;
  278. denom = akm1 * ak - 1.;
  279. i__1 = *nrhs;
  280. for (j = 1; j <= i__1; ++j) {
  281. bkm1 = b[k + j * b_dim1] / akm1k;
  282. bk = b[k + 1 + j * b_dim1] / akm1k;
  283. b[k + j * b_dim1] = (ak * bkm1 - bk) / denom;
  284. b[k + 1 + j * b_dim1] = (akm1 * bk - bkm1) / denom;
  285. /* L70: */
  286. }
  287. k += 2;
  288. }
  289. goto L60;
  290. L80:
  291. /* Next solve L'*X = B, overwriting B with X. */
  292. /* K is the main loop index, decreasing from N to 1 in steps of */
  293. /* 1 or 2, depending on the size of the diagonal blocks. */
  294. k = *n;
  295. L90:
  296. /* If K < 1, exit from loop. */
  297. if (k < 1) {
  298. goto L100;
  299. }
  300. if (ipiv[k] > 0) {
  301. /* 1 x 1 diagonal block */
  302. /* Multiply by inv(L'(K)), where L(K) is the transformation */
  303. /* stored in column K of A. */
  304. if (k < *n) {
  305. i__1 = *n - k;
  306. dgemv_("Transpose", &i__1, nrhs, &c_b7, &b[k + 1 + b_dim1],
  307. ldb, &a[k + 1 + k * a_dim1], &c__1, &c_b19, &b[k +
  308. b_dim1], ldb);
  309. }
  310. /* Interchange rows K and IPIV(K). */
  311. kp = ipiv[k];
  312. if (kp != k) {
  313. dswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb);
  314. }
  315. --k;
  316. } else {
  317. /* 2 x 2 diagonal block */
  318. /* Multiply by inv(L'(K-1)), where L(K-1) is the transformation */
  319. /* stored in columns K-1 and K of A. */
  320. if (k < *n) {
  321. i__1 = *n - k;
  322. dgemv_("Transpose", &i__1, nrhs, &c_b7, &b[k + 1 + b_dim1],
  323. ldb, &a[k + 1 + k * a_dim1], &c__1, &c_b19, &b[k +
  324. b_dim1], ldb);
  325. i__1 = *n - k;
  326. dgemv_("Transpose", &i__1, nrhs, &c_b7, &b[k + 1 + b_dim1],
  327. ldb, &a[k + 1 + (k - 1) * a_dim1], &c__1, &c_b19, &b[
  328. k - 1 + b_dim1], ldb);
  329. }
  330. /* Interchange rows K and -IPIV(K). */
  331. kp = -ipiv[k];
  332. if (kp != k) {
  333. dswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb);
  334. }
  335. k += -2;
  336. }
  337. goto L90;
  338. L100:
  339. ;
  340. }
  341. return 0;
  342. /* End of DSYTRS */
  343. } /* dsytrs_ */