dspev.c 7.2 KB

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