dgbtrs.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* dgbtrs.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_b23 = 1.;
  17. /* Subroutine */ int dgbtrs_(char *trans, integer *n, integer *kl, integer *
  18. ku, integer *nrhs, doublereal *ab, integer *ldab, integer *ipiv,
  19. doublereal *b, integer *ldb, integer *info)
  20. {
  21. /* System generated locals */
  22. integer ab_dim1, ab_offset, b_dim1, b_offset, i__1, i__2, i__3;
  23. /* Local variables */
  24. integer i__, j, l, kd, lm;
  25. extern /* Subroutine */ int dger_(integer *, integer *, doublereal *,
  26. doublereal *, integer *, doublereal *, integer *, doublereal *,
  27. integer *);
  28. extern logical lsame_(char *, char *);
  29. extern /* Subroutine */ int dgemv_(char *, integer *, integer *,
  30. doublereal *, doublereal *, integer *, doublereal *, integer *,
  31. doublereal *, doublereal *, integer *), dswap_(integer *,
  32. doublereal *, integer *, doublereal *, integer *), dtbsv_(char *,
  33. char *, char *, integer *, integer *, doublereal *, integer *,
  34. doublereal *, integer *);
  35. logical lnoti;
  36. extern /* Subroutine */ int xerbla_(char *, integer *);
  37. logical notran;
  38. /* -- LAPACK routine (version 3.2) -- */
  39. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  40. /* November 2006 */
  41. /* .. Scalar Arguments .. */
  42. /* .. */
  43. /* .. Array Arguments .. */
  44. /* .. */
  45. /* Purpose */
  46. /* ======= */
  47. /* DGBTRS solves a system of linear equations */
  48. /* A * X = B or A' * X = B */
  49. /* with a general band matrix A using the LU factorization computed */
  50. /* by DGBTRF. */
  51. /* Arguments */
  52. /* ========= */
  53. /* TRANS (input) CHARACTER*1 */
  54. /* Specifies the form of the system of equations. */
  55. /* = 'N': A * X = B (No transpose) */
  56. /* = 'T': A'* X = B (Transpose) */
  57. /* = 'C': A'* X = B (Conjugate transpose = Transpose) */
  58. /* N (input) INTEGER */
  59. /* The order of the matrix A. N >= 0. */
  60. /* KL (input) INTEGER */
  61. /* The number of subdiagonals within the band of A. KL >= 0. */
  62. /* KU (input) INTEGER */
  63. /* The number of superdiagonals within the band of A. KU >= 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. /* AB (input) DOUBLE PRECISION array, dimension (LDAB,N) */
  68. /* Details of the LU factorization of the band matrix A, as */
  69. /* computed by DGBTRF. U is stored as an upper triangular band */
  70. /* matrix with KL+KU superdiagonals in rows 1 to KL+KU+1, and */
  71. /* the multipliers used during the factorization are stored in */
  72. /* rows KL+KU+2 to 2*KL+KU+1. */
  73. /* LDAB (input) INTEGER */
  74. /* The leading dimension of the array AB. LDAB >= 2*KL+KU+1. */
  75. /* IPIV (input) INTEGER array, dimension (N) */
  76. /* The pivot indices; for 1 <= i <= N, row i of the matrix was */
  77. /* interchanged with row IPIV(i). */
  78. /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */
  79. /* On entry, the right hand side matrix B. */
  80. /* On exit, the solution matrix X. */
  81. /* LDB (input) INTEGER */
  82. /* The leading dimension of the array B. LDB >= max(1,N). */
  83. /* INFO (output) INTEGER */
  84. /* = 0: successful exit */
  85. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  86. /* ===================================================================== */
  87. /* .. Parameters .. */
  88. /* .. */
  89. /* .. Local Scalars .. */
  90. /* .. */
  91. /* .. External Functions .. */
  92. /* .. */
  93. /* .. External Subroutines .. */
  94. /* .. */
  95. /* .. Intrinsic Functions .. */
  96. /* .. */
  97. /* .. Executable Statements .. */
  98. /* Test the input parameters. */
  99. /* Parameter adjustments */
  100. ab_dim1 = *ldab;
  101. ab_offset = 1 + ab_dim1;
  102. ab -= ab_offset;
  103. --ipiv;
  104. b_dim1 = *ldb;
  105. b_offset = 1 + b_dim1;
  106. b -= b_offset;
  107. /* Function Body */
  108. *info = 0;
  109. notran = lsame_(trans, "N");
  110. if (! notran && ! lsame_(trans, "T") && ! lsame_(
  111. trans, "C")) {
  112. *info = -1;
  113. } else if (*n < 0) {
  114. *info = -2;
  115. } else if (*kl < 0) {
  116. *info = -3;
  117. } else if (*ku < 0) {
  118. *info = -4;
  119. } else if (*nrhs < 0) {
  120. *info = -5;
  121. } else if (*ldab < (*kl << 1) + *ku + 1) {
  122. *info = -7;
  123. } else if (*ldb < max(1,*n)) {
  124. *info = -10;
  125. }
  126. if (*info != 0) {
  127. i__1 = -(*info);
  128. xerbla_("DGBTRS", &i__1);
  129. return 0;
  130. }
  131. /* Quick return if possible */
  132. if (*n == 0 || *nrhs == 0) {
  133. return 0;
  134. }
  135. kd = *ku + *kl + 1;
  136. lnoti = *kl > 0;
  137. if (notran) {
  138. /* Solve A*X = B. */
  139. /* Solve L*X = B, overwriting B with X. */
  140. /* L is represented as a product of permutations and unit lower */
  141. /* triangular matrices L = P(1) * L(1) * ... * P(n-1) * L(n-1), */
  142. /* where each transformation L(i) is a rank-one modification of */
  143. /* the identity matrix. */
  144. if (lnoti) {
  145. i__1 = *n - 1;
  146. for (j = 1; j <= i__1; ++j) {
  147. /* Computing MIN */
  148. i__2 = *kl, i__3 = *n - j;
  149. lm = min(i__2,i__3);
  150. l = ipiv[j];
  151. if (l != j) {
  152. dswap_(nrhs, &b[l + b_dim1], ldb, &b[j + b_dim1], ldb);
  153. }
  154. dger_(&lm, nrhs, &c_b7, &ab[kd + 1 + j * ab_dim1], &c__1, &b[
  155. j + b_dim1], ldb, &b[j + 1 + b_dim1], ldb);
  156. /* L10: */
  157. }
  158. }
  159. i__1 = *nrhs;
  160. for (i__ = 1; i__ <= i__1; ++i__) {
  161. /* Solve U*X = B, overwriting B with X. */
  162. i__2 = *kl + *ku;
  163. dtbsv_("Upper", "No transpose", "Non-unit", n, &i__2, &ab[
  164. ab_offset], ldab, &b[i__ * b_dim1 + 1], &c__1);
  165. /* L20: */
  166. }
  167. } else {
  168. /* Solve A'*X = B. */
  169. i__1 = *nrhs;
  170. for (i__ = 1; i__ <= i__1; ++i__) {
  171. /* Solve U'*X = B, overwriting B with X. */
  172. i__2 = *kl + *ku;
  173. dtbsv_("Upper", "Transpose", "Non-unit", n, &i__2, &ab[ab_offset],
  174. ldab, &b[i__ * b_dim1 + 1], &c__1);
  175. /* L30: */
  176. }
  177. /* Solve L'*X = B, overwriting B with X. */
  178. if (lnoti) {
  179. for (j = *n - 1; j >= 1; --j) {
  180. /* Computing MIN */
  181. i__1 = *kl, i__2 = *n - j;
  182. lm = min(i__1,i__2);
  183. dgemv_("Transpose", &lm, nrhs, &c_b7, &b[j + 1 + b_dim1], ldb,
  184. &ab[kd + 1 + j * ab_dim1], &c__1, &c_b23, &b[j +
  185. b_dim1], ldb);
  186. l = ipiv[j];
  187. if (l != j) {
  188. dswap_(nrhs, &b[l + b_dim1], ldb, &b[j + b_dim1], ldb);
  189. }
  190. /* L40: */
  191. }
  192. }
  193. }
  194. return 0;
  195. /* End of DGBTRS */
  196. } /* dgbtrs_ */