dgbcon.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /* dgbcon.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_dgbcon_(char *norm, integer *n, integer *kl, integer *ku,
  16. doublereal *ab, integer *ldab, integer *ipiv, doublereal *anorm,
  17. doublereal *rcond, doublereal *work, integer *iwork, integer *info)
  18. {
  19. /* System generated locals */
  20. integer ab_dim1, ab_offset, i__1, i__2, i__3;
  21. doublereal d__1;
  22. /* Local variables */
  23. integer j;
  24. doublereal t;
  25. integer kd, lm, jp, ix, kase;
  26. extern doublereal _starpu_ddot_(integer *, doublereal *, integer *, doublereal *,
  27. integer *);
  28. integer kase1;
  29. doublereal scale;
  30. extern logical _starpu_lsame_(char *, char *);
  31. integer isave[3];
  32. extern /* Subroutine */ int _starpu_drscl_(integer *, doublereal *, doublereal *,
  33. integer *);
  34. logical lnoti;
  35. extern /* Subroutine */ int _starpu_daxpy_(integer *, doublereal *, doublereal *,
  36. integer *, doublereal *, integer *), _starpu_dlacn2_(integer *,
  37. doublereal *, doublereal *, integer *, doublereal *, integer *,
  38. integer *);
  39. extern doublereal _starpu_dlamch_(char *);
  40. extern integer _starpu_idamax_(integer *, doublereal *, integer *);
  41. extern /* Subroutine */ int _starpu_dlatbs_(char *, char *, char *, char *,
  42. integer *, integer *, doublereal *, integer *, doublereal *,
  43. doublereal *, doublereal *, integer *), _starpu_xerbla_(char *, integer *);
  44. doublereal ainvnm;
  45. logical onenrm;
  46. char normin[1];
  47. doublereal smlnum;
  48. /* -- LAPACK routine (version 3.2) -- */
  49. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  50. /* November 2006 */
  51. /* Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */
  52. /* .. Scalar Arguments .. */
  53. /* .. */
  54. /* .. Array Arguments .. */
  55. /* .. */
  56. /* Purpose */
  57. /* ======= */
  58. /* DGBCON estimates the reciprocal of the condition number of a real */
  59. /* general band matrix A, in either the 1-norm or the infinity-norm, */
  60. /* using the LU factorization computed by DGBTRF. */
  61. /* An estimate is obtained for norm(inv(A)), and the reciprocal of the */
  62. /* condition number is computed as */
  63. /* RCOND = 1 / ( norm(A) * norm(inv(A)) ). */
  64. /* Arguments */
  65. /* ========= */
  66. /* NORM (input) CHARACTER*1 */
  67. /* Specifies whether the 1-norm condition number or the */
  68. /* infinity-norm condition number is required: */
  69. /* = '1' or 'O': 1-norm; */
  70. /* = 'I': Infinity-norm. */
  71. /* N (input) INTEGER */
  72. /* The order of the matrix A. N >= 0. */
  73. /* KL (input) INTEGER */
  74. /* The number of subdiagonals within the band of A. KL >= 0. */
  75. /* KU (input) INTEGER */
  76. /* The number of superdiagonals within the band of A. KU >= 0. */
  77. /* AB (input) DOUBLE PRECISION array, dimension (LDAB,N) */
  78. /* Details of the LU factorization of the band matrix A, as */
  79. /* computed by DGBTRF. U is stored as an upper triangular band */
  80. /* matrix with KL+KU superdiagonals in rows 1 to KL+KU+1, and */
  81. /* the multipliers used during the factorization are stored in */
  82. /* rows KL+KU+2 to 2*KL+KU+1. */
  83. /* LDAB (input) INTEGER */
  84. /* The leading dimension of the array AB. LDAB >= 2*KL+KU+1. */
  85. /* IPIV (input) INTEGER array, dimension (N) */
  86. /* The pivot indices; for 1 <= i <= N, row i of the matrix was */
  87. /* interchanged with row IPIV(i). */
  88. /* ANORM (input) DOUBLE PRECISION */
  89. /* If NORM = '1' or 'O', the 1-norm of the original matrix A. */
  90. /* If NORM = 'I', the infinity-norm of the original matrix A. */
  91. /* RCOND (output) DOUBLE PRECISION */
  92. /* The reciprocal of the condition number of the matrix A, */
  93. /* computed as RCOND = 1/(norm(A) * norm(inv(A))). */
  94. /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
  95. /* IWORK (workspace) INTEGER array, dimension (N) */
  96. /* INFO (output) INTEGER */
  97. /* = 0: successful exit */
  98. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  99. /* ===================================================================== */
  100. /* .. Parameters .. */
  101. /* .. */
  102. /* .. Local Scalars .. */
  103. /* .. */
  104. /* .. Local Arrays .. */
  105. /* .. */
  106. /* .. External Functions .. */
  107. /* .. */
  108. /* .. External Subroutines .. */
  109. /* .. */
  110. /* .. Intrinsic Functions .. */
  111. /* .. */
  112. /* .. Executable Statements .. */
  113. /* Test the input parameters. */
  114. /* Parameter adjustments */
  115. ab_dim1 = *ldab;
  116. ab_offset = 1 + ab_dim1;
  117. ab -= ab_offset;
  118. --ipiv;
  119. --work;
  120. --iwork;
  121. /* Function Body */
  122. *info = 0;
  123. onenrm = *(unsigned char *)norm == '1' || _starpu_lsame_(norm, "O");
  124. if (! onenrm && ! _starpu_lsame_(norm, "I")) {
  125. *info = -1;
  126. } else if (*n < 0) {
  127. *info = -2;
  128. } else if (*kl < 0) {
  129. *info = -3;
  130. } else if (*ku < 0) {
  131. *info = -4;
  132. } else if (*ldab < (*kl << 1) + *ku + 1) {
  133. *info = -6;
  134. } else if (*anorm < 0.) {
  135. *info = -8;
  136. }
  137. if (*info != 0) {
  138. i__1 = -(*info);
  139. _starpu_xerbla_("DGBCON", &i__1);
  140. return 0;
  141. }
  142. /* Quick return if possible */
  143. *rcond = 0.;
  144. if (*n == 0) {
  145. *rcond = 1.;
  146. return 0;
  147. } else if (*anorm == 0.) {
  148. return 0;
  149. }
  150. smlnum = _starpu_dlamch_("Safe minimum");
  151. /* Estimate the norm of inv(A). */
  152. ainvnm = 0.;
  153. *(unsigned char *)normin = 'N';
  154. if (onenrm) {
  155. kase1 = 1;
  156. } else {
  157. kase1 = 2;
  158. }
  159. kd = *kl + *ku + 1;
  160. lnoti = *kl > 0;
  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(L). */
  167. if (lnoti) {
  168. i__1 = *n - 1;
  169. for (j = 1; j <= i__1; ++j) {
  170. /* Computing MIN */
  171. i__2 = *kl, i__3 = *n - j;
  172. lm = min(i__2,i__3);
  173. jp = ipiv[j];
  174. t = work[jp];
  175. if (jp != j) {
  176. work[jp] = work[j];
  177. work[j] = t;
  178. }
  179. d__1 = -t;
  180. _starpu_daxpy_(&lm, &d__1, &ab[kd + 1 + j * ab_dim1], &c__1, &
  181. work[j + 1], &c__1);
  182. /* L20: */
  183. }
  184. }
  185. /* Multiply by inv(U). */
  186. i__1 = *kl + *ku;
  187. _starpu_dlatbs_("Upper", "No transpose", "Non-unit", normin, n, &i__1, &
  188. ab[ab_offset], ldab, &work[1], &scale, &work[(*n << 1) +
  189. 1], info);
  190. } else {
  191. /* Multiply by inv(U'). */
  192. i__1 = *kl + *ku;
  193. _starpu_dlatbs_("Upper", "Transpose", "Non-unit", normin, n, &i__1, &ab[
  194. ab_offset], ldab, &work[1], &scale, &work[(*n << 1) + 1],
  195. info);
  196. /* Multiply by inv(L'). */
  197. if (lnoti) {
  198. for (j = *n - 1; j >= 1; --j) {
  199. /* Computing MIN */
  200. i__1 = *kl, i__2 = *n - j;
  201. lm = min(i__1,i__2);
  202. work[j] -= _starpu_ddot_(&lm, &ab[kd + 1 + j * ab_dim1], &c__1, &
  203. work[j + 1], &c__1);
  204. jp = ipiv[j];
  205. if (jp != j) {
  206. t = work[jp];
  207. work[jp] = work[j];
  208. work[j] = t;
  209. }
  210. /* L30: */
  211. }
  212. }
  213. }
  214. /* Divide X by 1/SCALE if doing so will not cause overflow. */
  215. *(unsigned char *)normin = 'Y';
  216. if (scale != 1.) {
  217. ix = _starpu_idamax_(n, &work[1], &c__1);
  218. if (scale < (d__1 = work[ix], abs(d__1)) * smlnum || scale == 0.)
  219. {
  220. goto L40;
  221. }
  222. _starpu_drscl_(n, &scale, &work[1], &c__1);
  223. }
  224. goto L10;
  225. }
  226. /* Compute the estimate of the reciprocal condition number. */
  227. if (ainvnm != 0.) {
  228. *rcond = 1. / ainvnm / *anorm;
  229. }
  230. L40:
  231. return 0;
  232. /* End of DGBCON */
  233. } /* _starpu_dgbcon_ */