You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

zdrgsx.f 33 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955
  1. *> \brief \b ZDRGSX
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. * Definition:
  9. * ===========
  10. *
  11. * SUBROUTINE ZDRGSX( NSIZE, NCMAX, THRESH, NIN, NOUT, A, LDA, B, AI,
  12. * BI, Z, Q, ALPHA, BETA, C, LDC, S, WORK, LWORK,
  13. * RWORK, IWORK, LIWORK, BWORK, INFO )
  14. *
  15. * .. Scalar Arguments ..
  16. * INTEGER INFO, LDA, LDC, LIWORK, LWORK, NCMAX, NIN,
  17. * $ NOUT, NSIZE
  18. * DOUBLE PRECISION THRESH
  19. * ..
  20. * .. Array Arguments ..
  21. * LOGICAL BWORK( * )
  22. * INTEGER IWORK( * )
  23. * DOUBLE PRECISION RWORK( * ), S( * )
  24. * COMPLEX*16 A( LDA, * ), AI( LDA, * ), ALPHA( * ),
  25. * $ B( LDA, * ), BETA( * ), BI( LDA, * ),
  26. * $ C( LDC, * ), Q( LDA, * ), WORK( * ),
  27. * $ Z( LDA, * )
  28. * ..
  29. *
  30. *
  31. *> \par Purpose:
  32. * =============
  33. *>
  34. *> \verbatim
  35. *>
  36. *> ZDRGSX checks the nonsymmetric generalized eigenvalue (Schur form)
  37. *> problem expert driver ZGGESX.
  38. *>
  39. *> ZGGES factors A and B as Q*S*Z' and Q*T*Z' , where ' means conjugate
  40. *> transpose, S and T are upper triangular (i.e., in generalized Schur
  41. *> form), and Q and Z are unitary. It also computes the generalized
  42. *> eigenvalues (alpha(j),beta(j)), j=1,...,n. Thus,
  43. *> w(j) = alpha(j)/beta(j) is a root of the characteristic equation
  44. *>
  45. *> det( A - w(j) B ) = 0
  46. *>
  47. *> Optionally it also reorders the eigenvalues so that a selected
  48. *> cluster of eigenvalues appears in the leading diagonal block of the
  49. *> Schur forms; computes a reciprocal condition number for the average
  50. *> of the selected eigenvalues; and computes a reciprocal condition
  51. *> number for the right and left deflating subspaces corresponding to
  52. *> the selected eigenvalues.
  53. *>
  54. *> When ZDRGSX is called with NSIZE > 0, five (5) types of built-in
  55. *> matrix pairs are used to test the routine ZGGESX.
  56. *>
  57. *> When ZDRGSX is called with NSIZE = 0, it reads in test matrix data
  58. *> to test ZGGESX.
  59. *> (need more details on what kind of read-in data are needed).
  60. *>
  61. *> For each matrix pair, the following tests will be performed and
  62. *> compared with the threshold THRESH except for the tests (7) and (9):
  63. *>
  64. *> (1) | A - Q S Z' | / ( |A| n ulp )
  65. *>
  66. *> (2) | B - Q T Z' | / ( |B| n ulp )
  67. *>
  68. *> (3) | I - QQ' | / ( n ulp )
  69. *>
  70. *> (4) | I - ZZ' | / ( n ulp )
  71. *>
  72. *> (5) if A is in Schur form (i.e. triangular form)
  73. *>
  74. *> (6) maximum over j of D(j) where:
  75. *>
  76. *> |alpha(j) - S(j,j)| |beta(j) - T(j,j)|
  77. *> D(j) = ------------------------ + -----------------------
  78. *> max(|alpha(j)|,|S(j,j)|) max(|beta(j)|,|T(j,j)|)
  79. *>
  80. *> (7) if sorting worked and SDIM is the number of eigenvalues
  81. *> which were selected.
  82. *>
  83. *> (8) the estimated value DIF does not differ from the true values of
  84. *> Difu and Difl more than a factor 10*THRESH. If the estimate DIF
  85. *> equals zero the corresponding true values of Difu and Difl
  86. *> should be less than EPS*norm(A, B). If the true value of Difu
  87. *> and Difl equal zero, the estimate DIF should be less than
  88. *> EPS*norm(A, B).
  89. *>
  90. *> (9) If INFO = N+3 is returned by ZGGESX, the reordering "failed"
  91. *> and we check that DIF = PL = PR = 0 and that the true value of
  92. *> Difu and Difl is < EPS*norm(A, B). We count the events when
  93. *> INFO=N+3.
  94. *>
  95. *> For read-in test matrices, the same tests are run except that the
  96. *> exact value for DIF (and PL) is input data. Additionally, there is
  97. *> one more test run for read-in test matrices:
  98. *>
  99. *> (10) the estimated value PL does not differ from the true value of
  100. *> PLTRU more than a factor THRESH. If the estimate PL equals
  101. *> zero the corresponding true value of PLTRU should be less than
  102. *> EPS*norm(A, B). If the true value of PLTRU equal zero, the
  103. *> estimate PL should be less than EPS*norm(A, B).
  104. *>
  105. *> Note that for the built-in tests, a total of 10*NSIZE*(NSIZE-1)
  106. *> matrix pairs are generated and tested. NSIZE should be kept small.
  107. *>
  108. *> SVD (routine ZGESVD) is used for computing the true value of DIF_u
  109. *> and DIF_l when testing the built-in test problems.
  110. *>
  111. *> Built-in Test Matrices
  112. *> ======================
  113. *>
  114. *> All built-in test matrices are the 2 by 2 block of triangular
  115. *> matrices
  116. *>
  117. *> A = [ A11 A12 ] and B = [ B11 B12 ]
  118. *> [ A22 ] [ B22 ]
  119. *>
  120. *> where for different type of A11 and A22 are given as the following.
  121. *> A12 and B12 are chosen so that the generalized Sylvester equation
  122. *>
  123. *> A11*R - L*A22 = -A12
  124. *> B11*R - L*B22 = -B12
  125. *>
  126. *> have prescribed solution R and L.
  127. *>
  128. *> Type 1: A11 = J_m(1,-1) and A_22 = J_k(1-a,1).
  129. *> B11 = I_m, B22 = I_k
  130. *> where J_k(a,b) is the k-by-k Jordan block with ``a'' on
  131. *> diagonal and ``b'' on superdiagonal.
  132. *>
  133. *> Type 2: A11 = (a_ij) = ( 2(.5-sin(i)) ) and
  134. *> B11 = (b_ij) = ( 2(.5-sin(ij)) ) for i=1,...,m, j=i,...,m
  135. *> A22 = (a_ij) = ( 2(.5-sin(i+j)) ) and
  136. *> B22 = (b_ij) = ( 2(.5-sin(ij)) ) for i=m+1,...,k, j=i,...,k
  137. *>
  138. *> Type 3: A11, A22 and B11, B22 are chosen as for Type 2, but each
  139. *> second diagonal block in A_11 and each third diagonal block
  140. *> in A_22 are made as 2 by 2 blocks.
  141. *>
  142. *> Type 4: A11 = ( 20(.5 - sin(ij)) ) and B22 = ( 2(.5 - sin(i+j)) )
  143. *> for i=1,...,m, j=1,...,m and
  144. *> A22 = ( 20(.5 - sin(i+j)) ) and B22 = ( 2(.5 - sin(ij)) )
  145. *> for i=m+1,...,k, j=m+1,...,k
  146. *>
  147. *> Type 5: (A,B) and have potentially close or common eigenvalues and
  148. *> very large departure from block diagonality A_11 is chosen
  149. *> as the m x m leading submatrix of A_1:
  150. *> | 1 b |
  151. *> | -b 1 |
  152. *> | 1+d b |
  153. *> | -b 1+d |
  154. *> A_1 = | d 1 |
  155. *> | -1 d |
  156. *> | -d 1 |
  157. *> | -1 -d |
  158. *> | 1 |
  159. *> and A_22 is chosen as the k x k leading submatrix of A_2:
  160. *> | -1 b |
  161. *> | -b -1 |
  162. *> | 1-d b |
  163. *> | -b 1-d |
  164. *> A_2 = | d 1+b |
  165. *> | -1-b d |
  166. *> | -d 1+b |
  167. *> | -1+b -d |
  168. *> | 1-d |
  169. *> and matrix B are chosen as identity matrices (see DLATM5).
  170. *>
  171. *> \endverbatim
  172. *
  173. * Arguments:
  174. * ==========
  175. *
  176. *> \param[in] NSIZE
  177. *> \verbatim
  178. *> NSIZE is INTEGER
  179. *> The maximum size of the matrices to use. NSIZE >= 0.
  180. *> If NSIZE = 0, no built-in tests matrices are used, but
  181. *> read-in test matrices are used to test DGGESX.
  182. *> \endverbatim
  183. *>
  184. *> \param[in] NCMAX
  185. *> \verbatim
  186. *> NCMAX is INTEGER
  187. *> Maximum allowable NMAX for generating Kroneker matrix
  188. *> in call to ZLAKF2
  189. *> \endverbatim
  190. *>
  191. *> \param[in] THRESH
  192. *> \verbatim
  193. *> THRESH is DOUBLE PRECISION
  194. *> A test will count as "failed" if the "error", computed as
  195. *> described above, exceeds THRESH. Note that the error
  196. *> is scaled to be O(1), so THRESH should be a reasonably
  197. *> small multiple of 1, e.g., 10 or 100. In particular,
  198. *> it should not depend on the precision (single vs. double)
  199. *> or the size of the matrix. THRESH >= 0.
  200. *> \endverbatim
  201. *>
  202. *> \param[in] NIN
  203. *> \verbatim
  204. *> NIN is INTEGER
  205. *> The FORTRAN unit number for reading in the data file of
  206. *> problems to solve.
  207. *> \endverbatim
  208. *>
  209. *> \param[in] NOUT
  210. *> \verbatim
  211. *> NOUT is INTEGER
  212. *> The FORTRAN unit number for printing out error messages
  213. *> (e.g., if a routine returns INFO not equal to 0.)
  214. *> \endverbatim
  215. *>
  216. *> \param[out] A
  217. *> \verbatim
  218. *> A is COMPLEX*16 array, dimension (LDA, NSIZE)
  219. *> Used to store the matrix whose eigenvalues are to be
  220. *> computed. On exit, A contains the last matrix actually used.
  221. *> \endverbatim
  222. *>
  223. *> \param[in] LDA
  224. *> \verbatim
  225. *> LDA is INTEGER
  226. *> The leading dimension of A, B, AI, BI, Z and Q,
  227. *> LDA >= max( 1, NSIZE ). For the read-in test,
  228. *> LDA >= max( 1, N ), N is the size of the test matrices.
  229. *> \endverbatim
  230. *>
  231. *> \param[out] B
  232. *> \verbatim
  233. *> B is COMPLEX*16 array, dimension (LDA, NSIZE)
  234. *> Used to store the matrix whose eigenvalues are to be
  235. *> computed. On exit, B contains the last matrix actually used.
  236. *> \endverbatim
  237. *>
  238. *> \param[out] AI
  239. *> \verbatim
  240. *> AI is COMPLEX*16 array, dimension (LDA, NSIZE)
  241. *> Copy of A, modified by ZGGESX.
  242. *> \endverbatim
  243. *>
  244. *> \param[out] BI
  245. *> \verbatim
  246. *> BI is COMPLEX*16 array, dimension (LDA, NSIZE)
  247. *> Copy of B, modified by ZGGESX.
  248. *> \endverbatim
  249. *>
  250. *> \param[out] Z
  251. *> \verbatim
  252. *> Z is COMPLEX*16 array, dimension (LDA, NSIZE)
  253. *> Z holds the left Schur vectors computed by ZGGESX.
  254. *> \endverbatim
  255. *>
  256. *> \param[out] Q
  257. *> \verbatim
  258. *> Q is COMPLEX*16 array, dimension (LDA, NSIZE)
  259. *> Q holds the right Schur vectors computed by ZGGESX.
  260. *> \endverbatim
  261. *>
  262. *> \param[out] ALPHA
  263. *> \verbatim
  264. *> ALPHA is COMPLEX*16 array, dimension (NSIZE)
  265. *> \endverbatim
  266. *>
  267. *> \param[out] BETA
  268. *> \verbatim
  269. *> BETA is COMPLEX*16 array, dimension (NSIZE)
  270. *>
  271. *> On exit, ALPHA/BETA are the eigenvalues.
  272. *> \endverbatim
  273. *>
  274. *> \param[out] C
  275. *> \verbatim
  276. *> C is COMPLEX*16 array, dimension (LDC, LDC)
  277. *> Store the matrix generated by subroutine ZLAKF2, this is the
  278. *> matrix formed by Kronecker products used for estimating
  279. *> DIF.
  280. *> \endverbatim
  281. *>
  282. *> \param[in] LDC
  283. *> \verbatim
  284. *> LDC is INTEGER
  285. *> The leading dimension of C. LDC >= max(1, LDA*LDA/2 ).
  286. *> \endverbatim
  287. *>
  288. *> \param[out] S
  289. *> \verbatim
  290. *> S is DOUBLE PRECISION array, dimension (LDC)
  291. *> Singular values of C
  292. *> \endverbatim
  293. *>
  294. *> \param[out] WORK
  295. *> \verbatim
  296. *> WORK is COMPLEX*16 array, dimension (LWORK)
  297. *> \endverbatim
  298. *>
  299. *> \param[in] LWORK
  300. *> \verbatim
  301. *> LWORK is INTEGER
  302. *> The dimension of the array WORK. LWORK >= 3*NSIZE*NSIZE/2
  303. *> \endverbatim
  304. *>
  305. *> \param[out] RWORK
  306. *> \verbatim
  307. *> RWORK is DOUBLE PRECISION array,
  308. *> dimension (5*NSIZE*NSIZE/2 - 4)
  309. *> \endverbatim
  310. *>
  311. *> \param[out] IWORK
  312. *> \verbatim
  313. *> IWORK is INTEGER array, dimension (LIWORK)
  314. *> \endverbatim
  315. *>
  316. *> \param[in] LIWORK
  317. *> \verbatim
  318. *> LIWORK is INTEGER
  319. *> The dimension of the array IWORK. LIWORK >= NSIZE + 2.
  320. *> \endverbatim
  321. *>
  322. *> \param[out] BWORK
  323. *> \verbatim
  324. *> BWORK is LOGICAL array, dimension (NSIZE)
  325. *> \endverbatim
  326. *>
  327. *> \param[out] INFO
  328. *> \verbatim
  329. *> INFO is INTEGER
  330. *> = 0: successful exit
  331. *> < 0: if INFO = -i, the i-th argument had an illegal value.
  332. *> > 0: A routine returned an error code.
  333. *> \endverbatim
  334. *
  335. * Authors:
  336. * ========
  337. *
  338. *> \author Univ. of Tennessee
  339. *> \author Univ. of California Berkeley
  340. *> \author Univ. of Colorado Denver
  341. *> \author NAG Ltd.
  342. *
  343. *> \ingroup complex16_eig
  344. *
  345. * =====================================================================
  346. SUBROUTINE ZDRGSX( NSIZE, NCMAX, THRESH, NIN, NOUT, A, LDA, B, AI,
  347. $ BI, Z, Q, ALPHA, BETA, C, LDC, S, WORK, LWORK,
  348. $ RWORK, IWORK, LIWORK, BWORK, INFO )
  349. *
  350. * -- LAPACK test routine --
  351. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  352. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  353. *
  354. * .. Scalar Arguments ..
  355. INTEGER INFO, LDA, LDC, LIWORK, LWORK, NCMAX, NIN,
  356. $ NOUT, NSIZE
  357. DOUBLE PRECISION THRESH
  358. * ..
  359. * .. Array Arguments ..
  360. LOGICAL BWORK( * )
  361. INTEGER IWORK( * )
  362. DOUBLE PRECISION RWORK( * ), S( * )
  363. COMPLEX*16 A( LDA, * ), AI( LDA, * ), ALPHA( * ),
  364. $ B( LDA, * ), BETA( * ), BI( LDA, * ),
  365. $ C( LDC, * ), Q( LDA, * ), WORK( * ),
  366. $ Z( LDA, * )
  367. * ..
  368. *
  369. * =====================================================================
  370. *
  371. * .. Parameters ..
  372. DOUBLE PRECISION ZERO, ONE, TEN
  373. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, TEN = 1.0D+1 )
  374. COMPLEX*16 CZERO
  375. PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ) )
  376. * ..
  377. * .. Local Scalars ..
  378. LOGICAL ILABAD
  379. CHARACTER SENSE
  380. INTEGER BDSPAC, I, IFUNC, J, LINFO, MAXWRK, MINWRK, MM,
  381. $ MN2, NERRS, NPTKNT, NTEST, NTESTT, PRTYPE, QBA,
  382. $ QBB
  383. DOUBLE PRECISION ABNRM, BIGNUM, DIFTRU, PLTRU, SMLNUM, TEMP1,
  384. $ TEMP2, THRSH2, ULP, ULPINV, WEIGHT
  385. COMPLEX*16 X
  386. * ..
  387. * .. Local Arrays ..
  388. DOUBLE PRECISION DIFEST( 2 ), PL( 2 ), RESULT( 10 )
  389. * ..
  390. * .. External Functions ..
  391. LOGICAL ZLCTSX
  392. INTEGER ILAENV
  393. DOUBLE PRECISION DLAMCH, ZLANGE
  394. EXTERNAL ZLCTSX, ILAENV, DLAMCH, ZLANGE
  395. * ..
  396. * .. External Subroutines ..
  397. EXTERNAL ALASVM, XERBLA, ZGESVD, ZGET51, ZGGESX,
  398. $ ZLACPY, ZLAKF2, ZLASET, ZLATM5
  399. * ..
  400. * .. Scalars in Common ..
  401. LOGICAL FS
  402. INTEGER K, M, MPLUSN, N
  403. * ..
  404. * .. Common blocks ..
  405. COMMON / MN / M, N, MPLUSN, K, FS
  406. * ..
  407. * .. Intrinsic Functions ..
  408. INTRINSIC ABS, DBLE, DIMAG, MAX, SQRT
  409. * ..
  410. * .. Statement Functions ..
  411. DOUBLE PRECISION ABS1
  412. * ..
  413. * .. Statement Function definitions ..
  414. ABS1( X ) = ABS( DBLE( X ) ) + ABS( DIMAG( X ) )
  415. * ..
  416. * .. Executable Statements ..
  417. *
  418. * Check for errors
  419. *
  420. INFO = 0
  421. IF( NSIZE.LT.0 ) THEN
  422. INFO = -1
  423. ELSE IF( THRESH.LT.ZERO ) THEN
  424. INFO = -2
  425. ELSE IF( NIN.LE.0 ) THEN
  426. INFO = -3
  427. ELSE IF( NOUT.LE.0 ) THEN
  428. INFO = -4
  429. ELSE IF( LDA.LT.1 .OR. LDA.LT.NSIZE ) THEN
  430. INFO = -6
  431. ELSE IF( LDC.LT.1 .OR. LDC.LT.NSIZE*NSIZE / 2 ) THEN
  432. INFO = -15
  433. ELSE IF( LIWORK.LT.NSIZE+2 ) THEN
  434. INFO = -21
  435. END IF
  436. *
  437. * Compute workspace
  438. * (Note: Comments in the code beginning "Workspace:" describe the
  439. * minimal amount of workspace needed at that point in the code,
  440. * as well as the preferred amount for good performance.
  441. * NB refers to the optimal block size for the immediately
  442. * following subroutine, as returned by ILAENV.)
  443. *
  444. MINWRK = 1
  445. IF( INFO.EQ.0 .AND. LWORK.GE.1 ) THEN
  446. MINWRK = 3*NSIZE*NSIZE / 2
  447. *
  448. * workspace for cggesx
  449. *
  450. MAXWRK = NSIZE*( 1+ILAENV( 1, 'ZGEQRF', ' ', NSIZE, 1, NSIZE,
  451. $ 0 ) )
  452. MAXWRK = MAX( MAXWRK, NSIZE*( 1+ILAENV( 1, 'ZUNGQR', ' ',
  453. $ NSIZE, 1, NSIZE, -1 ) ) )
  454. *
  455. * workspace for zgesvd
  456. *
  457. BDSPAC = 3*NSIZE*NSIZE / 2
  458. MAXWRK = MAX( MAXWRK, NSIZE*NSIZE*
  459. $ ( 1+ILAENV( 1, 'ZGEBRD', ' ', NSIZE*NSIZE / 2,
  460. $ NSIZE*NSIZE / 2, -1, -1 ) ) )
  461. MAXWRK = MAX( MAXWRK, BDSPAC )
  462. *
  463. MAXWRK = MAX( MAXWRK, MINWRK )
  464. *
  465. WORK( 1 ) = MAXWRK
  466. END IF
  467. *
  468. IF( LWORK.LT.MINWRK )
  469. $ INFO = -18
  470. *
  471. IF( INFO.NE.0 ) THEN
  472. CALL XERBLA( 'ZDRGSX', -INFO )
  473. RETURN
  474. END IF
  475. *
  476. * Important constants
  477. *
  478. ULP = DLAMCH( 'P' )
  479. ULPINV = ONE / ULP
  480. SMLNUM = DLAMCH( 'S' ) / ULP
  481. BIGNUM = ONE / SMLNUM
  482. THRSH2 = TEN*THRESH
  483. NTESTT = 0
  484. NERRS = 0
  485. *
  486. * Go to the tests for read-in matrix pairs
  487. *
  488. IFUNC = 0
  489. IF( NSIZE.EQ.0 )
  490. $ GO TO 70
  491. *
  492. * Test the built-in matrix pairs.
  493. * Loop over different functions (IFUNC) of ZGGESX, types (PRTYPE)
  494. * of test matrices, different size (M+N)
  495. *
  496. PRTYPE = 0
  497. QBA = 3
  498. QBB = 4
  499. WEIGHT = SQRT( ULP )
  500. *
  501. DO 60 IFUNC = 0, 3
  502. DO 50 PRTYPE = 1, 5
  503. DO 40 M = 1, NSIZE - 1
  504. DO 30 N = 1, NSIZE - M
  505. *
  506. WEIGHT = ONE / WEIGHT
  507. MPLUSN = M + N
  508. *
  509. * Generate test matrices
  510. *
  511. FS = .TRUE.
  512. K = 0
  513. *
  514. CALL ZLASET( 'Full', MPLUSN, MPLUSN, CZERO, CZERO, AI,
  515. $ LDA )
  516. CALL ZLASET( 'Full', MPLUSN, MPLUSN, CZERO, CZERO, BI,
  517. $ LDA )
  518. *
  519. CALL ZLATM5( PRTYPE, M, N, AI, LDA, AI( M+1, M+1 ),
  520. $ LDA, AI( 1, M+1 ), LDA, BI, LDA,
  521. $ BI( M+1, M+1 ), LDA, BI( 1, M+1 ), LDA,
  522. $ Q, LDA, Z, LDA, WEIGHT, QBA, QBB )
  523. *
  524. * Compute the Schur factorization and swapping the
  525. * m-by-m (1,1)-blocks with n-by-n (2,2)-blocks.
  526. * Swapping is accomplished via the function ZLCTSX
  527. * which is supplied below.
  528. *
  529. IF( IFUNC.EQ.0 ) THEN
  530. SENSE = 'N'
  531. ELSE IF( IFUNC.EQ.1 ) THEN
  532. SENSE = 'E'
  533. ELSE IF( IFUNC.EQ.2 ) THEN
  534. SENSE = 'V'
  535. ELSE IF( IFUNC.EQ.3 ) THEN
  536. SENSE = 'B'
  537. END IF
  538. *
  539. CALL ZLACPY( 'Full', MPLUSN, MPLUSN, AI, LDA, A, LDA )
  540. CALL ZLACPY( 'Full', MPLUSN, MPLUSN, BI, LDA, B, LDA )
  541. *
  542. CALL ZGGESX( 'V', 'V', 'S', ZLCTSX, SENSE, MPLUSN, AI,
  543. $ LDA, BI, LDA, MM, ALPHA, BETA, Q, LDA, Z,
  544. $ LDA, PL, DIFEST, WORK, LWORK, RWORK,
  545. $ IWORK, LIWORK, BWORK, LINFO )
  546. *
  547. IF( LINFO.NE.0 .AND. LINFO.NE.MPLUSN+2 ) THEN
  548. RESULT( 1 ) = ULPINV
  549. WRITE( NOUT, FMT = 9999 )'ZGGESX', LINFO, MPLUSN,
  550. $ PRTYPE
  551. INFO = LINFO
  552. GO TO 30
  553. END IF
  554. *
  555. * Compute the norm(A, B)
  556. *
  557. CALL ZLACPY( 'Full', MPLUSN, MPLUSN, AI, LDA, WORK,
  558. $ MPLUSN )
  559. CALL ZLACPY( 'Full', MPLUSN, MPLUSN, BI, LDA,
  560. $ WORK( MPLUSN*MPLUSN+1 ), MPLUSN )
  561. ABNRM = ZLANGE( 'Fro', MPLUSN, 2*MPLUSN, WORK, MPLUSN,
  562. $ RWORK )
  563. *
  564. * Do tests (1) to (4)
  565. *
  566. RESULT( 2 ) = ZERO
  567. CALL ZGET51( 1, MPLUSN, A, LDA, AI, LDA, Q, LDA, Z,
  568. $ LDA, WORK, RWORK, RESULT( 1 ) )
  569. CALL ZGET51( 1, MPLUSN, B, LDA, BI, LDA, Q, LDA, Z,
  570. $ LDA, WORK, RWORK, RESULT( 2 ) )
  571. CALL ZGET51( 3, MPLUSN, B, LDA, BI, LDA, Q, LDA, Q,
  572. $ LDA, WORK, RWORK, RESULT( 3 ) )
  573. CALL ZGET51( 3, MPLUSN, B, LDA, BI, LDA, Z, LDA, Z,
  574. $ LDA, WORK, RWORK, RESULT( 4 ) )
  575. NTEST = 4
  576. *
  577. * Do tests (5) and (6): check Schur form of A and
  578. * compare eigenvalues with diagonals.
  579. *
  580. TEMP1 = ZERO
  581. RESULT( 5 ) = ZERO
  582. RESULT( 6 ) = ZERO
  583. *
  584. DO 10 J = 1, MPLUSN
  585. ILABAD = .FALSE.
  586. TEMP2 = ( ABS1( ALPHA( J )-AI( J, J ) ) /
  587. $ MAX( SMLNUM, ABS1( ALPHA( J ) ),
  588. $ ABS1( AI( J, J ) ) )+
  589. $ ABS1( BETA( J )-BI( J, J ) ) /
  590. $ MAX( SMLNUM, ABS1( BETA( J ) ),
  591. $ ABS1( BI( J, J ) ) ) ) / ULP
  592. IF( J.LT.MPLUSN ) THEN
  593. IF( AI( J+1, J ).NE.ZERO ) THEN
  594. ILABAD = .TRUE.
  595. RESULT( 5 ) = ULPINV
  596. END IF
  597. END IF
  598. IF( J.GT.1 ) THEN
  599. IF( AI( J, J-1 ).NE.ZERO ) THEN
  600. ILABAD = .TRUE.
  601. RESULT( 5 ) = ULPINV
  602. END IF
  603. END IF
  604. TEMP1 = MAX( TEMP1, TEMP2 )
  605. IF( ILABAD ) THEN
  606. WRITE( NOUT, FMT = 9997 )J, MPLUSN, PRTYPE
  607. END IF
  608. 10 CONTINUE
  609. RESULT( 6 ) = TEMP1
  610. NTEST = NTEST + 2
  611. *
  612. * Test (7) (if sorting worked)
  613. *
  614. RESULT( 7 ) = ZERO
  615. IF( LINFO.EQ.MPLUSN+3 ) THEN
  616. RESULT( 7 ) = ULPINV
  617. ELSE IF( MM.NE.N ) THEN
  618. RESULT( 7 ) = ULPINV
  619. END IF
  620. NTEST = NTEST + 1
  621. *
  622. * Test (8): compare the estimated value DIF and its
  623. * value. first, compute the exact DIF.
  624. *
  625. RESULT( 8 ) = ZERO
  626. MN2 = MM*( MPLUSN-MM )*2
  627. IF( IFUNC.GE.2 .AND. MN2.LE.NCMAX*NCMAX ) THEN
  628. *
  629. * Note: for either following two cases, there are
  630. * almost same number of test cases fail the test.
  631. *
  632. CALL ZLAKF2( MM, MPLUSN-MM, AI, LDA,
  633. $ AI( MM+1, MM+1 ), BI,
  634. $ BI( MM+1, MM+1 ), C, LDC )
  635. *
  636. CALL ZGESVD( 'N', 'N', MN2, MN2, C, LDC, S, WORK,
  637. $ 1, WORK( 2 ), 1, WORK( 3 ), LWORK-2,
  638. $ RWORK, INFO )
  639. DIFTRU = S( MN2 )
  640. *
  641. IF( DIFEST( 2 ).EQ.ZERO ) THEN
  642. IF( DIFTRU.GT.ABNRM*ULP )
  643. $ RESULT( 8 ) = ULPINV
  644. ELSE IF( DIFTRU.EQ.ZERO ) THEN
  645. IF( DIFEST( 2 ).GT.ABNRM*ULP )
  646. $ RESULT( 8 ) = ULPINV
  647. ELSE IF( ( DIFTRU.GT.THRSH2*DIFEST( 2 ) ) .OR.
  648. $ ( DIFTRU*THRSH2.LT.DIFEST( 2 ) ) ) THEN
  649. RESULT( 8 ) = MAX( DIFTRU / DIFEST( 2 ),
  650. $ DIFEST( 2 ) / DIFTRU )
  651. END IF
  652. NTEST = NTEST + 1
  653. END IF
  654. *
  655. * Test (9)
  656. *
  657. RESULT( 9 ) = ZERO
  658. IF( LINFO.EQ.( MPLUSN+2 ) ) THEN
  659. IF( DIFTRU.GT.ABNRM*ULP )
  660. $ RESULT( 9 ) = ULPINV
  661. IF( ( IFUNC.GT.1 ) .AND. ( DIFEST( 2 ).NE.ZERO ) )
  662. $ RESULT( 9 ) = ULPINV
  663. IF( ( IFUNC.EQ.1 ) .AND. ( PL( 1 ).NE.ZERO ) )
  664. $ RESULT( 9 ) = ULPINV
  665. NTEST = NTEST + 1
  666. END IF
  667. *
  668. NTESTT = NTESTT + NTEST
  669. *
  670. * Print out tests which fail.
  671. *
  672. DO 20 J = 1, 9
  673. IF( RESULT( J ).GE.THRESH ) THEN
  674. *
  675. * If this is the first test to fail,
  676. * print a header to the data file.
  677. *
  678. IF( NERRS.EQ.0 ) THEN
  679. WRITE( NOUT, FMT = 9996 )'ZGX'
  680. *
  681. * Matrix types
  682. *
  683. WRITE( NOUT, FMT = 9994 )
  684. *
  685. * Tests performed
  686. *
  687. WRITE( NOUT, FMT = 9993 )'unitary', '''',
  688. $ 'transpose', ( '''', I = 1, 4 )
  689. *
  690. END IF
  691. NERRS = NERRS + 1
  692. IF( RESULT( J ).LT.10000.0D0 ) THEN
  693. WRITE( NOUT, FMT = 9992 )MPLUSN, PRTYPE,
  694. $ WEIGHT, M, J, RESULT( J )
  695. ELSE
  696. WRITE( NOUT, FMT = 9991 )MPLUSN, PRTYPE,
  697. $ WEIGHT, M, J, RESULT( J )
  698. END IF
  699. END IF
  700. 20 CONTINUE
  701. *
  702. 30 CONTINUE
  703. 40 CONTINUE
  704. 50 CONTINUE
  705. 60 CONTINUE
  706. *
  707. GO TO 150
  708. *
  709. 70 CONTINUE
  710. *
  711. * Read in data from file to check accuracy of condition estimation
  712. * Read input data until N=0
  713. *
  714. NPTKNT = 0
  715. *
  716. 80 CONTINUE
  717. READ( NIN, FMT = *, END = 140 )MPLUSN
  718. IF( MPLUSN.EQ.0 )
  719. $ GO TO 140
  720. READ( NIN, FMT = *, END = 140 )N
  721. DO 90 I = 1, MPLUSN
  722. READ( NIN, FMT = * )( AI( I, J ), J = 1, MPLUSN )
  723. 90 CONTINUE
  724. DO 100 I = 1, MPLUSN
  725. READ( NIN, FMT = * )( BI( I, J ), J = 1, MPLUSN )
  726. 100 CONTINUE
  727. READ( NIN, FMT = * )PLTRU, DIFTRU
  728. *
  729. NPTKNT = NPTKNT + 1
  730. FS = .TRUE.
  731. K = 0
  732. M = MPLUSN - N
  733. *
  734. CALL ZLACPY( 'Full', MPLUSN, MPLUSN, AI, LDA, A, LDA )
  735. CALL ZLACPY( 'Full', MPLUSN, MPLUSN, BI, LDA, B, LDA )
  736. *
  737. * Compute the Schur factorization while swapping the
  738. * m-by-m (1,1)-blocks with n-by-n (2,2)-blocks.
  739. *
  740. CALL ZGGESX( 'V', 'V', 'S', ZLCTSX, 'B', MPLUSN, AI, LDA, BI, LDA,
  741. $ MM, ALPHA, BETA, Q, LDA, Z, LDA, PL, DIFEST, WORK,
  742. $ LWORK, RWORK, IWORK, LIWORK, BWORK, LINFO )
  743. *
  744. IF( LINFO.NE.0 .AND. LINFO.NE.MPLUSN+2 ) THEN
  745. RESULT( 1 ) = ULPINV
  746. WRITE( NOUT, FMT = 9998 )'ZGGESX', LINFO, MPLUSN, NPTKNT
  747. GO TO 130
  748. END IF
  749. *
  750. * Compute the norm(A, B)
  751. * (should this be norm of (A,B) or (AI,BI)?)
  752. *
  753. CALL ZLACPY( 'Full', MPLUSN, MPLUSN, AI, LDA, WORK, MPLUSN )
  754. CALL ZLACPY( 'Full', MPLUSN, MPLUSN, BI, LDA,
  755. $ WORK( MPLUSN*MPLUSN+1 ), MPLUSN )
  756. ABNRM = ZLANGE( 'Fro', MPLUSN, 2*MPLUSN, WORK, MPLUSN, RWORK )
  757. *
  758. * Do tests (1) to (4)
  759. *
  760. CALL ZGET51( 1, MPLUSN, A, LDA, AI, LDA, Q, LDA, Z, LDA, WORK,
  761. $ RWORK, RESULT( 1 ) )
  762. CALL ZGET51( 1, MPLUSN, B, LDA, BI, LDA, Q, LDA, Z, LDA, WORK,
  763. $ RWORK, RESULT( 2 ) )
  764. CALL ZGET51( 3, MPLUSN, B, LDA, BI, LDA, Q, LDA, Q, LDA, WORK,
  765. $ RWORK, RESULT( 3 ) )
  766. CALL ZGET51( 3, MPLUSN, B, LDA, BI, LDA, Z, LDA, Z, LDA, WORK,
  767. $ RWORK, RESULT( 4 ) )
  768. *
  769. * Do tests (5) and (6): check Schur form of A and compare
  770. * eigenvalues with diagonals.
  771. *
  772. NTEST = 6
  773. TEMP1 = ZERO
  774. RESULT( 5 ) = ZERO
  775. RESULT( 6 ) = ZERO
  776. *
  777. DO 110 J = 1, MPLUSN
  778. ILABAD = .FALSE.
  779. TEMP2 = ( ABS1( ALPHA( J )-AI( J, J ) ) /
  780. $ MAX( SMLNUM, ABS1( ALPHA( J ) ), ABS1( AI( J, J ) ) )+
  781. $ ABS1( BETA( J )-BI( J, J ) ) /
  782. $ MAX( SMLNUM, ABS1( BETA( J ) ), ABS1( BI( J, J ) ) ) )
  783. $ / ULP
  784. IF( J.LT.MPLUSN ) THEN
  785. IF( AI( J+1, J ).NE.ZERO ) THEN
  786. ILABAD = .TRUE.
  787. RESULT( 5 ) = ULPINV
  788. END IF
  789. END IF
  790. IF( J.GT.1 ) THEN
  791. IF( AI( J, J-1 ).NE.ZERO ) THEN
  792. ILABAD = .TRUE.
  793. RESULT( 5 ) = ULPINV
  794. END IF
  795. END IF
  796. TEMP1 = MAX( TEMP1, TEMP2 )
  797. IF( ILABAD ) THEN
  798. WRITE( NOUT, FMT = 9997 )J, MPLUSN, NPTKNT
  799. END IF
  800. 110 CONTINUE
  801. RESULT( 6 ) = TEMP1
  802. *
  803. * Test (7) (if sorting worked) <--------- need to be checked.
  804. *
  805. NTEST = 7
  806. RESULT( 7 ) = ZERO
  807. IF( LINFO.EQ.MPLUSN+3 )
  808. $ RESULT( 7 ) = ULPINV
  809. *
  810. * Test (8): compare the estimated value of DIF and its true value.
  811. *
  812. NTEST = 8
  813. RESULT( 8 ) = ZERO
  814. IF( DIFEST( 2 ).EQ.ZERO ) THEN
  815. IF( DIFTRU.GT.ABNRM*ULP )
  816. $ RESULT( 8 ) = ULPINV
  817. ELSE IF( DIFTRU.EQ.ZERO ) THEN
  818. IF( DIFEST( 2 ).GT.ABNRM*ULP )
  819. $ RESULT( 8 ) = ULPINV
  820. ELSE IF( ( DIFTRU.GT.THRSH2*DIFEST( 2 ) ) .OR.
  821. $ ( DIFTRU*THRSH2.LT.DIFEST( 2 ) ) ) THEN
  822. RESULT( 8 ) = MAX( DIFTRU / DIFEST( 2 ), DIFEST( 2 ) / DIFTRU )
  823. END IF
  824. *
  825. * Test (9)
  826. *
  827. NTEST = 9
  828. RESULT( 9 ) = ZERO
  829. IF( LINFO.EQ.( MPLUSN+2 ) ) THEN
  830. IF( DIFTRU.GT.ABNRM*ULP )
  831. $ RESULT( 9 ) = ULPINV
  832. IF( ( IFUNC.GT.1 ) .AND. ( DIFEST( 2 ).NE.ZERO ) )
  833. $ RESULT( 9 ) = ULPINV
  834. IF( ( IFUNC.EQ.1 ) .AND. ( PL( 1 ).NE.ZERO ) )
  835. $ RESULT( 9 ) = ULPINV
  836. END IF
  837. *
  838. * Test (10): compare the estimated value of PL and it true value.
  839. *
  840. NTEST = 10
  841. RESULT( 10 ) = ZERO
  842. IF( PL( 1 ).EQ.ZERO ) THEN
  843. IF( PLTRU.GT.ABNRM*ULP )
  844. $ RESULT( 10 ) = ULPINV
  845. ELSE IF( PLTRU.EQ.ZERO ) THEN
  846. IF( PL( 1 ).GT.ABNRM*ULP )
  847. $ RESULT( 10 ) = ULPINV
  848. ELSE IF( ( PLTRU.GT.THRESH*PL( 1 ) ) .OR.
  849. $ ( PLTRU*THRESH.LT.PL( 1 ) ) ) THEN
  850. RESULT( 10 ) = ULPINV
  851. END IF
  852. *
  853. NTESTT = NTESTT + NTEST
  854. *
  855. * Print out tests which fail.
  856. *
  857. DO 120 J = 1, NTEST
  858. IF( RESULT( J ).GE.THRESH ) THEN
  859. *
  860. * If this is the first test to fail,
  861. * print a header to the data file.
  862. *
  863. IF( NERRS.EQ.0 ) THEN
  864. WRITE( NOUT, FMT = 9996 )'ZGX'
  865. *
  866. * Matrix types
  867. *
  868. WRITE( NOUT, FMT = 9995 )
  869. *
  870. * Tests performed
  871. *
  872. WRITE( NOUT, FMT = 9993 )'unitary', '''', 'transpose',
  873. $ ( '''', I = 1, 4 )
  874. *
  875. END IF
  876. NERRS = NERRS + 1
  877. IF( RESULT( J ).LT.10000.0D0 ) THEN
  878. WRITE( NOUT, FMT = 9990 )NPTKNT, MPLUSN, J, RESULT( J )
  879. ELSE
  880. WRITE( NOUT, FMT = 9989 )NPTKNT, MPLUSN, J, RESULT( J )
  881. END IF
  882. END IF
  883. *
  884. 120 CONTINUE
  885. *
  886. 130 CONTINUE
  887. GO TO 80
  888. 140 CONTINUE
  889. *
  890. 150 CONTINUE
  891. *
  892. * Summary
  893. *
  894. CALL ALASVM( 'ZGX', NOUT, NERRS, NTESTT, 0 )
  895. *
  896. WORK( 1 ) = MAXWRK
  897. *
  898. RETURN
  899. *
  900. 9999 FORMAT( ' ZDRGSX: ', A, ' returned INFO=', I6, '.', / 9X, 'N=',
  901. $ I6, ', JTYPE=', I6, ')' )
  902. *
  903. 9998 FORMAT( ' ZDRGSX: ', A, ' returned INFO=', I6, '.', / 9X, 'N=',
  904. $ I6, ', Input Example #', I2, ')' )
  905. *
  906. 9997 FORMAT( ' ZDRGSX: S not in Schur form at eigenvalue ', I6, '.',
  907. $ / 9X, 'N=', I6, ', JTYPE=', I6, ')' )
  908. *
  909. 9996 FORMAT( / 1X, A3, ' -- Complex Expert Generalized Schur form',
  910. $ ' problem driver' )
  911. *
  912. 9995 FORMAT( 'Input Example' )
  913. *
  914. 9994 FORMAT( ' Matrix types: ', /
  915. $ ' 1: A is a block diagonal matrix of Jordan blocks ',
  916. $ 'and B is the identity ', / ' matrix, ',
  917. $ / ' 2: A and B are upper triangular matrices, ',
  918. $ / ' 3: A and B are as type 2, but each second diagonal ',
  919. $ 'block in A_11 and ', /
  920. $ ' each third diagonal block in A_22 are 2x2 blocks,',
  921. $ / ' 4: A and B are block diagonal matrices, ',
  922. $ / ' 5: (A,B) has potentially close or common ',
  923. $ 'eigenvalues.', / )
  924. *
  925. 9993 FORMAT( / ' Tests performed: (S is Schur, T is triangular, ',
  926. $ 'Q and Z are ', A, ',', / 19X,
  927. $ ' a is alpha, b is beta, and ', A, ' means ', A, '.)',
  928. $ / ' 1 = | A - Q S Z', A,
  929. $ ' | / ( |A| n ulp ) 2 = | B - Q T Z', A,
  930. $ ' | / ( |B| n ulp )', / ' 3 = | I - QQ', A,
  931. $ ' | / ( n ulp ) 4 = | I - ZZ', A,
  932. $ ' | / ( n ulp )', / ' 5 = 1/ULP if A is not in ',
  933. $ 'Schur form S', / ' 6 = difference between (alpha,beta)',
  934. $ ' and diagonals of (S,T)', /
  935. $ ' 7 = 1/ULP if SDIM is not the correct number of ',
  936. $ 'selected eigenvalues', /
  937. $ ' 8 = 1/ULP if DIFEST/DIFTRU > 10*THRESH or ',
  938. $ 'DIFTRU/DIFEST > 10*THRESH',
  939. $ / ' 9 = 1/ULP if DIFEST <> 0 or DIFTRU > ULP*norm(A,B) ',
  940. $ 'when reordering fails', /
  941. $ ' 10 = 1/ULP if PLEST/PLTRU > THRESH or ',
  942. $ 'PLTRU/PLEST > THRESH', /
  943. $ ' ( Test 10 is only for input examples )', / )
  944. 9992 FORMAT( ' Matrix order=', I2, ', type=', I2, ', a=', D10.3,
  945. $ ', order(A_11)=', I2, ', result ', I2, ' is ', 0P, F8.2 )
  946. 9991 FORMAT( ' Matrix order=', I2, ', type=', I2, ', a=', D10.3,
  947. $ ', order(A_11)=', I2, ', result ', I2, ' is ', 0P, D10.3 )
  948. 9990 FORMAT( ' Input example #', I2, ', matrix order=', I4, ',',
  949. $ ' result ', I2, ' is', 0P, F8.2 )
  950. 9989 FORMAT( ' Input example #', I2, ', matrix order=', I4, ',',
  951. $ ' result ', I2, ' is', 1P, D10.3 )
  952. *
  953. * End of ZDRGSX
  954. *
  955. END