dpbtf2.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* dpbtf2.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_b8 = -1.;
  15. static integer c__1 = 1;
  16. /* Subroutine */ int _starpu_dpbtf2_(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, kn;
  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. /* DPBTF2 computes the Cholesky factorization of a real symmetric */
  44. /* positive definite band matrix A. */
  45. /* The factorization has the form */
  46. /* A = U' * U , if UPLO = 'U', or */
  47. /* A = L * L', if UPLO = 'L', */
  48. /* where U is an upper triangular matrix, U' is the transpose of U, and */
  49. /* L is lower triangular. */
  50. /* This is the unblocked version of the algorithm, calling Level 2 BLAS. */
  51. /* Arguments */
  52. /* ========= */
  53. /* UPLO (input) CHARACTER*1 */
  54. /* Specifies whether the upper or lower triangular part of the */
  55. /* symmetric matrix A is stored: */
  56. /* = 'U': Upper triangular */
  57. /* = 'L': Lower triangular */
  58. /* N (input) INTEGER */
  59. /* The order of the matrix A. N >= 0. */
  60. /* KD (input) INTEGER */
  61. /* The number of super-diagonals of the matrix A if UPLO = 'U', */
  62. /* or the number of sub-diagonals if UPLO = 'L'. KD >= 0. */
  63. /* AB (input/output) DOUBLE PRECISION array, dimension (LDAB,N) */
  64. /* On entry, the upper or lower triangle of the symmetric band */
  65. /* matrix A, stored in the first KD+1 rows of the array. The */
  66. /* j-th column of A is stored in the j-th column of the array AB */
  67. /* as follows: */
  68. /* if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */
  69. /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). */
  70. /* On exit, if INFO = 0, the triangular factor U or L from the */
  71. /* Cholesky factorization A = U'*U or A = L*L' of the band */
  72. /* matrix A, in the same storage format as A. */
  73. /* LDAB (input) INTEGER */
  74. /* The leading dimension of the array AB. LDAB >= KD+1. */
  75. /* INFO (output) INTEGER */
  76. /* = 0: successful exit */
  77. /* < 0: if INFO = -k, the k-th argument had an illegal value */
  78. /* > 0: if INFO = k, the leading minor of order k is not */
  79. /* positive definite, and the factorization could not be */
  80. /* completed. */
  81. /* Further Details */
  82. /* =============== */
  83. /* The band storage scheme is illustrated by the following example, when */
  84. /* N = 6, KD = 2, and UPLO = 'U': */
  85. /* On entry: On exit: */
  86. /* * * a13 a24 a35 a46 * * u13 u24 u35 u46 */
  87. /* * a12 a23 a34 a45 a56 * u12 u23 u34 u45 u56 */
  88. /* a11 a22 a33 a44 a55 a66 u11 u22 u33 u44 u55 u66 */
  89. /* Similarly, if UPLO = 'L' the format of A is as follows: */
  90. /* On entry: On exit: */
  91. /* a11 a22 a33 a44 a55 a66 l11 l22 l33 l44 l55 l66 */
  92. /* a21 a32 a43 a54 a65 * l21 l32 l43 l54 l65 * */
  93. /* a31 a42 a53 a64 * * l31 l42 l53 l64 * * */
  94. /* Array elements marked * are not used by the routine. */
  95. /* ===================================================================== */
  96. /* .. Parameters .. */
  97. /* .. */
  98. /* .. Local Scalars .. */
  99. /* .. */
  100. /* .. External Functions .. */
  101. /* .. */
  102. /* .. External Subroutines .. */
  103. /* .. */
  104. /* .. Intrinsic Functions .. */
  105. /* .. */
  106. /* .. Executable Statements .. */
  107. /* Test the input parameters. */
  108. /* Parameter adjustments */
  109. ab_dim1 = *ldab;
  110. ab_offset = 1 + ab_dim1;
  111. ab -= ab_offset;
  112. /* Function Body */
  113. *info = 0;
  114. upper = _starpu_lsame_(uplo, "U");
  115. if (! upper && ! _starpu_lsame_(uplo, "L")) {
  116. *info = -1;
  117. } else if (*n < 0) {
  118. *info = -2;
  119. } else if (*kd < 0) {
  120. *info = -3;
  121. } else if (*ldab < *kd + 1) {
  122. *info = -5;
  123. }
  124. if (*info != 0) {
  125. i__1 = -(*info);
  126. _starpu_xerbla_("DPBTF2", &i__1);
  127. return 0;
  128. }
  129. /* Quick return if possible */
  130. if (*n == 0) {
  131. return 0;
  132. }
  133. /* Computing MAX */
  134. i__1 = 1, i__2 = *ldab - 1;
  135. kld = max(i__1,i__2);
  136. if (upper) {
  137. /* Compute the Cholesky factorization A = U'*U. */
  138. i__1 = *n;
  139. for (j = 1; j <= i__1; ++j) {
  140. /* Compute U(J,J) and test for non-positive-definiteness. */
  141. ajj = ab[*kd + 1 + j * ab_dim1];
  142. if (ajj <= 0.) {
  143. goto L30;
  144. }
  145. ajj = sqrt(ajj);
  146. ab[*kd + 1 + j * ab_dim1] = ajj;
  147. /* Compute elements J+1:J+KN of row J and update the */
  148. /* trailing submatrix within the band. */
  149. /* Computing MIN */
  150. i__2 = *kd, i__3 = *n - j;
  151. kn = min(i__2,i__3);
  152. if (kn > 0) {
  153. d__1 = 1. / ajj;
  154. _starpu_dscal_(&kn, &d__1, &ab[*kd + (j + 1) * ab_dim1], &kld);
  155. _starpu_dsyr_("Upper", &kn, &c_b8, &ab[*kd + (j + 1) * ab_dim1], &kld,
  156. &ab[*kd + 1 + (j + 1) * ab_dim1], &kld);
  157. }
  158. /* L10: */
  159. }
  160. } else {
  161. /* Compute the Cholesky factorization A = L*L'. */
  162. i__1 = *n;
  163. for (j = 1; j <= i__1; ++j) {
  164. /* Compute L(J,J) and test for non-positive-definiteness. */
  165. ajj = ab[j * ab_dim1 + 1];
  166. if (ajj <= 0.) {
  167. goto L30;
  168. }
  169. ajj = sqrt(ajj);
  170. ab[j * ab_dim1 + 1] = ajj;
  171. /* Compute elements J+1:J+KN of column J and update the */
  172. /* trailing submatrix within the band. */
  173. /* Computing MIN */
  174. i__2 = *kd, i__3 = *n - j;
  175. kn = min(i__2,i__3);
  176. if (kn > 0) {
  177. d__1 = 1. / ajj;
  178. _starpu_dscal_(&kn, &d__1, &ab[j * ab_dim1 + 2], &c__1);
  179. _starpu_dsyr_("Lower", &kn, &c_b8, &ab[j * ab_dim1 + 2], &c__1, &ab[(
  180. j + 1) * ab_dim1 + 1], &kld);
  181. }
  182. /* L20: */
  183. }
  184. }
  185. return 0;
  186. L30:
  187. *info = j;
  188. return 0;
  189. /* End of DPBTF2 */
  190. } /* _starpu_dpbtf2_ */