dgbtf2.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /* dgbtf2.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_b9 = -1.;
  16. /* Subroutine */ int dgbtf2_(integer *m, integer *n, integer *kl, integer *ku,
  17. doublereal *ab, integer *ldab, integer *ipiv, integer *info)
  18. {
  19. /* System generated locals */
  20. integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4;
  21. doublereal d__1;
  22. /* Local variables */
  23. integer i__, j, km, jp, ju, kv;
  24. extern /* Subroutine */ int dger_(integer *, integer *, doublereal *,
  25. doublereal *, integer *, doublereal *, integer *, doublereal *,
  26. integer *), dscal_(integer *, doublereal *, doublereal *, integer
  27. *), dswap_(integer *, doublereal *, integer *, doublereal *,
  28. integer *);
  29. extern integer idamax_(integer *, doublereal *, integer *);
  30. extern /* Subroutine */ int xerbla_(char *, integer *);
  31. /* -- LAPACK routine (version 3.2) -- */
  32. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  33. /* November 2006 */
  34. /* .. Scalar Arguments .. */
  35. /* .. */
  36. /* .. Array Arguments .. */
  37. /* .. */
  38. /* Purpose */
  39. /* ======= */
  40. /* DGBTF2 computes an LU factorization of a real m-by-n band matrix A */
  41. /* using partial pivoting with row interchanges. */
  42. /* This is the unblocked version of the algorithm, calling Level 2 BLAS. */
  43. /* Arguments */
  44. /* ========= */
  45. /* M (input) INTEGER */
  46. /* The number of rows of the matrix A. M >= 0. */
  47. /* N (input) INTEGER */
  48. /* The number of columns of the matrix A. N >= 0. */
  49. /* KL (input) INTEGER */
  50. /* The number of subdiagonals within the band of A. KL >= 0. */
  51. /* KU (input) INTEGER */
  52. /* The number of superdiagonals within the band of A. KU >= 0. */
  53. /* AB (input/output) DOUBLE PRECISION array, dimension (LDAB,N) */
  54. /* On entry, the matrix A in band storage, in rows KL+1 to */
  55. /* 2*KL+KU+1; rows 1 to KL of the array need not be set. */
  56. /* The j-th column of A is stored in the j-th column of the */
  57. /* array AB as follows: */
  58. /* AB(kl+ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(m,j+kl) */
  59. /* On exit, details of the factorization: U is stored as an */
  60. /* upper triangular band matrix with KL+KU superdiagonals in */
  61. /* rows 1 to KL+KU+1, and the multipliers used during the */
  62. /* factorization are stored in rows KL+KU+2 to 2*KL+KU+1. */
  63. /* See below for further details. */
  64. /* LDAB (input) INTEGER */
  65. /* The leading dimension of the array AB. LDAB >= 2*KL+KU+1. */
  66. /* IPIV (output) INTEGER array, dimension (min(M,N)) */
  67. /* The pivot indices; for 1 <= i <= min(M,N), row i of the */
  68. /* matrix was interchanged with row IPIV(i). */
  69. /* INFO (output) INTEGER */
  70. /* = 0: successful exit */
  71. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  72. /* > 0: if INFO = +i, U(i,i) is exactly zero. The factorization */
  73. /* has been completed, but the factor U is exactly */
  74. /* singular, and division by zero will occur if it is used */
  75. /* to solve a system of equations. */
  76. /* Further Details */
  77. /* =============== */
  78. /* The band storage scheme is illustrated by the following example, when */
  79. /* M = N = 6, KL = 2, KU = 1: */
  80. /* On entry: On exit: */
  81. /* * * * + + + * * * u14 u25 u36 */
  82. /* * * + + + + * * u13 u24 u35 u46 */
  83. /* * a12 a23 a34 a45 a56 * u12 u23 u34 u45 u56 */
  84. /* a11 a22 a33 a44 a55 a66 u11 u22 u33 u44 u55 u66 */
  85. /* a21 a32 a43 a54 a65 * m21 m32 m43 m54 m65 * */
  86. /* a31 a42 a53 a64 * * m31 m42 m53 m64 * * */
  87. /* Array elements marked * are not used by the routine; elements marked */
  88. /* + need not be set on entry, but are required by the routine to store */
  89. /* elements of U, because of fill-in resulting from the row */
  90. /* interchanges. */
  91. /* ===================================================================== */
  92. /* .. Parameters .. */
  93. /* .. */
  94. /* .. Local Scalars .. */
  95. /* .. */
  96. /* .. External Functions .. */
  97. /* .. */
  98. /* .. External Subroutines .. */
  99. /* .. */
  100. /* .. Intrinsic Functions .. */
  101. /* .. */
  102. /* .. Executable Statements .. */
  103. /* KV is the number of superdiagonals in the factor U, allowing for */
  104. /* fill-in. */
  105. /* Parameter adjustments */
  106. ab_dim1 = *ldab;
  107. ab_offset = 1 + ab_dim1;
  108. ab -= ab_offset;
  109. --ipiv;
  110. /* Function Body */
  111. kv = *ku + *kl;
  112. /* Test the input parameters. */
  113. *info = 0;
  114. if (*m < 0) {
  115. *info = -1;
  116. } else if (*n < 0) {
  117. *info = -2;
  118. } else if (*kl < 0) {
  119. *info = -3;
  120. } else if (*ku < 0) {
  121. *info = -4;
  122. } else if (*ldab < *kl + kv + 1) {
  123. *info = -6;
  124. }
  125. if (*info != 0) {
  126. i__1 = -(*info);
  127. xerbla_("DGBTF2", &i__1);
  128. return 0;
  129. }
  130. /* Quick return if possible */
  131. if (*m == 0 || *n == 0) {
  132. return 0;
  133. }
  134. /* Gaussian elimination with partial pivoting */
  135. /* Set fill-in elements in columns KU+2 to KV to zero. */
  136. i__1 = min(kv,*n);
  137. for (j = *ku + 2; j <= i__1; ++j) {
  138. i__2 = *kl;
  139. for (i__ = kv - j + 2; i__ <= i__2; ++i__) {
  140. ab[i__ + j * ab_dim1] = 0.;
  141. /* L10: */
  142. }
  143. /* L20: */
  144. }
  145. /* JU is the index of the last column affected by the current stage */
  146. /* of the factorization. */
  147. ju = 1;
  148. i__1 = min(*m,*n);
  149. for (j = 1; j <= i__1; ++j) {
  150. /* Set fill-in elements in column J+KV to zero. */
  151. if (j + kv <= *n) {
  152. i__2 = *kl;
  153. for (i__ = 1; i__ <= i__2; ++i__) {
  154. ab[i__ + (j + kv) * ab_dim1] = 0.;
  155. /* L30: */
  156. }
  157. }
  158. /* Find pivot and test for singularity. KM is the number of */
  159. /* subdiagonal elements in the current column. */
  160. /* Computing MIN */
  161. i__2 = *kl, i__3 = *m - j;
  162. km = min(i__2,i__3);
  163. i__2 = km + 1;
  164. jp = idamax_(&i__2, &ab[kv + 1 + j * ab_dim1], &c__1);
  165. ipiv[j] = jp + j - 1;
  166. if (ab[kv + jp + j * ab_dim1] != 0.) {
  167. /* Computing MAX */
  168. /* Computing MIN */
  169. i__4 = j + *ku + jp - 1;
  170. i__2 = ju, i__3 = min(i__4,*n);
  171. ju = max(i__2,i__3);
  172. /* Apply interchange to columns J to JU. */
  173. if (jp != 1) {
  174. i__2 = ju - j + 1;
  175. i__3 = *ldab - 1;
  176. i__4 = *ldab - 1;
  177. dswap_(&i__2, &ab[kv + jp + j * ab_dim1], &i__3, &ab[kv + 1 +
  178. j * ab_dim1], &i__4);
  179. }
  180. if (km > 0) {
  181. /* Compute multipliers. */
  182. d__1 = 1. / ab[kv + 1 + j * ab_dim1];
  183. dscal_(&km, &d__1, &ab[kv + 2 + j * ab_dim1], &c__1);
  184. /* Update trailing submatrix within the band. */
  185. if (ju > j) {
  186. i__2 = ju - j;
  187. i__3 = *ldab - 1;
  188. i__4 = *ldab - 1;
  189. dger_(&km, &i__2, &c_b9, &ab[kv + 2 + j * ab_dim1], &c__1,
  190. &ab[kv + (j + 1) * ab_dim1], &i__3, &ab[kv + 1 +
  191. (j + 1) * ab_dim1], &i__4);
  192. }
  193. }
  194. } else {
  195. /* If pivot is zero, set INFO to the index of the pivot */
  196. /* unless a zero pivot has already been found. */
  197. if (*info == 0) {
  198. *info = j;
  199. }
  200. }
  201. /* L40: */
  202. }
  203. return 0;
  204. /* End of DGBTF2 */
  205. } /* dgbtf2_ */