dtptri.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* dtptri.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. /* Subroutine */ int _starpu_dtptri_(char *uplo, char *diag, integer *n, doublereal *
  16. ap, integer *info)
  17. {
  18. /* System generated locals */
  19. integer i__1, i__2;
  20. /* Local variables */
  21. integer j, jc, jj;
  22. doublereal ajj;
  23. extern /* Subroutine */ int _starpu_dscal_(integer *, doublereal *, doublereal *,
  24. integer *);
  25. extern logical _starpu_lsame_(char *, char *);
  26. extern /* Subroutine */ int _starpu_dtpmv_(char *, char *, char *, integer *,
  27. doublereal *, doublereal *, integer *);
  28. logical upper;
  29. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  30. integer jclast;
  31. logical nounit;
  32. /* -- LAPACK routine (version 3.2) -- */
  33. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  34. /* November 2006 */
  35. /* .. Scalar Arguments .. */
  36. /* .. */
  37. /* .. Array Arguments .. */
  38. /* .. */
  39. /* Purpose */
  40. /* ======= */
  41. /* DTPTRI computes the inverse of a real upper or lower triangular */
  42. /* matrix A stored in packed format. */
  43. /* Arguments */
  44. /* ========= */
  45. /* UPLO (input) CHARACTER*1 */
  46. /* = 'U': A is upper triangular; */
  47. /* = 'L': A is lower triangular. */
  48. /* DIAG (input) CHARACTER*1 */
  49. /* = 'N': A is non-unit triangular; */
  50. /* = 'U': A is unit triangular. */
  51. /* N (input) INTEGER */
  52. /* The order of the matrix A. N >= 0. */
  53. /* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
  54. /* On entry, the upper or lower triangular matrix A, stored */
  55. /* columnwise in a linear array. The j-th column of A is stored */
  56. /* in the array AP as follows: */
  57. /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
  58. /* if UPLO = 'L', AP(i + (j-1)*((2*n-j)/2) = A(i,j) for j<=i<=n. */
  59. /* See below for further details. */
  60. /* On exit, the (triangular) inverse of the original matrix, in */
  61. /* the same packed storage format. */
  62. /* INFO (output) INTEGER */
  63. /* = 0: successful exit */
  64. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  65. /* > 0: if INFO = i, A(i,i) is exactly zero. The triangular */
  66. /* matrix is singular and its inverse can not be computed. */
  67. /* Further Details */
  68. /* =============== */
  69. /* A triangular matrix A can be transferred to packed storage using one */
  70. /* of the following program segments: */
  71. /* UPLO = 'U': UPLO = 'L': */
  72. /* JC = 1 JC = 1 */
  73. /* DO 2 J = 1, N DO 2 J = 1, N */
  74. /* DO 1 I = 1, J DO 1 I = J, N */
  75. /* AP(JC+I-1) = A(I,J) AP(JC+I-J) = A(I,J) */
  76. /* 1 CONTINUE 1 CONTINUE */
  77. /* JC = JC + J JC = JC + N - J + 1 */
  78. /* 2 CONTINUE 2 CONTINUE */
  79. /* ===================================================================== */
  80. /* .. Parameters .. */
  81. /* .. */
  82. /* .. Local Scalars .. */
  83. /* .. */
  84. /* .. External Functions .. */
  85. /* .. */
  86. /* .. External Subroutines .. */
  87. /* .. */
  88. /* .. Executable Statements .. */
  89. /* Test the input parameters. */
  90. /* Parameter adjustments */
  91. --ap;
  92. /* Function Body */
  93. *info = 0;
  94. upper = _starpu_lsame_(uplo, "U");
  95. nounit = _starpu_lsame_(diag, "N");
  96. if (! upper && ! _starpu_lsame_(uplo, "L")) {
  97. *info = -1;
  98. } else if (! nounit && ! _starpu_lsame_(diag, "U")) {
  99. *info = -2;
  100. } else if (*n < 0) {
  101. *info = -3;
  102. }
  103. if (*info != 0) {
  104. i__1 = -(*info);
  105. _starpu_xerbla_("DTPTRI", &i__1);
  106. return 0;
  107. }
  108. /* Check for singularity if non-unit. */
  109. if (nounit) {
  110. if (upper) {
  111. jj = 0;
  112. i__1 = *n;
  113. for (*info = 1; *info <= i__1; ++(*info)) {
  114. jj += *info;
  115. if (ap[jj] == 0.) {
  116. return 0;
  117. }
  118. /* L10: */
  119. }
  120. } else {
  121. jj = 1;
  122. i__1 = *n;
  123. for (*info = 1; *info <= i__1; ++(*info)) {
  124. if (ap[jj] == 0.) {
  125. return 0;
  126. }
  127. jj = jj + *n - *info + 1;
  128. /* L20: */
  129. }
  130. }
  131. *info = 0;
  132. }
  133. if (upper) {
  134. /* Compute inverse of upper triangular matrix. */
  135. jc = 1;
  136. i__1 = *n;
  137. for (j = 1; j <= i__1; ++j) {
  138. if (nounit) {
  139. ap[jc + j - 1] = 1. / ap[jc + j - 1];
  140. ajj = -ap[jc + j - 1];
  141. } else {
  142. ajj = -1.;
  143. }
  144. /* Compute elements 1:j-1 of j-th column. */
  145. i__2 = j - 1;
  146. _starpu_dtpmv_("Upper", "No transpose", diag, &i__2, &ap[1], &ap[jc], &
  147. c__1);
  148. i__2 = j - 1;
  149. _starpu_dscal_(&i__2, &ajj, &ap[jc], &c__1);
  150. jc += j;
  151. /* L30: */
  152. }
  153. } else {
  154. /* Compute inverse of lower triangular matrix. */
  155. jc = *n * (*n + 1) / 2;
  156. for (j = *n; j >= 1; --j) {
  157. if (nounit) {
  158. ap[jc] = 1. / ap[jc];
  159. ajj = -ap[jc];
  160. } else {
  161. ajj = -1.;
  162. }
  163. if (j < *n) {
  164. /* Compute elements j+1:n of j-th column. */
  165. i__1 = *n - j;
  166. _starpu_dtpmv_("Lower", "No transpose", diag, &i__1, &ap[jclast], &ap[
  167. jc + 1], &c__1);
  168. i__1 = *n - j;
  169. _starpu_dscal_(&i__1, &ajj, &ap[jc + 1], &c__1);
  170. }
  171. jclast = jc;
  172. jc = jc - *n + j - 2;
  173. /* L40: */
  174. }
  175. }
  176. return 0;
  177. /* End of DTPTRI */
  178. } /* _starpu_dtptri_ */