dpotf2.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /* dpotf2.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_b10 = -1.;
  16. static doublereal c_b12 = 1.;
  17. /* Subroutine */ int _starpu_dpotf2_(char *uplo, integer *n, doublereal *a, integer *
  18. lda, integer *info)
  19. {
  20. /* System generated locals */
  21. integer a_dim1, a_offset, i__1, i__2, i__3;
  22. doublereal d__1;
  23. /* Builtin functions */
  24. double sqrt(doublereal);
  25. /* Local variables */
  26. integer j;
  27. doublereal ajj;
  28. extern doublereal _starpu_ddot_(integer *, doublereal *, integer *, doublereal *,
  29. integer *);
  30. extern /* Subroutine */ int _starpu_dscal_(integer *, doublereal *, doublereal *,
  31. integer *);
  32. extern logical _starpu_lsame_(char *, char *);
  33. extern /* Subroutine */ int _starpu_dgemv_(char *, integer *, integer *,
  34. doublereal *, doublereal *, integer *, doublereal *, integer *,
  35. doublereal *, doublereal *, integer *);
  36. logical upper;
  37. extern logical _starpu_disnan_(doublereal *);
  38. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  39. /* -- LAPACK routine (version 3.2) -- */
  40. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  41. /* November 2006 */
  42. /* .. Scalar Arguments .. */
  43. /* .. */
  44. /* .. Array Arguments .. */
  45. /* .. */
  46. /* Purpose */
  47. /* ======= */
  48. /* DPOTF2 computes the Cholesky factorization of a real symmetric */
  49. /* positive definite matrix A. */
  50. /* The factorization has the form */
  51. /* A = U' * U , if UPLO = 'U', or */
  52. /* A = L * L', if UPLO = 'L', */
  53. /* where U is an upper triangular matrix and L is lower triangular. */
  54. /* This is the unblocked version of the algorithm, calling Level 2 BLAS. */
  55. /* Arguments */
  56. /* ========= */
  57. /* UPLO (input) CHARACTER*1 */
  58. /* Specifies whether the upper or lower triangular part of the */
  59. /* symmetric matrix A is stored. */
  60. /* = 'U': Upper triangular */
  61. /* = 'L': Lower triangular */
  62. /* N (input) INTEGER */
  63. /* The order of the matrix A. N >= 0. */
  64. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  65. /* On entry, the symmetric matrix A. If UPLO = 'U', the leading */
  66. /* n by n upper triangular part of A contains the upper */
  67. /* triangular part of the matrix A, and the strictly lower */
  68. /* triangular part of A is not referenced. If UPLO = 'L', the */
  69. /* leading n by n lower triangular part of A contains the lower */
  70. /* triangular part of the matrix A, and the strictly upper */
  71. /* triangular part of A is not referenced. */
  72. /* On exit, if INFO = 0, the factor U or L from the Cholesky */
  73. /* factorization A = U'*U or A = L*L'. */
  74. /* LDA (input) INTEGER */
  75. /* The leading dimension of the array A. LDA >= max(1,N). */
  76. /* INFO (output) INTEGER */
  77. /* = 0: successful exit */
  78. /* < 0: if INFO = -k, the k-th argument had an illegal value */
  79. /* > 0: if INFO = k, the leading minor of order k is not */
  80. /* positive definite, and the factorization could not be */
  81. /* completed. */
  82. /* ===================================================================== */
  83. /* .. Parameters .. */
  84. /* .. */
  85. /* .. Local Scalars .. */
  86. /* .. */
  87. /* .. External Functions .. */
  88. /* .. */
  89. /* .. External Subroutines .. */
  90. /* .. */
  91. /* .. Intrinsic Functions .. */
  92. /* .. */
  93. /* .. Executable Statements .. */
  94. /* Test the input parameters. */
  95. /* Parameter adjustments */
  96. a_dim1 = *lda;
  97. a_offset = 1 + a_dim1;
  98. a -= a_offset;
  99. /* Function Body */
  100. *info = 0;
  101. upper = _starpu_lsame_(uplo, "U");
  102. if (! upper && ! _starpu_lsame_(uplo, "L")) {
  103. *info = -1;
  104. } else if (*n < 0) {
  105. *info = -2;
  106. } else if (*lda < max(1,*n)) {
  107. *info = -4;
  108. }
  109. if (*info != 0) {
  110. i__1 = -(*info);
  111. _starpu_xerbla_("DPOTF2", &i__1);
  112. return 0;
  113. }
  114. /* Quick return if possible */
  115. if (*n == 0) {
  116. return 0;
  117. }
  118. if (upper) {
  119. /* Compute the Cholesky factorization A = U'*U. */
  120. i__1 = *n;
  121. for (j = 1; j <= i__1; ++j) {
  122. /* Compute U(J,J) and test for non-positive-definiteness. */
  123. i__2 = j - 1;
  124. ajj = a[j + j * a_dim1] - _starpu_ddot_(&i__2, &a[j * a_dim1 + 1], &c__1,
  125. &a[j * a_dim1 + 1], &c__1);
  126. if (ajj <= 0. || _starpu_disnan_(&ajj)) {
  127. a[j + j * a_dim1] = ajj;
  128. goto L30;
  129. }
  130. ajj = sqrt(ajj);
  131. a[j + j * a_dim1] = ajj;
  132. /* Compute elements J+1:N of row J. */
  133. if (j < *n) {
  134. i__2 = j - 1;
  135. i__3 = *n - j;
  136. _starpu_dgemv_("Transpose", &i__2, &i__3, &c_b10, &a[(j + 1) * a_dim1
  137. + 1], lda, &a[j * a_dim1 + 1], &c__1, &c_b12, &a[j + (
  138. j + 1) * a_dim1], lda);
  139. i__2 = *n - j;
  140. d__1 = 1. / ajj;
  141. _starpu_dscal_(&i__2, &d__1, &a[j + (j + 1) * a_dim1], lda);
  142. }
  143. /* L10: */
  144. }
  145. } else {
  146. /* Compute the Cholesky factorization A = L*L'. */
  147. i__1 = *n;
  148. for (j = 1; j <= i__1; ++j) {
  149. /* Compute L(J,J) and test for non-positive-definiteness. */
  150. i__2 = j - 1;
  151. ajj = a[j + j * a_dim1] - _starpu_ddot_(&i__2, &a[j + a_dim1], lda, &a[j
  152. + a_dim1], lda);
  153. if (ajj <= 0. || _starpu_disnan_(&ajj)) {
  154. a[j + j * a_dim1] = ajj;
  155. goto L30;
  156. }
  157. ajj = sqrt(ajj);
  158. a[j + j * a_dim1] = ajj;
  159. /* Compute elements J+1:N of column J. */
  160. if (j < *n) {
  161. i__2 = *n - j;
  162. i__3 = j - 1;
  163. _starpu_dgemv_("No transpose", &i__2, &i__3, &c_b10, &a[j + 1 +
  164. a_dim1], lda, &a[j + a_dim1], lda, &c_b12, &a[j + 1 +
  165. j * a_dim1], &c__1);
  166. i__2 = *n - j;
  167. d__1 = 1. / ajj;
  168. _starpu_dscal_(&i__2, &d__1, &a[j + 1 + j * a_dim1], &c__1);
  169. }
  170. /* L20: */
  171. }
  172. }
  173. goto L40;
  174. L30:
  175. *info = j;
  176. L40:
  177. return 0;
  178. /* End of DPOTF2 */
  179. } /* _starpu_dpotf2_ */