dsbev.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /* dsbev.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 doublereal c_b11 = 1.;
  15. static integer c__1 = 1;
  16. /* Subroutine */ int _starpu_dsbev_(char *jobz, char *uplo, integer *n, integer *kd,
  17. doublereal *ab, integer *ldab, doublereal *w, doublereal *z__,
  18. integer *ldz, doublereal *work, integer *info)
  19. {
  20. /* System generated locals */
  21. integer ab_dim1, ab_offset, z_dim1, z_offset, i__1;
  22. doublereal d__1;
  23. /* Builtin functions */
  24. double sqrt(doublereal);
  25. /* Local variables */
  26. doublereal eps;
  27. integer inde;
  28. doublereal anrm;
  29. integer imax;
  30. doublereal rmin, rmax;
  31. extern /* Subroutine */ int _starpu_dscal_(integer *, doublereal *, doublereal *,
  32. integer *);
  33. doublereal sigma;
  34. extern logical _starpu_lsame_(char *, char *);
  35. integer iinfo;
  36. logical lower, wantz;
  37. extern doublereal _starpu_dlamch_(char *);
  38. integer iscale;
  39. extern /* Subroutine */ int _starpu_dlascl_(char *, integer *, integer *,
  40. doublereal *, doublereal *, integer *, integer *, doublereal *,
  41. integer *, integer *);
  42. extern doublereal _starpu_dlansb_(char *, char *, integer *, integer *,
  43. doublereal *, integer *, doublereal *);
  44. doublereal safmin;
  45. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  46. doublereal bignum;
  47. extern /* Subroutine */ int _starpu_dsbtrd_(char *, char *, integer *, integer *,
  48. doublereal *, integer *, doublereal *, doublereal *, doublereal *,
  49. integer *, doublereal *, integer *), _starpu_dsterf_(
  50. integer *, doublereal *, doublereal *, integer *);
  51. integer indwrk;
  52. extern /* Subroutine */ int _starpu_dsteqr_(char *, integer *, doublereal *,
  53. doublereal *, doublereal *, integer *, doublereal *, integer *);
  54. doublereal smlnum;
  55. /* -- LAPACK driver routine (version 3.2) -- */
  56. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  57. /* November 2006 */
  58. /* .. Scalar Arguments .. */
  59. /* .. */
  60. /* .. Array Arguments .. */
  61. /* .. */
  62. /* Purpose */
  63. /* ======= */
  64. /* DSBEV computes all the eigenvalues and, optionally, eigenvectors of */
  65. /* a real symmetric band matrix A. */
  66. /* Arguments */
  67. /* ========= */
  68. /* JOBZ (input) CHARACTER*1 */
  69. /* = 'N': Compute eigenvalues only; */
  70. /* = 'V': Compute eigenvalues and eigenvectors. */
  71. /* UPLO (input) CHARACTER*1 */
  72. /* = 'U': Upper triangle of A is stored; */
  73. /* = 'L': Lower triangle of A is stored. */
  74. /* N (input) INTEGER */
  75. /* The order of the matrix A. N >= 0. */
  76. /* KD (input) INTEGER */
  77. /* The number of superdiagonals of the matrix A if UPLO = 'U', */
  78. /* or the number of subdiagonals if UPLO = 'L'. KD >= 0. */
  79. /* AB (input/output) DOUBLE PRECISION array, dimension (LDAB, N) */
  80. /* On entry, the upper or lower triangle of the symmetric band */
  81. /* matrix A, stored in the first KD+1 rows of the array. The */
  82. /* j-th column of A is stored in the j-th column of the array AB */
  83. /* 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. /* On exit, AB is overwritten by values generated during the */
  87. /* reduction to tridiagonal form. If UPLO = 'U', the first */
  88. /* superdiagonal and the diagonal of the tridiagonal matrix T */
  89. /* are returned in rows KD and KD+1 of AB, and if UPLO = 'L', */
  90. /* the diagonal and first subdiagonal of T are returned in the */
  91. /* first two rows of AB. */
  92. /* LDAB (input) INTEGER */
  93. /* The leading dimension of the array AB. LDAB >= KD + 1. */
  94. /* W (output) DOUBLE PRECISION array, dimension (N) */
  95. /* If INFO = 0, the eigenvalues in ascending order. */
  96. /* Z (output) DOUBLE PRECISION array, dimension (LDZ, N) */
  97. /* If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal */
  98. /* eigenvectors of the matrix A, with the i-th column of Z */
  99. /* holding the eigenvector associated with W(i). */
  100. /* If JOBZ = 'N', then Z is not referenced. */
  101. /* LDZ (input) INTEGER */
  102. /* The leading dimension of the array Z. LDZ >= 1, and if */
  103. /* JOBZ = 'V', LDZ >= max(1,N). */
  104. /* WORK (workspace) DOUBLE PRECISION array, dimension (max(1,3*N-2)) */
  105. /* INFO (output) INTEGER */
  106. /* = 0: successful exit */
  107. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  108. /* > 0: if INFO = i, the algorithm failed to converge; i */
  109. /* off-diagonal elements of an intermediate tridiagonal */
  110. /* form did not converge to zero. */
  111. /* ===================================================================== */
  112. /* .. Parameters .. */
  113. /* .. */
  114. /* .. Local Scalars .. */
  115. /* .. */
  116. /* .. External Functions .. */
  117. /* .. */
  118. /* .. External Subroutines .. */
  119. /* .. */
  120. /* .. Intrinsic Functions .. */
  121. /* .. */
  122. /* .. Executable Statements .. */
  123. /* Test the input parameters. */
  124. /* Parameter adjustments */
  125. ab_dim1 = *ldab;
  126. ab_offset = 1 + ab_dim1;
  127. ab -= ab_offset;
  128. --w;
  129. z_dim1 = *ldz;
  130. z_offset = 1 + z_dim1;
  131. z__ -= z_offset;
  132. --work;
  133. /* Function Body */
  134. wantz = _starpu_lsame_(jobz, "V");
  135. lower = _starpu_lsame_(uplo, "L");
  136. *info = 0;
  137. if (! (wantz || _starpu_lsame_(jobz, "N"))) {
  138. *info = -1;
  139. } else if (! (lower || _starpu_lsame_(uplo, "U"))) {
  140. *info = -2;
  141. } else if (*n < 0) {
  142. *info = -3;
  143. } else if (*kd < 0) {
  144. *info = -4;
  145. } else if (*ldab < *kd + 1) {
  146. *info = -6;
  147. } else if (*ldz < 1 || wantz && *ldz < *n) {
  148. *info = -9;
  149. }
  150. if (*info != 0) {
  151. i__1 = -(*info);
  152. _starpu_xerbla_("DSBEV ", &i__1);
  153. return 0;
  154. }
  155. /* Quick return if possible */
  156. if (*n == 0) {
  157. return 0;
  158. }
  159. if (*n == 1) {
  160. if (lower) {
  161. w[1] = ab[ab_dim1 + 1];
  162. } else {
  163. w[1] = ab[*kd + 1 + ab_dim1];
  164. }
  165. if (wantz) {
  166. z__[z_dim1 + 1] = 1.;
  167. }
  168. return 0;
  169. }
  170. /* Get machine constants. */
  171. safmin = _starpu_dlamch_("Safe minimum");
  172. eps = _starpu_dlamch_("Precision");
  173. smlnum = safmin / eps;
  174. bignum = 1. / smlnum;
  175. rmin = sqrt(smlnum);
  176. rmax = sqrt(bignum);
  177. /* Scale matrix to allowable range, if necessary. */
  178. anrm = _starpu_dlansb_("M", uplo, n, kd, &ab[ab_offset], ldab, &work[1]);
  179. iscale = 0;
  180. if (anrm > 0. && anrm < rmin) {
  181. iscale = 1;
  182. sigma = rmin / anrm;
  183. } else if (anrm > rmax) {
  184. iscale = 1;
  185. sigma = rmax / anrm;
  186. }
  187. if (iscale == 1) {
  188. if (lower) {
  189. _starpu_dlascl_("B", kd, kd, &c_b11, &sigma, n, n, &ab[ab_offset], ldab,
  190. info);
  191. } else {
  192. _starpu_dlascl_("Q", kd, kd, &c_b11, &sigma, n, n, &ab[ab_offset], ldab,
  193. info);
  194. }
  195. }
  196. /* Call DSBTRD to reduce symmetric band matrix to tridiagonal form. */
  197. inde = 1;
  198. indwrk = inde + *n;
  199. _starpu_dsbtrd_(jobz, uplo, n, kd, &ab[ab_offset], ldab, &w[1], &work[inde], &z__[
  200. z_offset], ldz, &work[indwrk], &iinfo);
  201. /* For eigenvalues only, call DSTERF. For eigenvectors, call SSTEQR. */
  202. if (! wantz) {
  203. _starpu_dsterf_(n, &w[1], &work[inde], info);
  204. } else {
  205. _starpu_dsteqr_(jobz, n, &w[1], &work[inde], &z__[z_offset], ldz, &work[
  206. indwrk], info);
  207. }
  208. /* If matrix was scaled, then rescale eigenvalues appropriately. */
  209. if (iscale == 1) {
  210. if (*info == 0) {
  211. imax = *n;
  212. } else {
  213. imax = *info - 1;
  214. }
  215. d__1 = 1. / sigma;
  216. _starpu_dscal_(&imax, &d__1, &w[1], &c__1);
  217. }
  218. return 0;
  219. /* End of DSBEV */
  220. } /* _starpu_dsbev_ */