dtbcon.c 7.1 KB

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