dpbstf.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /* dpbstf.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 _starpu_dpbstf_(char *uplo, integer *n, integer *kd, doublereal *
  17. ab, integer *ldab, integer *info)
  18. {
  19. /* System generated locals */
  20. integer ab_dim1, ab_offset, i__1, i__2, i__3;
  21. doublereal d__1;
  22. /* Builtin functions */
  23. double sqrt(doublereal);
  24. /* Local variables */
  25. integer j, m, km;
  26. doublereal ajj;
  27. integer kld;
  28. extern /* Subroutine */ int _starpu_dsyr_(char *, integer *, doublereal *,
  29. doublereal *, integer *, doublereal *, integer *), _starpu_dscal_(
  30. integer *, doublereal *, doublereal *, integer *);
  31. extern logical _starpu_lsame_(char *, char *);
  32. logical upper;
  33. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  34. /* -- LAPACK routine (version 3.2) -- */
  35. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  36. /* November 2006 */
  37. /* .. Scalar Arguments .. */
  38. /* .. */
  39. /* .. Array Arguments .. */
  40. /* .. */
  41. /* Purpose */
  42. /* ======= */
  43. /* DPBSTF computes a split Cholesky factorization of a real */
  44. /* symmetric positive definite band matrix A. */
  45. /* This routine is designed to be used in conjunction with DSBGST. */
  46. /* The factorization has the form A = S**T*S where S is a band matrix */
  47. /* of the same bandwidth as A and the following structure: */
  48. /* S = ( U ) */
  49. /* ( M L ) */
  50. /* where U is upper triangular of order m = (n+kd)/2, and L is lower */
  51. /* triangular of order n-m. */
  52. /* Arguments */
  53. /* ========= */
  54. /* UPLO (input) CHARACTER*1 */
  55. /* = 'U': Upper triangle of A is stored; */
  56. /* = 'L': Lower triangle of A is stored. */
  57. /* N (input) INTEGER */
  58. /* The order of the matrix A. N >= 0. */
  59. /* KD (input) INTEGER */
  60. /* The number of superdiagonals of the matrix A if UPLO = 'U', */
  61. /* or the number of subdiagonals if UPLO = 'L'. KD >= 0. */
  62. /* AB (input/output) DOUBLE PRECISION array, dimension (LDAB,N) */
  63. /* On entry, the upper or lower triangle of the symmetric band */
  64. /* matrix A, stored in the first kd+1 rows of the array. The */
  65. /* j-th column of A is stored in the j-th column of the array AB */
  66. /* as follows: */
  67. /* if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */
  68. /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). */
  69. /* On exit, if INFO = 0, the factor S from the split Cholesky */
  70. /* factorization A = S**T*S. See Further Details. */
  71. /* LDAB (input) INTEGER */
  72. /* The leading dimension of the array AB. LDAB >= KD+1. */
  73. /* INFO (output) INTEGER */
  74. /* = 0: successful exit */
  75. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  76. /* > 0: if INFO = i, the factorization could not be completed, */
  77. /* because the updated element a(i,i) was negative; the */
  78. /* matrix A is not positive definite. */
  79. /* Further Details */
  80. /* =============== */
  81. /* The band storage scheme is illustrated by the following example, when */
  82. /* N = 7, KD = 2: */
  83. /* S = ( s11 s12 s13 ) */
  84. /* ( s22 s23 s24 ) */
  85. /* ( s33 s34 ) */
  86. /* ( s44 ) */
  87. /* ( s53 s54 s55 ) */
  88. /* ( s64 s65 s66 ) */
  89. /* ( s75 s76 s77 ) */
  90. /* If UPLO = 'U', the array AB holds: */
  91. /* on entry: on exit: */
  92. /* * * a13 a24 a35 a46 a57 * * s13 s24 s53 s64 s75 */
  93. /* * a12 a23 a34 a45 a56 a67 * s12 s23 s34 s54 s65 s76 */
  94. /* a11 a22 a33 a44 a55 a66 a77 s11 s22 s33 s44 s55 s66 s77 */
  95. /* If UPLO = 'L', the array AB holds: */
  96. /* on entry: on exit: */
  97. /* a11 a22 a33 a44 a55 a66 a77 s11 s22 s33 s44 s55 s66 s77 */
  98. /* a21 a32 a43 a54 a65 a76 * s12 s23 s34 s54 s65 s76 * */
  99. /* a31 a42 a53 a64 a64 * * s13 s24 s53 s64 s75 * * */
  100. /* Array elements marked * are not used by the routine. */
  101. /* ===================================================================== */
  102. /* .. Parameters .. */
  103. /* .. */
  104. /* .. Local Scalars .. */
  105. /* .. */
  106. /* .. External Functions .. */
  107. /* .. */
  108. /* .. External Subroutines .. */
  109. /* .. */
  110. /* .. Intrinsic Functions .. */
  111. /* .. */
  112. /* .. Executable Statements .. */
  113. /* Test the input parameters. */
  114. /* Parameter adjustments */
  115. ab_dim1 = *ldab;
  116. ab_offset = 1 + ab_dim1;
  117. ab -= ab_offset;
  118. /* Function Body */
  119. *info = 0;
  120. upper = _starpu_lsame_(uplo, "U");
  121. if (! upper && ! _starpu_lsame_(uplo, "L")) {
  122. *info = -1;
  123. } else if (*n < 0) {
  124. *info = -2;
  125. } else if (*kd < 0) {
  126. *info = -3;
  127. } else if (*ldab < *kd + 1) {
  128. *info = -5;
  129. }
  130. if (*info != 0) {
  131. i__1 = -(*info);
  132. _starpu_xerbla_("DPBSTF", &i__1);
  133. return 0;
  134. }
  135. /* Quick return if possible */
  136. if (*n == 0) {
  137. return 0;
  138. }
  139. /* Computing MAX */
  140. i__1 = 1, i__2 = *ldab - 1;
  141. kld = max(i__1,i__2);
  142. /* Set the splitting point m. */
  143. m = (*n + *kd) / 2;
  144. if (upper) {
  145. /* Factorize A(m+1:n,m+1:n) as L**T*L, and update A(1:m,1:m). */
  146. i__1 = m + 1;
  147. for (j = *n; j >= i__1; --j) {
  148. /* Compute s(j,j) and test for non-positive-definiteness. */
  149. ajj = ab[*kd + 1 + j * ab_dim1];
  150. if (ajj <= 0.) {
  151. goto L50;
  152. }
  153. ajj = sqrt(ajj);
  154. ab[*kd + 1 + j * ab_dim1] = ajj;
  155. /* Computing MIN */
  156. i__2 = j - 1;
  157. km = min(i__2,*kd);
  158. /* Compute elements j-km:j-1 of the j-th column and update the */
  159. /* the leading submatrix within the band. */
  160. d__1 = 1. / ajj;
  161. _starpu_dscal_(&km, &d__1, &ab[*kd + 1 - km + j * ab_dim1], &c__1);
  162. _starpu_dsyr_("Upper", &km, &c_b9, &ab[*kd + 1 - km + j * ab_dim1], &c__1,
  163. &ab[*kd + 1 + (j - km) * ab_dim1], &kld);
  164. /* L10: */
  165. }
  166. /* Factorize the updated submatrix A(1:m,1:m) as U**T*U. */
  167. i__1 = m;
  168. for (j = 1; j <= i__1; ++j) {
  169. /* Compute s(j,j) and test for non-positive-definiteness. */
  170. ajj = ab[*kd + 1 + j * ab_dim1];
  171. if (ajj <= 0.) {
  172. goto L50;
  173. }
  174. ajj = sqrt(ajj);
  175. ab[*kd + 1 + j * ab_dim1] = ajj;
  176. /* Computing MIN */
  177. i__2 = *kd, i__3 = m - j;
  178. km = min(i__2,i__3);
  179. /* Compute elements j+1:j+km of the j-th row and update the */
  180. /* trailing submatrix within the band. */
  181. if (km > 0) {
  182. d__1 = 1. / ajj;
  183. _starpu_dscal_(&km, &d__1, &ab[*kd + (j + 1) * ab_dim1], &kld);
  184. _starpu_dsyr_("Upper", &km, &c_b9, &ab[*kd + (j + 1) * ab_dim1], &kld,
  185. &ab[*kd + 1 + (j + 1) * ab_dim1], &kld);
  186. }
  187. /* L20: */
  188. }
  189. } else {
  190. /* Factorize A(m+1:n,m+1:n) as L**T*L, and update A(1:m,1:m). */
  191. i__1 = m + 1;
  192. for (j = *n; j >= i__1; --j) {
  193. /* Compute s(j,j) and test for non-positive-definiteness. */
  194. ajj = ab[j * ab_dim1 + 1];
  195. if (ajj <= 0.) {
  196. goto L50;
  197. }
  198. ajj = sqrt(ajj);
  199. ab[j * ab_dim1 + 1] = ajj;
  200. /* Computing MIN */
  201. i__2 = j - 1;
  202. km = min(i__2,*kd);
  203. /* Compute elements j-km:j-1 of the j-th row and update the */
  204. /* trailing submatrix within the band. */
  205. d__1 = 1. / ajj;
  206. _starpu_dscal_(&km, &d__1, &ab[km + 1 + (j - km) * ab_dim1], &kld);
  207. _starpu_dsyr_("Lower", &km, &c_b9, &ab[km + 1 + (j - km) * ab_dim1], &kld,
  208. &ab[(j - km) * ab_dim1 + 1], &kld);
  209. /* L30: */
  210. }
  211. /* Factorize the updated submatrix A(1:m,1:m) as U**T*U. */
  212. i__1 = m;
  213. for (j = 1; j <= i__1; ++j) {
  214. /* Compute s(j,j) and test for non-positive-definiteness. */
  215. ajj = ab[j * ab_dim1 + 1];
  216. if (ajj <= 0.) {
  217. goto L50;
  218. }
  219. ajj = sqrt(ajj);
  220. ab[j * ab_dim1 + 1] = ajj;
  221. /* Computing MIN */
  222. i__2 = *kd, i__3 = m - j;
  223. km = min(i__2,i__3);
  224. /* Compute elements j+1:j+km of the j-th column and update the */
  225. /* trailing submatrix within the band. */
  226. if (km > 0) {
  227. d__1 = 1. / ajj;
  228. _starpu_dscal_(&km, &d__1, &ab[j * ab_dim1 + 2], &c__1);
  229. _starpu_dsyr_("Lower", &km, &c_b9, &ab[j * ab_dim1 + 2], &c__1, &ab[(
  230. j + 1) * ab_dim1 + 1], &kld);
  231. }
  232. /* L40: */
  233. }
  234. }
  235. return 0;
  236. L50:
  237. *info = j;
  238. return 0;
  239. /* End of DPBSTF */
  240. } /* _starpu_dpbstf_ */