dpptrf.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* dpptrf.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_b16 = -1.;
  16. /* Subroutine */ int _starpu_dpptrf_(char *uplo, integer *n, doublereal *ap, integer *
  17. info)
  18. {
  19. /* System generated locals */
  20. integer i__1, i__2;
  21. doublereal d__1;
  22. /* Builtin functions */
  23. double sqrt(doublereal);
  24. /* Local variables */
  25. integer j, jc, jj;
  26. doublereal ajj;
  27. extern doublereal _starpu_ddot_(integer *, doublereal *, integer *, doublereal *,
  28. integer *);
  29. extern /* Subroutine */ int _starpu_dspr_(char *, integer *, doublereal *,
  30. doublereal *, integer *, doublereal *), _starpu_dscal_(integer *,
  31. doublereal *, doublereal *, integer *);
  32. extern logical _starpu_lsame_(char *, char *);
  33. logical upper;
  34. extern /* Subroutine */ int _starpu_dtpsv_(char *, char *, char *, integer *,
  35. doublereal *, doublereal *, integer *),
  36. _starpu_xerbla_(char *, integer *);
  37. /* -- LAPACK routine (version 3.2) -- */
  38. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  39. /* November 2006 */
  40. /* .. Scalar Arguments .. */
  41. /* .. */
  42. /* .. Array Arguments .. */
  43. /* .. */
  44. /* Purpose */
  45. /* ======= */
  46. /* DPPTRF computes the Cholesky factorization of a real symmetric */
  47. /* positive definite matrix A stored in packed format. */
  48. /* The factorization has the form */
  49. /* A = U**T * U, if UPLO = 'U', or */
  50. /* A = L * L**T, if UPLO = 'L', */
  51. /* where U is an upper triangular matrix and L is lower triangular. */
  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. /* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
  60. /* On entry, the upper or lower triangle of the symmetric matrix */
  61. /* A, packed columnwise in a linear array. The j-th column of A */
  62. /* is stored in the array AP as follows: */
  63. /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
  64. /* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
  65. /* See below for further details. */
  66. /* On exit, if INFO = 0, the triangular factor U or L from the */
  67. /* Cholesky factorization A = U**T*U or A = L*L**T, in the same */
  68. /* storage format as A. */
  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, the leading minor of order i is not */
  73. /* positive definite, and the factorization could not be */
  74. /* completed. */
  75. /* Further Details */
  76. /* ======= ======= */
  77. /* The packed storage scheme is illustrated by the following example */
  78. /* when N = 4, UPLO = 'U': */
  79. /* Two-dimensional storage of the symmetric matrix A: */
  80. /* a11 a12 a13 a14 */
  81. /* a22 a23 a24 */
  82. /* a33 a34 (aij = aji) */
  83. /* a44 */
  84. /* Packed storage of the upper triangle of A: */
  85. /* AP = [ a11, a12, a22, a13, a23, a33, a14, a24, a34, a44 ] */
  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. --ap;
  101. /* Function Body */
  102. *info = 0;
  103. upper = _starpu_lsame_(uplo, "U");
  104. if (! upper && ! _starpu_lsame_(uplo, "L")) {
  105. *info = -1;
  106. } else if (*n < 0) {
  107. *info = -2;
  108. }
  109. if (*info != 0) {
  110. i__1 = -(*info);
  111. _starpu_xerbla_("DPPTRF", &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. jj = 0;
  121. i__1 = *n;
  122. for (j = 1; j <= i__1; ++j) {
  123. jc = jj + 1;
  124. jj += j;
  125. /* Compute elements 1:J-1 of column J. */
  126. if (j > 1) {
  127. i__2 = j - 1;
  128. _starpu_dtpsv_("Upper", "Transpose", "Non-unit", &i__2, &ap[1], &ap[
  129. jc], &c__1);
  130. }
  131. /* Compute U(J,J) and test for non-positive-definiteness. */
  132. i__2 = j - 1;
  133. ajj = ap[jj] - _starpu_ddot_(&i__2, &ap[jc], &c__1, &ap[jc], &c__1);
  134. if (ajj <= 0.) {
  135. ap[jj] = ajj;
  136. goto L30;
  137. }
  138. ap[jj] = sqrt(ajj);
  139. /* L10: */
  140. }
  141. } else {
  142. /* Compute the Cholesky factorization A = L*L'. */
  143. jj = 1;
  144. i__1 = *n;
  145. for (j = 1; j <= i__1; ++j) {
  146. /* Compute L(J,J) and test for non-positive-definiteness. */
  147. ajj = ap[jj];
  148. if (ajj <= 0.) {
  149. ap[jj] = ajj;
  150. goto L30;
  151. }
  152. ajj = sqrt(ajj);
  153. ap[jj] = ajj;
  154. /* Compute elements J+1:N of column J and update the trailing */
  155. /* submatrix. */
  156. if (j < *n) {
  157. i__2 = *n - j;
  158. d__1 = 1. / ajj;
  159. _starpu_dscal_(&i__2, &d__1, &ap[jj + 1], &c__1);
  160. i__2 = *n - j;
  161. _starpu_dspr_("Lower", &i__2, &c_b16, &ap[jj + 1], &c__1, &ap[jj + *n
  162. - j + 1]);
  163. jj = jj + *n - j + 1;
  164. }
  165. /* L20: */
  166. }
  167. }
  168. goto L40;
  169. L30:
  170. *info = j;
  171. L40:
  172. return 0;
  173. /* End of DPPTRF */
  174. } /* _starpu_dpptrf_ */