dpbcon.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /* dpbcon.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_dpbcon_(char *uplo, integer *n, integer *kd, doublereal *
  16. ab, integer *ldab, doublereal *anorm, doublereal *rcond, doublereal *
  17. 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;
  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. logical upper;
  30. extern /* Subroutine */ int _starpu_dlacn2_(integer *, doublereal *, doublereal *,
  31. integer *, doublereal *, integer *, integer *);
  32. extern doublereal _starpu_dlamch_(char *);
  33. doublereal scalel;
  34. extern integer _starpu_idamax_(integer *, doublereal *, integer *);
  35. extern /* Subroutine */ int _starpu_dlatbs_(char *, char *, char *, char *,
  36. integer *, integer *, doublereal *, integer *, doublereal *,
  37. doublereal *, doublereal *, integer *);
  38. doublereal scaleu;
  39. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  40. doublereal ainvnm;
  41. char normin[1];
  42. doublereal smlnum;
  43. /* -- LAPACK routine (version 3.2) -- */
  44. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  45. /* November 2006 */
  46. /* Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */
  47. /* .. Scalar Arguments .. */
  48. /* .. */
  49. /* .. Array Arguments .. */
  50. /* .. */
  51. /* Purpose */
  52. /* ======= */
  53. /* DPBCON estimates the reciprocal of the condition number (in the */
  54. /* 1-norm) of a real symmetric positive definite band matrix using the */
  55. /* Cholesky factorization A = U**T*U or A = L*L**T computed by DPBTRF. */
  56. /* An estimate is obtained for norm(inv(A)), and the reciprocal of the */
  57. /* condition number is computed as RCOND = 1 / (ANORM * norm(inv(A))). */
  58. /* Arguments */
  59. /* ========= */
  60. /* UPLO (input) CHARACTER*1 */
  61. /* = 'U': Upper triangular factor stored in AB; */
  62. /* = 'L': Lower triangular factor stored in AB. */
  63. /* N (input) INTEGER */
  64. /* The order of the matrix A. N >= 0. */
  65. /* KD (input) INTEGER */
  66. /* The number of superdiagonals of the matrix A if UPLO = 'U', */
  67. /* or the number of subdiagonals if UPLO = 'L'. KD >= 0. */
  68. /* AB (input) DOUBLE PRECISION array, dimension (LDAB,N) */
  69. /* The triangular factor U or L from the Cholesky factorization */
  70. /* A = U**T*U or A = L*L**T of the band matrix A, stored in the */
  71. /* first KD+1 rows of the array. The j-th column of U or L is */
  72. /* stored in the j-th column of the array AB as follows: */
  73. /* if UPLO ='U', AB(kd+1+i-j,j) = U(i,j) for max(1,j-kd)<=i<=j; */
  74. /* if UPLO ='L', AB(1+i-j,j) = L(i,j) for j<=i<=min(n,j+kd). */
  75. /* LDAB (input) INTEGER */
  76. /* The leading dimension of the array AB. LDAB >= KD+1. */
  77. /* ANORM (input) DOUBLE PRECISION */
  78. /* The 1-norm (or infinity-norm) of the symmetric band matrix A. */
  79. /* RCOND (output) DOUBLE PRECISION */
  80. /* The reciprocal of the condition number of the matrix A, */
  81. /* computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is an */
  82. /* estimate of the 1-norm of inv(A) computed in this routine. */
  83. /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
  84. /* IWORK (workspace) INTEGER array, dimension (N) */
  85. /* INFO (output) INTEGER */
  86. /* = 0: successful exit */
  87. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  88. /* ===================================================================== */
  89. /* .. Parameters .. */
  90. /* .. */
  91. /* .. Local Scalars .. */
  92. /* .. */
  93. /* .. Local Arrays .. */
  94. /* .. */
  95. /* .. External Functions .. */
  96. /* .. */
  97. /* .. External Subroutines .. */
  98. /* .. */
  99. /* .. Intrinsic Functions .. */
  100. /* .. */
  101. /* .. Executable Statements .. */
  102. /* Test the input parameters. */
  103. /* Parameter adjustments */
  104. ab_dim1 = *ldab;
  105. ab_offset = 1 + ab_dim1;
  106. ab -= ab_offset;
  107. --work;
  108. --iwork;
  109. /* Function Body */
  110. *info = 0;
  111. upper = _starpu_lsame_(uplo, "U");
  112. if (! upper && ! _starpu_lsame_(uplo, "L")) {
  113. *info = -1;
  114. } else if (*n < 0) {
  115. *info = -2;
  116. } else if (*kd < 0) {
  117. *info = -3;
  118. } else if (*ldab < *kd + 1) {
  119. *info = -5;
  120. } else if (*anorm < 0.) {
  121. *info = -6;
  122. }
  123. if (*info != 0) {
  124. i__1 = -(*info);
  125. _starpu_xerbla_("DPBCON", &i__1);
  126. return 0;
  127. }
  128. /* Quick return if possible */
  129. *rcond = 0.;
  130. if (*n == 0) {
  131. *rcond = 1.;
  132. return 0;
  133. } else if (*anorm == 0.) {
  134. return 0;
  135. }
  136. smlnum = _starpu_dlamch_("Safe minimum");
  137. /* Estimate the 1-norm of the inverse. */
  138. kase = 0;
  139. *(unsigned char *)normin = 'N';
  140. L10:
  141. _starpu_dlacn2_(n, &work[*n + 1], &work[1], &iwork[1], &ainvnm, &kase, isave);
  142. if (kase != 0) {
  143. if (upper) {
  144. /* Multiply by inv(U'). */
  145. _starpu_dlatbs_("Upper", "Transpose", "Non-unit", normin, n, kd, &ab[
  146. ab_offset], ldab, &work[1], &scalel, &work[(*n << 1) + 1],
  147. info);
  148. *(unsigned char *)normin = 'Y';
  149. /* Multiply by inv(U). */
  150. _starpu_dlatbs_("Upper", "No transpose", "Non-unit", normin, n, kd, &ab[
  151. ab_offset], ldab, &work[1], &scaleu, &work[(*n << 1) + 1],
  152. info);
  153. } else {
  154. /* Multiply by inv(L). */
  155. _starpu_dlatbs_("Lower", "No transpose", "Non-unit", normin, n, kd, &ab[
  156. ab_offset], ldab, &work[1], &scalel, &work[(*n << 1) + 1],
  157. info);
  158. *(unsigned char *)normin = 'Y';
  159. /* Multiply by inv(L'). */
  160. _starpu_dlatbs_("Lower", "Transpose", "Non-unit", normin, n, kd, &ab[
  161. ab_offset], ldab, &work[1], &scaleu, &work[(*n << 1) + 1],
  162. info);
  163. }
  164. /* Multiply by 1/SCALE if doing so will not cause overflow. */
  165. scale = scalel * scaleu;
  166. if (scale != 1.) {
  167. ix = _starpu_idamax_(n, &work[1], &c__1);
  168. if (scale < (d__1 = work[ix], abs(d__1)) * smlnum || scale == 0.)
  169. {
  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. / ainvnm / *anorm;
  179. }
  180. L20:
  181. return 0;
  182. /* End of DPBCON */
  183. } /* _starpu_dpbcon_ */