dtpcon.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /* dtpcon.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_dtpcon_(char *norm, char *uplo, char *diag, integer *n,
  16. doublereal *ap, doublereal *rcond, doublereal *work, integer *iwork,
  17. integer *info)
  18. {
  19. /* System generated locals */
  20. integer i__1;
  21. doublereal d__1;
  22. /* Local variables */
  23. integer ix, kase, kase1;
  24. doublereal scale;
  25. extern logical _starpu_lsame_(char *, char *);
  26. integer isave[3];
  27. extern /* Subroutine */ int _starpu_drscl_(integer *, doublereal *, doublereal *,
  28. integer *);
  29. doublereal anorm;
  30. logical upper;
  31. doublereal xnorm;
  32. extern /* Subroutine */ int _starpu_dlacn2_(integer *, doublereal *, doublereal *,
  33. integer *, doublereal *, integer *, integer *);
  34. extern doublereal _starpu_dlamch_(char *);
  35. extern integer _starpu_idamax_(integer *, doublereal *, integer *);
  36. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  37. extern doublereal _starpu_dlantp_(char *, char *, char *, integer *, doublereal *,
  38. doublereal *);
  39. doublereal ainvnm;
  40. extern /* Subroutine */ int _starpu_dlatps_(char *, char *, char *, char *,
  41. integer *, doublereal *, doublereal *, doublereal *, doublereal *,
  42. integer *);
  43. logical onenrm;
  44. char normin[1];
  45. doublereal smlnum;
  46. logical nounit;
  47. /* -- LAPACK routine (version 3.2) -- */
  48. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  49. /* November 2006 */
  50. /* Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */
  51. /* .. Scalar Arguments .. */
  52. /* .. */
  53. /* .. Array Arguments .. */
  54. /* .. */
  55. /* Purpose */
  56. /* ======= */
  57. /* DTPCON estimates the reciprocal of the condition number of a packed */
  58. /* triangular matrix A, in either the 1-norm or the infinity-norm. */
  59. /* The norm of A is computed and an estimate is obtained for */
  60. /* norm(inv(A)), then the reciprocal of the condition number is */
  61. /* computed as */
  62. /* RCOND = 1 / ( norm(A) * norm(inv(A)) ). */
  63. /* Arguments */
  64. /* ========= */
  65. /* NORM (input) CHARACTER*1 */
  66. /* Specifies whether the 1-norm condition number or the */
  67. /* infinity-norm condition number is required: */
  68. /* = '1' or 'O': 1-norm; */
  69. /* = 'I': Infinity-norm. */
  70. /* UPLO (input) CHARACTER*1 */
  71. /* = 'U': A is upper triangular; */
  72. /* = 'L': A is lower triangular. */
  73. /* DIAG (input) CHARACTER*1 */
  74. /* = 'N': A is non-unit triangular; */
  75. /* = 'U': A is unit triangular. */
  76. /* N (input) INTEGER */
  77. /* The order of the matrix A. N >= 0. */
  78. /* AP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
  79. /* The upper or lower triangular matrix A, packed columnwise in */
  80. /* a linear array. The j-th column of A is stored in the array */
  81. /* AP as follows: */
  82. /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
  83. /* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
  84. /* If DIAG = 'U', the diagonal elements of A are not referenced */
  85. /* and are assumed to be 1. */
  86. /* RCOND (output) DOUBLE PRECISION */
  87. /* The reciprocal of the condition number of the matrix A, */
  88. /* computed as RCOND = 1/(norm(A) * norm(inv(A))). */
  89. /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
  90. /* IWORK (workspace) INTEGER array, dimension (N) */
  91. /* INFO (output) INTEGER */
  92. /* = 0: successful exit */
  93. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  94. /* ===================================================================== */
  95. /* .. Parameters .. */
  96. /* .. */
  97. /* .. Local Scalars .. */
  98. /* .. */
  99. /* .. Local Arrays .. */
  100. /* .. */
  101. /* .. External Functions .. */
  102. /* .. */
  103. /* .. External Subroutines .. */
  104. /* .. */
  105. /* .. Intrinsic Functions .. */
  106. /* .. */
  107. /* .. Executable Statements .. */
  108. /* Test the input parameters. */
  109. /* Parameter adjustments */
  110. --iwork;
  111. --work;
  112. --ap;
  113. /* Function Body */
  114. *info = 0;
  115. upper = _starpu_lsame_(uplo, "U");
  116. onenrm = *(unsigned char *)norm == '1' || _starpu_lsame_(norm, "O");
  117. nounit = _starpu_lsame_(diag, "N");
  118. if (! onenrm && ! _starpu_lsame_(norm, "I")) {
  119. *info = -1;
  120. } else if (! upper && ! _starpu_lsame_(uplo, "L")) {
  121. *info = -2;
  122. } else if (! nounit && ! _starpu_lsame_(diag, "U")) {
  123. *info = -3;
  124. } else if (*n < 0) {
  125. *info = -4;
  126. }
  127. if (*info != 0) {
  128. i__1 = -(*info);
  129. _starpu_xerbla_("DTPCON", &i__1);
  130. return 0;
  131. }
  132. /* Quick return if possible */
  133. if (*n == 0) {
  134. *rcond = 1.;
  135. return 0;
  136. }
  137. *rcond = 0.;
  138. smlnum = _starpu_dlamch_("Safe minimum") * (doublereal) max(1,*n);
  139. /* Compute the norm of the triangular matrix A. */
  140. anorm = _starpu_dlantp_(norm, uplo, diag, n, &ap[1], &work[1]);
  141. /* Continue only if ANORM > 0. */
  142. if (anorm > 0.) {
  143. /* Estimate the norm of the inverse of A. */
  144. ainvnm = 0.;
  145. *(unsigned char *)normin = 'N';
  146. if (onenrm) {
  147. kase1 = 1;
  148. } else {
  149. kase1 = 2;
  150. }
  151. kase = 0;
  152. L10:
  153. _starpu_dlacn2_(n, &work[*n + 1], &work[1], &iwork[1], &ainvnm, &kase, isave);
  154. if (kase != 0) {
  155. if (kase == kase1) {
  156. /* Multiply by inv(A). */
  157. _starpu_dlatps_(uplo, "No transpose", diag, normin, n, &ap[1], &work[
  158. 1], &scale, &work[(*n << 1) + 1], info);
  159. } else {
  160. /* Multiply by inv(A'). */
  161. _starpu_dlatps_(uplo, "Transpose", diag, normin, n, &ap[1], &work[1],
  162. &scale, &work[(*n << 1) + 1], info);
  163. }
  164. *(unsigned char *)normin = 'Y';
  165. /* Multiply by 1/SCALE if doing so will not cause overflow. */
  166. if (scale != 1.) {
  167. ix = _starpu_idamax_(n, &work[1], &c__1);
  168. xnorm = (d__1 = work[ix], abs(d__1));
  169. if (scale < xnorm * smlnum || scale == 0.) {
  170. goto L20;
  171. }
  172. _starpu_drscl_(n, &scale, &work[1], &c__1);
  173. }
  174. goto L10;
  175. }
  176. /* Compute the estimate of the reciprocal condition number. */
  177. if (ainvnm != 0.) {
  178. *rcond = 1. / anorm / ainvnm;
  179. }
  180. }
  181. L20:
  182. return 0;
  183. /* End of DTPCON */
  184. } /* _starpu_dtpcon_ */