dlaexc.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. /* dlaexc.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. static integer c__4 = 4;
  16. static logical c_false = FALSE_;
  17. static integer c_n1 = -1;
  18. static integer c__2 = 2;
  19. static integer c__3 = 3;
  20. /* Subroutine */ int _starpu_dlaexc_(logical *wantq, integer *n, doublereal *t,
  21. integer *ldt, doublereal *q, integer *ldq, integer *j1, integer *n1,
  22. integer *n2, doublereal *work, integer *info)
  23. {
  24. /* System generated locals */
  25. integer q_dim1, q_offset, t_dim1, t_offset, i__1;
  26. doublereal d__1, d__2, d__3;
  27. /* Local variables */
  28. doublereal d__[16] /* was [4][4] */;
  29. integer k;
  30. doublereal u[3], x[4] /* was [2][2] */;
  31. integer j2, j3, j4;
  32. doublereal u1[3], u2[3];
  33. integer nd;
  34. doublereal cs, t11, t22, t33, sn, wi1, wi2, wr1, wr2, eps, tau, tau1,
  35. tau2;
  36. integer ierr;
  37. doublereal temp;
  38. extern /* Subroutine */ int _starpu_drot_(integer *, doublereal *, integer *,
  39. doublereal *, integer *, doublereal *, doublereal *);
  40. doublereal scale, dnorm, xnorm;
  41. extern /* Subroutine */ int _starpu_dlanv2_(doublereal *, doublereal *,
  42. doublereal *, doublereal *, doublereal *, doublereal *,
  43. doublereal *, doublereal *, doublereal *, doublereal *), _starpu_dlasy2_(
  44. logical *, logical *, integer *, integer *, integer *, doublereal
  45. *, integer *, doublereal *, integer *, doublereal *, integer *,
  46. doublereal *, doublereal *, integer *, doublereal *, integer *);
  47. extern doublereal _starpu_dlamch_(char *), _starpu_dlange_(char *, integer *,
  48. integer *, doublereal *, integer *, doublereal *);
  49. extern /* Subroutine */ int _starpu_dlarfg_(integer *, doublereal *, doublereal *,
  50. integer *, doublereal *), _starpu_dlacpy_(char *, integer *, integer *,
  51. doublereal *, integer *, doublereal *, integer *),
  52. _starpu_dlartg_(doublereal *, doublereal *, doublereal *, doublereal *,
  53. doublereal *), _starpu_dlarfx_(char *, integer *, integer *, doublereal *,
  54. doublereal *, doublereal *, integer *, doublereal *);
  55. doublereal thresh, smlnum;
  56. /* -- LAPACK auxiliary routine (version 3.2) -- */
  57. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  58. /* November 2006 */
  59. /* .. Scalar Arguments .. */
  60. /* .. */
  61. /* .. Array Arguments .. */
  62. /* .. */
  63. /* Purpose */
  64. /* ======= */
  65. /* DLAEXC swaps adjacent diagonal blocks T11 and T22 of order 1 or 2 in */
  66. /* an upper quasi-triangular matrix T by an orthogonal similarity */
  67. /* transformation. */
  68. /* T must be in Schur canonical form, that is, block upper triangular */
  69. /* with 1-by-1 and 2-by-2 diagonal blocks; each 2-by-2 diagonal block */
  70. /* has its diagonal elemnts equal and its off-diagonal elements of */
  71. /* opposite sign. */
  72. /* Arguments */
  73. /* ========= */
  74. /* WANTQ (input) LOGICAL */
  75. /* = .TRUE. : accumulate the transformation in the matrix Q; */
  76. /* = .FALSE.: do not accumulate the transformation. */
  77. /* N (input) INTEGER */
  78. /* The order of the matrix T. N >= 0. */
  79. /* T (input/output) DOUBLE PRECISION array, dimension (LDT,N) */
  80. /* On entry, the upper quasi-triangular matrix T, in Schur */
  81. /* canonical form. */
  82. /* On exit, the updated matrix T, again in Schur canonical form. */
  83. /* LDT (input) INTEGER */
  84. /* The leading dimension of the array T. LDT >= max(1,N). */
  85. /* Q (input/output) DOUBLE PRECISION array, dimension (LDQ,N) */
  86. /* On entry, if WANTQ is .TRUE., the orthogonal matrix Q. */
  87. /* On exit, if WANTQ is .TRUE., the updated matrix Q. */
  88. /* If WANTQ is .FALSE., Q is not referenced. */
  89. /* LDQ (input) INTEGER */
  90. /* The leading dimension of the array Q. */
  91. /* LDQ >= 1; and if WANTQ is .TRUE., LDQ >= N. */
  92. /* J1 (input) INTEGER */
  93. /* The index of the first row of the first block T11. */
  94. /* N1 (input) INTEGER */
  95. /* The order of the first block T11. N1 = 0, 1 or 2. */
  96. /* N2 (input) INTEGER */
  97. /* The order of the second block T22. N2 = 0, 1 or 2. */
  98. /* WORK (workspace) DOUBLE PRECISION array, dimension (N) */
  99. /* INFO (output) INTEGER */
  100. /* = 0: successful exit */
  101. /* = 1: the transformed matrix T would be too far from Schur */
  102. /* form; the blocks are not swapped and T and Q are */
  103. /* unchanged. */
  104. /* ===================================================================== */
  105. /* .. Parameters .. */
  106. /* .. */
  107. /* .. Local Scalars .. */
  108. /* .. */
  109. /* .. Local Arrays .. */
  110. /* .. */
  111. /* .. External Functions .. */
  112. /* .. */
  113. /* .. External Subroutines .. */
  114. /* .. */
  115. /* .. Intrinsic Functions .. */
  116. /* .. */
  117. /* .. Executable Statements .. */
  118. /* Parameter adjustments */
  119. t_dim1 = *ldt;
  120. t_offset = 1 + t_dim1;
  121. t -= t_offset;
  122. q_dim1 = *ldq;
  123. q_offset = 1 + q_dim1;
  124. q -= q_offset;
  125. --work;
  126. /* Function Body */
  127. *info = 0;
  128. /* Quick return if possible */
  129. if (*n == 0 || *n1 == 0 || *n2 == 0) {
  130. return 0;
  131. }
  132. if (*j1 + *n1 > *n) {
  133. return 0;
  134. }
  135. j2 = *j1 + 1;
  136. j3 = *j1 + 2;
  137. j4 = *j1 + 3;
  138. if (*n1 == 1 && *n2 == 1) {
  139. /* Swap two 1-by-1 blocks. */
  140. t11 = t[*j1 + *j1 * t_dim1];
  141. t22 = t[j2 + j2 * t_dim1];
  142. /* Determine the transformation to perform the interchange. */
  143. d__1 = t22 - t11;
  144. _starpu_dlartg_(&t[*j1 + j2 * t_dim1], &d__1, &cs, &sn, &temp);
  145. /* Apply transformation to the matrix T. */
  146. if (j3 <= *n) {
  147. i__1 = *n - *j1 - 1;
  148. _starpu_drot_(&i__1, &t[*j1 + j3 * t_dim1], ldt, &t[j2 + j3 * t_dim1],
  149. ldt, &cs, &sn);
  150. }
  151. i__1 = *j1 - 1;
  152. _starpu_drot_(&i__1, &t[*j1 * t_dim1 + 1], &c__1, &t[j2 * t_dim1 + 1], &c__1,
  153. &cs, &sn);
  154. t[*j1 + *j1 * t_dim1] = t22;
  155. t[j2 + j2 * t_dim1] = t11;
  156. if (*wantq) {
  157. /* Accumulate transformation in the matrix Q. */
  158. _starpu_drot_(n, &q[*j1 * q_dim1 + 1], &c__1, &q[j2 * q_dim1 + 1], &c__1,
  159. &cs, &sn);
  160. }
  161. } else {
  162. /* Swapping involves at least one 2-by-2 block. */
  163. /* Copy the diagonal block of order N1+N2 to the local array D */
  164. /* and compute its norm. */
  165. nd = *n1 + *n2;
  166. _starpu_dlacpy_("Full", &nd, &nd, &t[*j1 + *j1 * t_dim1], ldt, d__, &c__4);
  167. dnorm = _starpu_dlange_("Max", &nd, &nd, d__, &c__4, &work[1]);
  168. /* Compute machine-dependent threshold for test for accepting */
  169. /* swap. */
  170. eps = _starpu_dlamch_("P");
  171. smlnum = _starpu_dlamch_("S") / eps;
  172. /* Computing MAX */
  173. d__1 = eps * 10. * dnorm;
  174. thresh = max(d__1,smlnum);
  175. /* Solve T11*X - X*T22 = scale*T12 for X. */
  176. _starpu_dlasy2_(&c_false, &c_false, &c_n1, n1, n2, d__, &c__4, &d__[*n1 + 1 +
  177. (*n1 + 1 << 2) - 5], &c__4, &d__[(*n1 + 1 << 2) - 4], &c__4, &
  178. scale, x, &c__2, &xnorm, &ierr);
  179. /* Swap the adjacent diagonal blocks. */
  180. k = *n1 + *n1 + *n2 - 3;
  181. switch (k) {
  182. case 1: goto L10;
  183. case 2: goto L20;
  184. case 3: goto L30;
  185. }
  186. L10:
  187. /* N1 = 1, N2 = 2: generate elementary reflector H so that: */
  188. /* ( scale, X11, X12 ) H = ( 0, 0, * ) */
  189. u[0] = scale;
  190. u[1] = x[0];
  191. u[2] = x[2];
  192. _starpu_dlarfg_(&c__3, &u[2], u, &c__1, &tau);
  193. u[2] = 1.;
  194. t11 = t[*j1 + *j1 * t_dim1];
  195. /* Perform swap provisionally on diagonal block in D. */
  196. _starpu_dlarfx_("L", &c__3, &c__3, u, &tau, d__, &c__4, &work[1]);
  197. _starpu_dlarfx_("R", &c__3, &c__3, u, &tau, d__, &c__4, &work[1]);
  198. /* Test whether to reject swap. */
  199. /* Computing MAX */
  200. d__2 = abs(d__[2]), d__3 = abs(d__[6]), d__2 = max(d__2,d__3), d__3 =
  201. (d__1 = d__[10] - t11, abs(d__1));
  202. if (max(d__2,d__3) > thresh) {
  203. goto L50;
  204. }
  205. /* Accept swap: apply transformation to the entire matrix T. */
  206. i__1 = *n - *j1 + 1;
  207. _starpu_dlarfx_("L", &c__3, &i__1, u, &tau, &t[*j1 + *j1 * t_dim1], ldt, &
  208. work[1]);
  209. _starpu_dlarfx_("R", &j2, &c__3, u, &tau, &t[*j1 * t_dim1 + 1], ldt, &work[1]);
  210. t[j3 + *j1 * t_dim1] = 0.;
  211. t[j3 + j2 * t_dim1] = 0.;
  212. t[j3 + j3 * t_dim1] = t11;
  213. if (*wantq) {
  214. /* Accumulate transformation in the matrix Q. */
  215. _starpu_dlarfx_("R", n, &c__3, u, &tau, &q[*j1 * q_dim1 + 1], ldq, &work[
  216. 1]);
  217. }
  218. goto L40;
  219. L20:
  220. /* N1 = 2, N2 = 1: generate elementary reflector H so that: */
  221. /* H ( -X11 ) = ( * ) */
  222. /* ( -X21 ) = ( 0 ) */
  223. /* ( scale ) = ( 0 ) */
  224. u[0] = -x[0];
  225. u[1] = -x[1];
  226. u[2] = scale;
  227. _starpu_dlarfg_(&c__3, u, &u[1], &c__1, &tau);
  228. u[0] = 1.;
  229. t33 = t[j3 + j3 * t_dim1];
  230. /* Perform swap provisionally on diagonal block in D. */
  231. _starpu_dlarfx_("L", &c__3, &c__3, u, &tau, d__, &c__4, &work[1]);
  232. _starpu_dlarfx_("R", &c__3, &c__3, u, &tau, d__, &c__4, &work[1]);
  233. /* Test whether to reject swap. */
  234. /* Computing MAX */
  235. d__2 = abs(d__[1]), d__3 = abs(d__[2]), d__2 = max(d__2,d__3), d__3 =
  236. (d__1 = d__[0] - t33, abs(d__1));
  237. if (max(d__2,d__3) > thresh) {
  238. goto L50;
  239. }
  240. /* Accept swap: apply transformation to the entire matrix T. */
  241. _starpu_dlarfx_("R", &j3, &c__3, u, &tau, &t[*j1 * t_dim1 + 1], ldt, &work[1]);
  242. i__1 = *n - *j1;
  243. _starpu_dlarfx_("L", &c__3, &i__1, u, &tau, &t[*j1 + j2 * t_dim1], ldt, &work[
  244. 1]);
  245. t[*j1 + *j1 * t_dim1] = t33;
  246. t[j2 + *j1 * t_dim1] = 0.;
  247. t[j3 + *j1 * t_dim1] = 0.;
  248. if (*wantq) {
  249. /* Accumulate transformation in the matrix Q. */
  250. _starpu_dlarfx_("R", n, &c__3, u, &tau, &q[*j1 * q_dim1 + 1], ldq, &work[
  251. 1]);
  252. }
  253. goto L40;
  254. L30:
  255. /* N1 = 2, N2 = 2: generate elementary reflectors H(1) and H(2) so */
  256. /* that: */
  257. /* H(2) H(1) ( -X11 -X12 ) = ( * * ) */
  258. /* ( -X21 -X22 ) ( 0 * ) */
  259. /* ( scale 0 ) ( 0 0 ) */
  260. /* ( 0 scale ) ( 0 0 ) */
  261. u1[0] = -x[0];
  262. u1[1] = -x[1];
  263. u1[2] = scale;
  264. _starpu_dlarfg_(&c__3, u1, &u1[1], &c__1, &tau1);
  265. u1[0] = 1.;
  266. temp = -tau1 * (x[2] + u1[1] * x[3]);
  267. u2[0] = -temp * u1[1] - x[3];
  268. u2[1] = -temp * u1[2];
  269. u2[2] = scale;
  270. _starpu_dlarfg_(&c__3, u2, &u2[1], &c__1, &tau2);
  271. u2[0] = 1.;
  272. /* Perform swap provisionally on diagonal block in D. */
  273. _starpu_dlarfx_("L", &c__3, &c__4, u1, &tau1, d__, &c__4, &work[1])
  274. ;
  275. _starpu_dlarfx_("R", &c__4, &c__3, u1, &tau1, d__, &c__4, &work[1])
  276. ;
  277. _starpu_dlarfx_("L", &c__3, &c__4, u2, &tau2, &d__[1], &c__4, &work[1]);
  278. _starpu_dlarfx_("R", &c__4, &c__3, u2, &tau2, &d__[4], &c__4, &work[1]);
  279. /* Test whether to reject swap. */
  280. /* Computing MAX */
  281. d__1 = abs(d__[2]), d__2 = abs(d__[6]), d__1 = max(d__1,d__2), d__2 =
  282. abs(d__[3]), d__1 = max(d__1,d__2), d__2 = abs(d__[7]);
  283. if (max(d__1,d__2) > thresh) {
  284. goto L50;
  285. }
  286. /* Accept swap: apply transformation to the entire matrix T. */
  287. i__1 = *n - *j1 + 1;
  288. _starpu_dlarfx_("L", &c__3, &i__1, u1, &tau1, &t[*j1 + *j1 * t_dim1], ldt, &
  289. work[1]);
  290. _starpu_dlarfx_("R", &j4, &c__3, u1, &tau1, &t[*j1 * t_dim1 + 1], ldt, &work[
  291. 1]);
  292. i__1 = *n - *j1 + 1;
  293. _starpu_dlarfx_("L", &c__3, &i__1, u2, &tau2, &t[j2 + *j1 * t_dim1], ldt, &
  294. work[1]);
  295. _starpu_dlarfx_("R", &j4, &c__3, u2, &tau2, &t[j2 * t_dim1 + 1], ldt, &work[1]
  296. );
  297. t[j3 + *j1 * t_dim1] = 0.;
  298. t[j3 + j2 * t_dim1] = 0.;
  299. t[j4 + *j1 * t_dim1] = 0.;
  300. t[j4 + j2 * t_dim1] = 0.;
  301. if (*wantq) {
  302. /* Accumulate transformation in the matrix Q. */
  303. _starpu_dlarfx_("R", n, &c__3, u1, &tau1, &q[*j1 * q_dim1 + 1], ldq, &
  304. work[1]);
  305. _starpu_dlarfx_("R", n, &c__3, u2, &tau2, &q[j2 * q_dim1 + 1], ldq, &work[
  306. 1]);
  307. }
  308. L40:
  309. if (*n2 == 2) {
  310. /* Standardize new 2-by-2 block T11 */
  311. _starpu_dlanv2_(&t[*j1 + *j1 * t_dim1], &t[*j1 + j2 * t_dim1], &t[j2 + *
  312. j1 * t_dim1], &t[j2 + j2 * t_dim1], &wr1, &wi1, &wr2, &
  313. wi2, &cs, &sn);
  314. i__1 = *n - *j1 - 1;
  315. _starpu_drot_(&i__1, &t[*j1 + (*j1 + 2) * t_dim1], ldt, &t[j2 + (*j1 + 2)
  316. * t_dim1], ldt, &cs, &sn);
  317. i__1 = *j1 - 1;
  318. _starpu_drot_(&i__1, &t[*j1 * t_dim1 + 1], &c__1, &t[j2 * t_dim1 + 1], &
  319. c__1, &cs, &sn);
  320. if (*wantq) {
  321. _starpu_drot_(n, &q[*j1 * q_dim1 + 1], &c__1, &q[j2 * q_dim1 + 1], &
  322. c__1, &cs, &sn);
  323. }
  324. }
  325. if (*n1 == 2) {
  326. /* Standardize new 2-by-2 block T22 */
  327. j3 = *j1 + *n2;
  328. j4 = j3 + 1;
  329. _starpu_dlanv2_(&t[j3 + j3 * t_dim1], &t[j3 + j4 * t_dim1], &t[j4 + j3 *
  330. t_dim1], &t[j4 + j4 * t_dim1], &wr1, &wi1, &wr2, &wi2, &
  331. cs, &sn);
  332. if (j3 + 2 <= *n) {
  333. i__1 = *n - j3 - 1;
  334. _starpu_drot_(&i__1, &t[j3 + (j3 + 2) * t_dim1], ldt, &t[j4 + (j3 + 2)
  335. * t_dim1], ldt, &cs, &sn);
  336. }
  337. i__1 = j3 - 1;
  338. _starpu_drot_(&i__1, &t[j3 * t_dim1 + 1], &c__1, &t[j4 * t_dim1 + 1], &
  339. c__1, &cs, &sn);
  340. if (*wantq) {
  341. _starpu_drot_(n, &q[j3 * q_dim1 + 1], &c__1, &q[j4 * q_dim1 + 1], &
  342. c__1, &cs, &sn);
  343. }
  344. }
  345. }
  346. return 0;
  347. /* Exit with INFO = 1 if swap was rejected. */
  348. L50:
  349. *info = 1;
  350. return 0;
  351. /* End of DLAEXC */
  352. } /* _starpu_dlaexc_ */