dpteqr.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* dpteqr.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_b7 = 0.;
  15. static doublereal c_b8 = 1.;
  16. static integer c__0 = 0;
  17. static integer c__1 = 1;
  18. /* Subroutine */ int _starpu_dpteqr_(char *compz, integer *n, doublereal *d__,
  19. doublereal *e, doublereal *z__, integer *ldz, doublereal *work,
  20. integer *info)
  21. {
  22. /* System generated locals */
  23. integer z_dim1, z_offset, i__1;
  24. /* Builtin functions */
  25. double sqrt(doublereal);
  26. /* Local variables */
  27. doublereal c__[1] /* was [1][1] */;
  28. integer i__;
  29. doublereal vt[1] /* was [1][1] */;
  30. integer nru;
  31. extern logical _starpu_lsame_(char *, char *);
  32. extern /* Subroutine */ int _starpu_dlaset_(char *, integer *, integer *,
  33. doublereal *, doublereal *, doublereal *, integer *),
  34. _starpu_xerbla_(char *, integer *), _starpu_dbdsqr_(char *, integer *,
  35. integer *, integer *, integer *, doublereal *, doublereal *,
  36. doublereal *, integer *, doublereal *, integer *, doublereal *,
  37. integer *, doublereal *, integer *);
  38. integer icompz;
  39. extern /* Subroutine */ int _starpu_dpttrf_(integer *, doublereal *, doublereal *,
  40. integer *);
  41. /* -- LAPACK routine (version 3.2) -- */
  42. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  43. /* November 2006 */
  44. /* .. Scalar Arguments .. */
  45. /* .. */
  46. /* .. Array Arguments .. */
  47. /* .. */
  48. /* Purpose */
  49. /* ======= */
  50. /* DPTEQR computes all eigenvalues and, optionally, eigenvectors of a */
  51. /* symmetric positive definite tridiagonal matrix by first factoring the */
  52. /* matrix using DPTTRF, and then calling DBDSQR to compute the singular */
  53. /* values of the bidiagonal factor. */
  54. /* This routine computes the eigenvalues of the positive definite */
  55. /* tridiagonal matrix to high relative accuracy. This means that if the */
  56. /* eigenvalues range over many orders of magnitude in size, then the */
  57. /* small eigenvalues and corresponding eigenvectors will be computed */
  58. /* more accurately than, for example, with the standard QR method. */
  59. /* The eigenvectors of a full or band symmetric positive definite matrix */
  60. /* can also be found if DSYTRD, DSPTRD, or DSBTRD has been used to */
  61. /* reduce this matrix to tridiagonal form. (The reduction to tridiagonal */
  62. /* form, however, may preclude the possibility of obtaining high */
  63. /* relative accuracy in the small eigenvalues of the original matrix, if */
  64. /* these eigenvalues range over many orders of magnitude.) */
  65. /* Arguments */
  66. /* ========= */
  67. /* COMPZ (input) CHARACTER*1 */
  68. /* = 'N': Compute eigenvalues only. */
  69. /* = 'V': Compute eigenvectors of original symmetric */
  70. /* matrix also. Array Z contains the orthogonal */
  71. /* matrix used to reduce the original matrix to */
  72. /* tridiagonal form. */
  73. /* = 'I': Compute eigenvectors of tridiagonal matrix also. */
  74. /* N (input) INTEGER */
  75. /* The order of the matrix. N >= 0. */
  76. /* D (input/output) DOUBLE PRECISION array, dimension (N) */
  77. /* On entry, the n diagonal elements of the tridiagonal */
  78. /* matrix. */
  79. /* On normal exit, D contains the eigenvalues, in descending */
  80. /* order. */
  81. /* E (input/output) DOUBLE PRECISION array, dimension (N-1) */
  82. /* On entry, the (n-1) subdiagonal elements of the tridiagonal */
  83. /* matrix. */
  84. /* On exit, E has been destroyed. */
  85. /* Z (input/output) DOUBLE PRECISION array, dimension (LDZ, N) */
  86. /* On entry, if COMPZ = 'V', the orthogonal matrix used in the */
  87. /* reduction to tridiagonal form. */
  88. /* On exit, if COMPZ = 'V', the orthonormal eigenvectors of the */
  89. /* original symmetric matrix; */
  90. /* if COMPZ = 'I', the orthonormal eigenvectors of the */
  91. /* tridiagonal matrix. */
  92. /* If INFO > 0 on exit, Z contains the eigenvectors associated */
  93. /* with only the stored eigenvalues. */
  94. /* If COMPZ = 'N', then Z is not referenced. */
  95. /* LDZ (input) INTEGER */
  96. /* The leading dimension of the array Z. LDZ >= 1, and if */
  97. /* COMPZ = 'V' or 'I', LDZ >= max(1,N). */
  98. /* WORK (workspace) DOUBLE PRECISION array, dimension (4*N) */
  99. /* INFO (output) INTEGER */
  100. /* = 0: successful exit. */
  101. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  102. /* > 0: if INFO = i, and i is: */
  103. /* <= N the Cholesky factorization of the matrix could */
  104. /* not be performed because the i-th principal minor */
  105. /* was not positive definite. */
  106. /* > N the SVD algorithm failed to converge; */
  107. /* if INFO = N+i, i off-diagonal elements of the */
  108. /* bidiagonal factor did not converge to zero. */
  109. /* ===================================================================== */
  110. /* .. Parameters .. */
  111. /* .. */
  112. /* .. External Functions .. */
  113. /* .. */
  114. /* .. External Subroutines .. */
  115. /* .. */
  116. /* .. Local Arrays .. */
  117. /* .. */
  118. /* .. Local Scalars .. */
  119. /* .. */
  120. /* .. Intrinsic Functions .. */
  121. /* .. */
  122. /* .. Executable Statements .. */
  123. /* Test the input parameters. */
  124. /* Parameter adjustments */
  125. --d__;
  126. --e;
  127. z_dim1 = *ldz;
  128. z_offset = 1 + z_dim1;
  129. z__ -= z_offset;
  130. --work;
  131. /* Function Body */
  132. *info = 0;
  133. if (_starpu_lsame_(compz, "N")) {
  134. icompz = 0;
  135. } else if (_starpu_lsame_(compz, "V")) {
  136. icompz = 1;
  137. } else if (_starpu_lsame_(compz, "I")) {
  138. icompz = 2;
  139. } else {
  140. icompz = -1;
  141. }
  142. if (icompz < 0) {
  143. *info = -1;
  144. } else if (*n < 0) {
  145. *info = -2;
  146. } else if (*ldz < 1 || icompz > 0 && *ldz < max(1,*n)) {
  147. *info = -6;
  148. }
  149. if (*info != 0) {
  150. i__1 = -(*info);
  151. _starpu_xerbla_("DPTEQR", &i__1);
  152. return 0;
  153. }
  154. /* Quick return if possible */
  155. if (*n == 0) {
  156. return 0;
  157. }
  158. if (*n == 1) {
  159. if (icompz > 0) {
  160. z__[z_dim1 + 1] = 1.;
  161. }
  162. return 0;
  163. }
  164. if (icompz == 2) {
  165. _starpu_dlaset_("Full", n, n, &c_b7, &c_b8, &z__[z_offset], ldz);
  166. }
  167. /* Call DPTTRF to factor the matrix. */
  168. _starpu_dpttrf_(n, &d__[1], &e[1], info);
  169. if (*info != 0) {
  170. return 0;
  171. }
  172. i__1 = *n;
  173. for (i__ = 1; i__ <= i__1; ++i__) {
  174. d__[i__] = sqrt(d__[i__]);
  175. /* L10: */
  176. }
  177. i__1 = *n - 1;
  178. for (i__ = 1; i__ <= i__1; ++i__) {
  179. e[i__] *= d__[i__];
  180. /* L20: */
  181. }
  182. /* Call DBDSQR to compute the singular values/vectors of the */
  183. /* bidiagonal factor. */
  184. if (icompz > 0) {
  185. nru = *n;
  186. } else {
  187. nru = 0;
  188. }
  189. _starpu_dbdsqr_("Lower", n, &c__0, &nru, &c__0, &d__[1], &e[1], vt, &c__1, &z__[
  190. z_offset], ldz, c__, &c__1, &work[1], info);
  191. /* Square the singular values. */
  192. if (*info == 0) {
  193. i__1 = *n;
  194. for (i__ = 1; i__ <= i__1; ++i__) {
  195. d__[i__] *= d__[i__];
  196. /* L30: */
  197. }
  198. } else {
  199. *info = *n + *info;
  200. }
  201. return 0;
  202. /* End of DPTEQR */
  203. } /* _starpu_dpteqr_ */