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.

cdrges3.f 34 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  1. *> \brief \b CDRGES3
  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 CDRGES3( NSIZES, NN, NTYPES, DOTYPE, ISEED, THRESH,
  12. * NOUNIT, A, LDA, B, S, T, Q, LDQ, Z, ALPHA,
  13. * BETA, WORK, LWORK, RWORK, RESULT, BWORK, INFO )
  14. *
  15. * .. Scalar Arguments ..
  16. * INTEGER INFO, LDA, LDQ, LWORK, NOUNIT, NSIZES, NTYPES
  17. * REAL THRESH
  18. * ..
  19. * .. Array Arguments ..
  20. * LOGICAL BWORK( * ), DOTYPE( * )
  21. * INTEGER ISEED( 4 ), NN( * )
  22. * REAL RESULT( 13 ), RWORK( * )
  23. * COMPLEX A( LDA, * ), ALPHA( * ), B( LDA, * ),
  24. * $ BETA( * ), Q( LDQ, * ), S( LDA, * ),
  25. * $ T( LDA, * ), WORK( * ), Z( LDQ, * )
  26. * ..
  27. *
  28. *
  29. *> \par Purpose:
  30. * =============
  31. *>
  32. *> \verbatim
  33. *>
  34. *> CDRGES3 checks the nonsymmetric generalized eigenvalue (Schur form)
  35. *> problem driver CGGES3.
  36. *>
  37. *> CGGES3 factors A and B as Q*S*Z' and Q*T*Z' , where ' means conjugate
  38. *> transpose, S and T are upper triangular (i.e., in generalized Schur
  39. *> form), and Q and Z are unitary. It also computes the generalized
  40. *> eigenvalues (alpha(j),beta(j)), j=1,...,n. Thus,
  41. *> w(j) = alpha(j)/beta(j) is a root of the characteristic equation
  42. *>
  43. *> det( A - w(j) B ) = 0
  44. *>
  45. *> Optionally it also reorder the eigenvalues so that a selected
  46. *> cluster of eigenvalues appears in the leading diagonal block of the
  47. *> Schur forms.
  48. *>
  49. *> When CDRGES3 is called, a number of matrix "sizes" ("N's") and a
  50. *> number of matrix "TYPES" are specified. For each size ("N")
  51. *> and each TYPE of matrix, a pair of matrices (A, B) will be generated
  52. *> and used for testing. For each matrix pair, the following 13 tests
  53. *> will be performed and compared with the threshold THRESH except
  54. *> the tests (5), (11) and (13).
  55. *>
  56. *>
  57. *> (1) | A - Q S Z' | / ( |A| n ulp ) (no sorting of eigenvalues)
  58. *>
  59. *>
  60. *> (2) | B - Q T Z' | / ( |B| n ulp ) (no sorting of eigenvalues)
  61. *>
  62. *>
  63. *> (3) | I - QQ' | / ( n ulp ) (no sorting of eigenvalues)
  64. *>
  65. *>
  66. *> (4) | I - ZZ' | / ( n ulp ) (no sorting of eigenvalues)
  67. *>
  68. *> (5) if A is in Schur form (i.e. triangular form) (no sorting of
  69. *> eigenvalues)
  70. *>
  71. *> (6) if eigenvalues = diagonal elements of the Schur form (S, T),
  72. *> i.e., test the maximum over j of D(j) where:
  73. *>
  74. *> |alpha(j) - S(j,j)| |beta(j) - T(j,j)|
  75. *> D(j) = ------------------------ + -----------------------
  76. *> max(|alpha(j)|,|S(j,j)|) max(|beta(j)|,|T(j,j)|)
  77. *>
  78. *> (no sorting of eigenvalues)
  79. *>
  80. *> (7) | (A,B) - Q (S,T) Z' | / ( |(A,B)| n ulp )
  81. *> (with sorting of eigenvalues).
  82. *>
  83. *> (8) | I - QQ' | / ( n ulp ) (with sorting of eigenvalues).
  84. *>
  85. *> (9) | I - ZZ' | / ( n ulp ) (with sorting of eigenvalues).
  86. *>
  87. *> (10) if A is in Schur form (i.e. quasi-triangular form)
  88. *> (with sorting of eigenvalues).
  89. *>
  90. *> (11) if eigenvalues = diagonal elements of the Schur form (S, T),
  91. *> i.e. test the maximum over j of D(j) where:
  92. *>
  93. *> |alpha(j) - S(j,j)| |beta(j) - T(j,j)|
  94. *> D(j) = ------------------------ + -----------------------
  95. *> max(|alpha(j)|,|S(j,j)|) max(|beta(j)|,|T(j,j)|)
  96. *>
  97. *> (with sorting of eigenvalues).
  98. *>
  99. *> (12) if sorting worked and SDIM is the number of eigenvalues
  100. *> which were CELECTed.
  101. *>
  102. *> Test Matrices
  103. *> =============
  104. *>
  105. *> The sizes of the test matrices are specified by an array
  106. *> NN(1:NSIZES); the value of each element NN(j) specifies one size.
  107. *> The "types" are specified by a logical array DOTYPE( 1:NTYPES ); if
  108. *> DOTYPE(j) is .TRUE., then matrix type "j" will be generated.
  109. *> Currently, the list of possible types is:
  110. *>
  111. *> (1) ( 0, 0 ) (a pair of zero matrices)
  112. *>
  113. *> (2) ( I, 0 ) (an identity and a zero matrix)
  114. *>
  115. *> (3) ( 0, I ) (an identity and a zero matrix)
  116. *>
  117. *> (4) ( I, I ) (a pair of identity matrices)
  118. *>
  119. *> t t
  120. *> (5) ( J , J ) (a pair of transposed Jordan blocks)
  121. *>
  122. *> t ( I 0 )
  123. *> (6) ( X, Y ) where X = ( J 0 ) and Y = ( t )
  124. *> ( 0 I ) ( 0 J )
  125. *> and I is a k x k identity and J a (k+1)x(k+1)
  126. *> Jordan block; k=(N-1)/2
  127. *>
  128. *> (7) ( D, I ) where D is diag( 0, 1,..., N-1 ) (a diagonal
  129. *> matrix with those diagonal entries.)
  130. *> (8) ( I, D )
  131. *>
  132. *> (9) ( big*D, small*I ) where "big" is near overflow and small=1/big
  133. *>
  134. *> (10) ( small*D, big*I )
  135. *>
  136. *> (11) ( big*I, small*D )
  137. *>
  138. *> (12) ( small*I, big*D )
  139. *>
  140. *> (13) ( big*D, big*I )
  141. *>
  142. *> (14) ( small*D, small*I )
  143. *>
  144. *> (15) ( D1, D2 ) where D1 is diag( 0, 0, 1, ..., N-3, 0 ) and
  145. *> D2 is diag( 0, N-3, N-4,..., 1, 0, 0 )
  146. *> t t
  147. *> (16) Q ( J , J ) Z where Q and Z are random orthogonal matrices.
  148. *>
  149. *> (17) Q ( T1, T2 ) Z where T1 and T2 are upper triangular matrices
  150. *> with random O(1) entries above the diagonal
  151. *> and diagonal entries diag(T1) =
  152. *> ( 0, 0, 1, ..., N-3, 0 ) and diag(T2) =
  153. *> ( 0, N-3, N-4,..., 1, 0, 0 )
  154. *>
  155. *> (18) Q ( T1, T2 ) Z diag(T1) = ( 0, 0, 1, 1, s, ..., s, 0 )
  156. *> diag(T2) = ( 0, 1, 0, 1,..., 1, 0 )
  157. *> s = machine precision.
  158. *>
  159. *> (19) Q ( T1, T2 ) Z diag(T1)=( 0,0,1,1, 1-d, ..., 1-(N-5)*d=s, 0 )
  160. *> diag(T2) = ( 0, 1, 0, 1, ..., 1, 0 )
  161. *>
  162. *> N-5
  163. *> (20) Q ( T1, T2 ) Z diag(T1)=( 0, 0, 1, 1, a, ..., a =s, 0 )
  164. *> diag(T2) = ( 0, 1, 0, 1, ..., 1, 0, 0 )
  165. *>
  166. *> (21) Q ( T1, T2 ) Z diag(T1)=( 0, 0, 1, r1, r2, ..., r(N-4), 0 )
  167. *> diag(T2) = ( 0, 1, 0, 1, ..., 1, 0, 0 )
  168. *> where r1,..., r(N-4) are random.
  169. *>
  170. *> (22) Q ( big*T1, small*T2 ) Z diag(T1) = ( 0, 0, 1, ..., N-3, 0 )
  171. *> diag(T2) = ( 0, 1, ..., 1, 0, 0 )
  172. *>
  173. *> (23) Q ( small*T1, big*T2 ) Z diag(T1) = ( 0, 0, 1, ..., N-3, 0 )
  174. *> diag(T2) = ( 0, 1, ..., 1, 0, 0 )
  175. *>
  176. *> (24) Q ( small*T1, small*T2 ) Z diag(T1) = ( 0, 0, 1, ..., N-3, 0 )
  177. *> diag(T2) = ( 0, 1, ..., 1, 0, 0 )
  178. *>
  179. *> (25) Q ( big*T1, big*T2 ) Z diag(T1) = ( 0, 0, 1, ..., N-3, 0 )
  180. *> diag(T2) = ( 0, 1, ..., 1, 0, 0 )
  181. *>
  182. *> (26) Q ( T1, T2 ) Z where T1 and T2 are random upper-triangular
  183. *> matrices.
  184. *>
  185. *> \endverbatim
  186. *
  187. * Arguments:
  188. * ==========
  189. *
  190. *> \param[in] NSIZES
  191. *> \verbatim
  192. *> NSIZES is INTEGER
  193. *> The number of sizes of matrices to use. If it is zero,
  194. *> SDRGES3 does nothing. NSIZES >= 0.
  195. *> \endverbatim
  196. *>
  197. *> \param[in] NN
  198. *> \verbatim
  199. *> NN is INTEGER array, dimension (NSIZES)
  200. *> An array containing the sizes to be used for the matrices.
  201. *> Zero values will be skipped. NN >= 0.
  202. *> \endverbatim
  203. *>
  204. *> \param[in] NTYPES
  205. *> \verbatim
  206. *> NTYPES is INTEGER
  207. *> The number of elements in DOTYPE. If it is zero, SDRGES3
  208. *> does nothing. It must be at least zero. If it is MAXTYP+1
  209. *> and NSIZES is 1, then an additional type, MAXTYP+1 is
  210. *> defined, which is to use whatever matrix is in A on input.
  211. *> This is only useful if DOTYPE(1:MAXTYP) is .FALSE. and
  212. *> DOTYPE(MAXTYP+1) is .TRUE. .
  213. *> \endverbatim
  214. *>
  215. *> \param[in] DOTYPE
  216. *> \verbatim
  217. *> DOTYPE is LOGICAL array, dimension (NTYPES)
  218. *> If DOTYPE(j) is .TRUE., then for each size in NN a
  219. *> matrix of that size and of type j will be generated.
  220. *> If NTYPES is smaller than the maximum number of types
  221. *> defined (PARAMETER MAXTYP), then types NTYPES+1 through
  222. *> MAXTYP will not be generated. If NTYPES is larger
  223. *> than MAXTYP, DOTYPE(MAXTYP+1) through DOTYPE(NTYPES)
  224. *> will be ignored.
  225. *> \endverbatim
  226. *>
  227. *> \param[in,out] ISEED
  228. *> \verbatim
  229. *> ISEED is INTEGER array, dimension (4)
  230. *> On entry ISEED specifies the seed of the random number
  231. *> generator. The array elements should be between 0 and 4095;
  232. *> if not they will be reduced mod 4096. Also, ISEED(4) must
  233. *> be odd. The random number generator uses a linear
  234. *> congruential sequence limited to small integers, and so
  235. *> should produce machine independent random numbers. The
  236. *> values of ISEED are changed on exit, and can be used in the
  237. *> next call to SDRGES3 to continue the same random number
  238. *> sequence.
  239. *> \endverbatim
  240. *>
  241. *> \param[in] THRESH
  242. *> \verbatim
  243. *> THRESH is REAL
  244. *> A test will count as "failed" if the "error", computed as
  245. *> described above, exceeds THRESH. Note that the error is
  246. *> scaled to be O(1), so THRESH should be a reasonably small
  247. *> multiple of 1, e.g., 10 or 100. In particular, it should
  248. *> not depend on the precision (single vs. double) or the size
  249. *> of the matrix. THRESH >= 0.
  250. *> \endverbatim
  251. *>
  252. *> \param[in] NOUNIT
  253. *> \verbatim
  254. *> NOUNIT is INTEGER
  255. *> The FORTRAN unit number for printing out error messages
  256. *> (e.g., if a routine returns IINFO not equal to 0.)
  257. *> \endverbatim
  258. *>
  259. *> \param[in,out] A
  260. *> \verbatim
  261. *> A is COMPLEX array, dimension(LDA, max(NN))
  262. *> Used to hold the original A matrix. Used as input only
  263. *> if NTYPES=MAXTYP+1, DOTYPE(1:MAXTYP)=.FALSE., and
  264. *> DOTYPE(MAXTYP+1)=.TRUE.
  265. *> \endverbatim
  266. *>
  267. *> \param[in] LDA
  268. *> \verbatim
  269. *> LDA is INTEGER
  270. *> The leading dimension of A, B, S, and T.
  271. *> It must be at least 1 and at least max( NN ).
  272. *> \endverbatim
  273. *>
  274. *> \param[in,out] B
  275. *> \verbatim
  276. *> B is COMPLEX array, dimension(LDA, max(NN))
  277. *> Used to hold the original B matrix. Used as input only
  278. *> if NTYPES=MAXTYP+1, DOTYPE(1:MAXTYP)=.FALSE., and
  279. *> DOTYPE(MAXTYP+1)=.TRUE.
  280. *> \endverbatim
  281. *>
  282. *> \param[out] S
  283. *> \verbatim
  284. *> S is COMPLEX array, dimension (LDA, max(NN))
  285. *> The Schur form matrix computed from A by CGGES3. On exit, S
  286. *> contains the Schur form matrix corresponding to the matrix
  287. *> in A.
  288. *> \endverbatim
  289. *>
  290. *> \param[out] T
  291. *> \verbatim
  292. *> T is COMPLEX array, dimension (LDA, max(NN))
  293. *> The upper triangular matrix computed from B by CGGES3.
  294. *> \endverbatim
  295. *>
  296. *> \param[out] Q
  297. *> \verbatim
  298. *> Q is COMPLEX array, dimension (LDQ, max(NN))
  299. *> The (left) orthogonal matrix computed by CGGES3.
  300. *> \endverbatim
  301. *>
  302. *> \param[in] LDQ
  303. *> \verbatim
  304. *> LDQ is INTEGER
  305. *> The leading dimension of Q and Z. It must
  306. *> be at least 1 and at least max( NN ).
  307. *> \endverbatim
  308. *>
  309. *> \param[out] Z
  310. *> \verbatim
  311. *> Z is COMPLEX array, dimension( LDQ, max(NN) )
  312. *> The (right) orthogonal matrix computed by CGGES3.
  313. *> \endverbatim
  314. *>
  315. *> \param[out] ALPHA
  316. *> \verbatim
  317. *> ALPHA is COMPLEX array, dimension (max(NN))
  318. *> \endverbatim
  319. *>
  320. *> \param[out] BETA
  321. *> \verbatim
  322. *> BETA is COMPLEX array, dimension (max(NN))
  323. *>
  324. *> The generalized eigenvalues of (A,B) computed by CGGES3.
  325. *> ALPHA(k) / BETA(k) is the k-th generalized eigenvalue of A
  326. *> and B.
  327. *> \endverbatim
  328. *>
  329. *> \param[out] WORK
  330. *> \verbatim
  331. *> WORK is COMPLEX array, dimension (LWORK)
  332. *> \endverbatim
  333. *>
  334. *> \param[in] LWORK
  335. *> \verbatim
  336. *> LWORK is INTEGER
  337. *> The dimension of the array WORK. LWORK >= 3*N*N.
  338. *> \endverbatim
  339. *>
  340. *> \param[out] RWORK
  341. *> \verbatim
  342. *> RWORK is REAL array, dimension ( 8*N )
  343. *> Real workspace.
  344. *> \endverbatim
  345. *>
  346. *> \param[out] RESULT
  347. *> \verbatim
  348. *> RESULT is REAL array, dimension (15)
  349. *> The values computed by the tests described above.
  350. *> The values are currently limited to 1/ulp, to avoid overflow.
  351. *> \endverbatim
  352. *>
  353. *> \param[out] BWORK
  354. *> \verbatim
  355. *> BWORK is LOGICAL array, dimension (N)
  356. *> \endverbatim
  357. *>
  358. *> \param[out] INFO
  359. *> \verbatim
  360. *> INFO is INTEGER
  361. *> = 0: successful exit
  362. *> < 0: if INFO = -i, the i-th argument had an illegal value.
  363. *> > 0: A routine returned an error code. INFO is the
  364. *> absolute value of the INFO value returned.
  365. *> \endverbatim
  366. *
  367. * Authors:
  368. * ========
  369. *
  370. *> \author Univ. of Tennessee
  371. *> \author Univ. of California Berkeley
  372. *> \author Univ. of Colorado Denver
  373. *> \author NAG Ltd.
  374. *
  375. *> \ingroup complex_eig
  376. *
  377. * =====================================================================
  378. SUBROUTINE CDRGES3( NSIZES, NN, NTYPES, DOTYPE, ISEED, THRESH,
  379. $ NOUNIT, A, LDA, B, S, T, Q, LDQ, Z, ALPHA,
  380. $ BETA, WORK, LWORK, RWORK, RESULT, BWORK,
  381. $ INFO )
  382. *
  383. * -- LAPACK test routine --
  384. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  385. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  386. *
  387. * .. Scalar Arguments ..
  388. INTEGER INFO, LDA, LDQ, LWORK, NOUNIT, NSIZES, NTYPES
  389. REAL THRESH
  390. * ..
  391. * .. Array Arguments ..
  392. LOGICAL BWORK( * ), DOTYPE( * )
  393. INTEGER ISEED( 4 ), NN( * )
  394. REAL RESULT( 13 ), RWORK( * )
  395. COMPLEX A( LDA, * ), ALPHA( * ), B( LDA, * ),
  396. $ BETA( * ), Q( LDQ, * ), S( LDA, * ),
  397. $ T( LDA, * ), WORK( * ), Z( LDQ, * )
  398. * ..
  399. *
  400. * =====================================================================
  401. *
  402. * .. Parameters ..
  403. REAL ZERO, ONE
  404. PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
  405. COMPLEX CZERO, CONE
  406. PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ),
  407. $ CONE = ( 1.0E+0, 0.0E+0 ) )
  408. INTEGER MAXTYP
  409. PARAMETER ( MAXTYP = 26 )
  410. * ..
  411. * .. Local Scalars ..
  412. LOGICAL BADNN, ILABAD
  413. CHARACTER SORT
  414. INTEGER I, IADD, IINFO, IN, ISORT, J, JC, JR, JSIZE,
  415. $ JTYPE, KNTEIG, MAXWRK, MINWRK, MTYPES, N, N1,
  416. $ NB, NERRS, NMATS, NMAX, NTEST, NTESTT, RSUB,
  417. $ SDIM
  418. REAL SAFMAX, SAFMIN, TEMP1, TEMP2, ULP, ULPINV
  419. COMPLEX CTEMP, X
  420. * ..
  421. * .. Local Arrays ..
  422. LOGICAL LASIGN( MAXTYP ), LBSIGN( MAXTYP )
  423. INTEGER IOLDSD( 4 ), KADD( 6 ), KAMAGN( MAXTYP ),
  424. $ KATYPE( MAXTYP ), KAZERO( MAXTYP ),
  425. $ KBMAGN( MAXTYP ), KBTYPE( MAXTYP ),
  426. $ KBZERO( MAXTYP ), KCLASS( MAXTYP ),
  427. $ KTRIAN( MAXTYP ), KZ1( 6 ), KZ2( 6 )
  428. REAL RMAGN( 0: 3 )
  429. * ..
  430. * .. External Functions ..
  431. LOGICAL CLCTES
  432. INTEGER ILAENV
  433. REAL SLAMCH
  434. COMPLEX CLARND
  435. EXTERNAL CLCTES, ILAENV, SLAMCH, CLARND
  436. * ..
  437. * .. External Subroutines ..
  438. EXTERNAL ALASVM, CGET51, CGET54, CGGES3, CLACPY, CLARFG,
  439. $ CLASET, CLATM4, CUNM2R, SLABAD, XERBLA
  440. * ..
  441. * .. Intrinsic Functions ..
  442. INTRINSIC ABS, AIMAG, CONJG, MAX, MIN, REAL, SIGN
  443. * ..
  444. * .. Statement Functions ..
  445. REAL ABS1
  446. * ..
  447. * .. Statement Function definitions ..
  448. ABS1( X ) = ABS( REAL( X ) ) + ABS( AIMAG( X ) )
  449. * ..
  450. * .. Data statements ..
  451. DATA KCLASS / 15*1, 10*2, 1*3 /
  452. DATA KZ1 / 0, 1, 2, 1, 3, 3 /
  453. DATA KZ2 / 0, 0, 1, 2, 1, 1 /
  454. DATA KADD / 0, 0, 0, 0, 3, 2 /
  455. DATA KATYPE / 0, 1, 0, 1, 2, 3, 4, 1, 4, 4, 1, 1, 4,
  456. $ 4, 4, 2, 4, 5, 8, 7, 9, 4*4, 0 /
  457. DATA KBTYPE / 0, 0, 1, 1, 2, -3, 1, 4, 1, 1, 4, 4,
  458. $ 1, 1, -4, 2, -4, 8*8, 0 /
  459. DATA KAZERO / 6*1, 2, 1, 2*2, 2*1, 2*2, 3, 1, 3,
  460. $ 4*5, 4*3, 1 /
  461. DATA KBZERO / 6*1, 1, 2, 2*1, 2*2, 2*1, 4, 1, 4,
  462. $ 4*6, 4*4, 1 /
  463. DATA KAMAGN / 8*1, 2, 3, 2, 3, 2, 3, 7*1, 2, 3, 3,
  464. $ 2, 1 /
  465. DATA KBMAGN / 8*1, 3, 2, 3, 2, 2, 3, 7*1, 3, 2, 3,
  466. $ 2, 1 /
  467. DATA KTRIAN / 16*0, 10*1 /
  468. DATA LASIGN / 6*.FALSE., .TRUE., .FALSE., 2*.TRUE.,
  469. $ 2*.FALSE., 3*.TRUE., .FALSE., .TRUE.,
  470. $ 3*.FALSE., 5*.TRUE., .FALSE. /
  471. DATA LBSIGN / 7*.FALSE., .TRUE., 2*.FALSE.,
  472. $ 2*.TRUE., 2*.FALSE., .TRUE., .FALSE., .TRUE.,
  473. $ 9*.FALSE. /
  474. * ..
  475. * .. Executable Statements ..
  476. *
  477. * Check for errors
  478. *
  479. INFO = 0
  480. *
  481. BADNN = .FALSE.
  482. NMAX = 1
  483. DO 10 J = 1, NSIZES
  484. NMAX = MAX( NMAX, NN( J ) )
  485. IF( NN( J ).LT.0 )
  486. $ BADNN = .TRUE.
  487. 10 CONTINUE
  488. *
  489. IF( NSIZES.LT.0 ) THEN
  490. INFO = -1
  491. ELSE IF( BADNN ) THEN
  492. INFO = -2
  493. ELSE IF( NTYPES.LT.0 ) THEN
  494. INFO = -3
  495. ELSE IF( THRESH.LT.ZERO ) THEN
  496. INFO = -6
  497. ELSE IF( LDA.LE.1 .OR. LDA.LT.NMAX ) THEN
  498. INFO = -9
  499. ELSE IF( LDQ.LE.1 .OR. LDQ.LT.NMAX ) THEN
  500. INFO = -14
  501. END IF
  502. *
  503. * Compute workspace
  504. * (Note: Comments in the code beginning "Workspace:" describe the
  505. * minimal amount of workspace needed at that point in the code,
  506. * as well as the preferred amount for good performance.
  507. * NB refers to the optimal block size for the immediately
  508. * following subroutine, as returned by ILAENV.
  509. *
  510. MINWRK = 1
  511. IF( INFO.EQ.0 .AND. LWORK.GE.1 ) THEN
  512. MINWRK = 3*NMAX*NMAX
  513. NB = MAX( 1, ILAENV( 1, 'CGEQRF', ' ', NMAX, NMAX, -1, -1 ),
  514. $ ILAENV( 1, 'CUNMQR', 'LC', NMAX, NMAX, NMAX, -1 ),
  515. $ ILAENV( 1, 'CUNGQR', ' ', NMAX, NMAX, NMAX, -1 ) )
  516. MAXWRK = MAX( NMAX+NMAX*NB, 3*NMAX*NMAX)
  517. WORK( 1 ) = MAXWRK
  518. END IF
  519. *
  520. IF( LWORK.LT.MINWRK )
  521. $ INFO = -19
  522. *
  523. IF( INFO.NE.0 ) THEN
  524. CALL XERBLA( 'CDRGES3', -INFO )
  525. RETURN
  526. END IF
  527. *
  528. * Quick return if possible
  529. *
  530. IF( NSIZES.EQ.0 .OR. NTYPES.EQ.0 )
  531. $ RETURN
  532. *
  533. ULP = SLAMCH( 'Precision' )
  534. SAFMIN = SLAMCH( 'Safe minimum' )
  535. SAFMIN = SAFMIN / ULP
  536. SAFMAX = ONE / SAFMIN
  537. CALL SLABAD( SAFMIN, SAFMAX )
  538. ULPINV = ONE / ULP
  539. *
  540. * The values RMAGN(2:3) depend on N, see below.
  541. *
  542. RMAGN( 0 ) = ZERO
  543. RMAGN( 1 ) = ONE
  544. *
  545. * Loop over matrix sizes
  546. *
  547. NTESTT = 0
  548. NERRS = 0
  549. NMATS = 0
  550. *
  551. DO 190 JSIZE = 1, NSIZES
  552. N = NN( JSIZE )
  553. N1 = MAX( 1, N )
  554. RMAGN( 2 ) = SAFMAX*ULP / REAL( N1 )
  555. RMAGN( 3 ) = SAFMIN*ULPINV*REAL( N1 )
  556. *
  557. IF( NSIZES.NE.1 ) THEN
  558. MTYPES = MIN( MAXTYP, NTYPES )
  559. ELSE
  560. MTYPES = MIN( MAXTYP+1, NTYPES )
  561. END IF
  562. *
  563. * Loop over matrix types
  564. *
  565. DO 180 JTYPE = 1, MTYPES
  566. IF( .NOT.DOTYPE( JTYPE ) )
  567. $ GO TO 180
  568. NMATS = NMATS + 1
  569. NTEST = 0
  570. *
  571. * Save ISEED in case of an error.
  572. *
  573. DO 20 J = 1, 4
  574. IOLDSD( J ) = ISEED( J )
  575. 20 CONTINUE
  576. *
  577. * Initialize RESULT
  578. *
  579. DO 30 J = 1, 13
  580. RESULT( J ) = ZERO
  581. 30 CONTINUE
  582. *
  583. * Generate test matrices A and B
  584. *
  585. * Description of control parameters:
  586. *
  587. * KCLASS: =1 means w/o rotation, =2 means w/ rotation,
  588. * =3 means random.
  589. * KATYPE: the "type" to be passed to CLATM4 for computing A.
  590. * KAZERO: the pattern of zeros on the diagonal for A:
  591. * =1: ( xxx ), =2: (0, xxx ) =3: ( 0, 0, xxx, 0 ),
  592. * =4: ( 0, xxx, 0, 0 ), =5: ( 0, 0, 1, xxx, 0 ),
  593. * =6: ( 0, 1, 0, xxx, 0 ). (xxx means a string of
  594. * non-zero entries.)
  595. * KAMAGN: the magnitude of the matrix: =0: zero, =1: O(1),
  596. * =2: large, =3: small.
  597. * LASIGN: .TRUE. if the diagonal elements of A are to be
  598. * multiplied by a random magnitude 1 number.
  599. * KBTYPE, KBZERO, KBMAGN, LBSIGN: the same, but for B.
  600. * KTRIAN: =0: don't fill in the upper triangle, =1: do.
  601. * KZ1, KZ2, KADD: used to implement KAZERO and KBZERO.
  602. * RMAGN: used to implement KAMAGN and KBMAGN.
  603. *
  604. IF( MTYPES.GT.MAXTYP )
  605. $ GO TO 110
  606. IINFO = 0
  607. IF( KCLASS( JTYPE ).LT.3 ) THEN
  608. *
  609. * Generate A (w/o rotation)
  610. *
  611. IF( ABS( KATYPE( JTYPE ) ).EQ.3 ) THEN
  612. IN = 2*( ( N-1 ) / 2 ) + 1
  613. IF( IN.NE.N )
  614. $ CALL CLASET( 'Full', N, N, CZERO, CZERO, A, LDA )
  615. ELSE
  616. IN = N
  617. END IF
  618. CALL CLATM4( KATYPE( JTYPE ), IN, KZ1( KAZERO( JTYPE ) ),
  619. $ KZ2( KAZERO( JTYPE ) ), LASIGN( JTYPE ),
  620. $ RMAGN( KAMAGN( JTYPE ) ), ULP,
  621. $ RMAGN( KTRIAN( JTYPE )*KAMAGN( JTYPE ) ), 2,
  622. $ ISEED, A, LDA )
  623. IADD = KADD( KAZERO( JTYPE ) )
  624. IF( IADD.GT.0 .AND. IADD.LE.N )
  625. $ A( IADD, IADD ) = RMAGN( KAMAGN( JTYPE ) )
  626. *
  627. * Generate B (w/o rotation)
  628. *
  629. IF( ABS( KBTYPE( JTYPE ) ).EQ.3 ) THEN
  630. IN = 2*( ( N-1 ) / 2 ) + 1
  631. IF( IN.NE.N )
  632. $ CALL CLASET( 'Full', N, N, CZERO, CZERO, B, LDA )
  633. ELSE
  634. IN = N
  635. END IF
  636. CALL CLATM4( KBTYPE( JTYPE ), IN, KZ1( KBZERO( JTYPE ) ),
  637. $ KZ2( KBZERO( JTYPE ) ), LBSIGN( JTYPE ),
  638. $ RMAGN( KBMAGN( JTYPE ) ), ONE,
  639. $ RMAGN( KTRIAN( JTYPE )*KBMAGN( JTYPE ) ), 2,
  640. $ ISEED, B, LDA )
  641. IADD = KADD( KBZERO( JTYPE ) )
  642. IF( IADD.NE.0 .AND. IADD.LE.N )
  643. $ B( IADD, IADD ) = RMAGN( KBMAGN( JTYPE ) )
  644. *
  645. IF( KCLASS( JTYPE ).EQ.2 .AND. N.GT.0 ) THEN
  646. *
  647. * Include rotations
  648. *
  649. * Generate Q, Z as Householder transformations times
  650. * a diagonal matrix.
  651. *
  652. DO 50 JC = 1, N - 1
  653. DO 40 JR = JC, N
  654. Q( JR, JC ) = CLARND( 3, ISEED )
  655. Z( JR, JC ) = CLARND( 3, ISEED )
  656. 40 CONTINUE
  657. CALL CLARFG( N+1-JC, Q( JC, JC ), Q( JC+1, JC ), 1,
  658. $ WORK( JC ) )
  659. WORK( 2*N+JC ) = SIGN( ONE, REAL( Q( JC, JC ) ) )
  660. Q( JC, JC ) = CONE
  661. CALL CLARFG( N+1-JC, Z( JC, JC ), Z( JC+1, JC ), 1,
  662. $ WORK( N+JC ) )
  663. WORK( 3*N+JC ) = SIGN( ONE, REAL( Z( JC, JC ) ) )
  664. Z( JC, JC ) = CONE
  665. 50 CONTINUE
  666. CTEMP = CLARND( 3, ISEED )
  667. Q( N, N ) = CONE
  668. WORK( N ) = CZERO
  669. WORK( 3*N ) = CTEMP / ABS( CTEMP )
  670. CTEMP = CLARND( 3, ISEED )
  671. Z( N, N ) = CONE
  672. WORK( 2*N ) = CZERO
  673. WORK( 4*N ) = CTEMP / ABS( CTEMP )
  674. *
  675. * Apply the diagonal matrices
  676. *
  677. DO 70 JC = 1, N
  678. DO 60 JR = 1, N
  679. A( JR, JC ) = WORK( 2*N+JR )*
  680. $ CONJG( WORK( 3*N+JC ) )*
  681. $ A( JR, JC )
  682. B( JR, JC ) = WORK( 2*N+JR )*
  683. $ CONJG( WORK( 3*N+JC ) )*
  684. $ B( JR, JC )
  685. 60 CONTINUE
  686. 70 CONTINUE
  687. CALL CUNM2R( 'L', 'N', N, N, N-1, Q, LDQ, WORK, A,
  688. $ LDA, WORK( 2*N+1 ), IINFO )
  689. IF( IINFO.NE.0 )
  690. $ GO TO 100
  691. CALL CUNM2R( 'R', 'C', N, N, N-1, Z, LDQ, WORK( N+1 ),
  692. $ A, LDA, WORK( 2*N+1 ), IINFO )
  693. IF( IINFO.NE.0 )
  694. $ GO TO 100
  695. CALL CUNM2R( 'L', 'N', N, N, N-1, Q, LDQ, WORK, B,
  696. $ LDA, WORK( 2*N+1 ), IINFO )
  697. IF( IINFO.NE.0 )
  698. $ GO TO 100
  699. CALL CUNM2R( 'R', 'C', N, N, N-1, Z, LDQ, WORK( N+1 ),
  700. $ B, LDA, WORK( 2*N+1 ), IINFO )
  701. IF( IINFO.NE.0 )
  702. $ GO TO 100
  703. END IF
  704. ELSE
  705. *
  706. * Random matrices
  707. *
  708. DO 90 JC = 1, N
  709. DO 80 JR = 1, N
  710. A( JR, JC ) = RMAGN( KAMAGN( JTYPE ) )*
  711. $ CLARND( 4, ISEED )
  712. B( JR, JC ) = RMAGN( KBMAGN( JTYPE ) )*
  713. $ CLARND( 4, ISEED )
  714. 80 CONTINUE
  715. 90 CONTINUE
  716. END IF
  717. *
  718. 100 CONTINUE
  719. *
  720. IF( IINFO.NE.0 ) THEN
  721. WRITE( NOUNIT, FMT = 9999 )'Generator', IINFO, N, JTYPE,
  722. $ IOLDSD
  723. INFO = ABS( IINFO )
  724. RETURN
  725. END IF
  726. *
  727. 110 CONTINUE
  728. *
  729. DO 120 I = 1, 13
  730. RESULT( I ) = -ONE
  731. 120 CONTINUE
  732. *
  733. * Test with and without sorting of eigenvalues
  734. *
  735. DO 150 ISORT = 0, 1
  736. IF( ISORT.EQ.0 ) THEN
  737. SORT = 'N'
  738. RSUB = 0
  739. ELSE
  740. SORT = 'S'
  741. RSUB = 5
  742. END IF
  743. *
  744. * Call XLAENV to set the parameters used in CLAQZ0
  745. *
  746. CALL XLAENV( 12, 10 )
  747. CALL XLAENV( 13, 12 )
  748. CALL XLAENV( 14, 13 )
  749. CALL XLAENV( 15, 2 )
  750. CALL XLAENV( 17, 10 )
  751. *
  752. * Call CGGES3 to compute H, T, Q, Z, alpha, and beta.
  753. *
  754. CALL CLACPY( 'Full', N, N, A, LDA, S, LDA )
  755. CALL CLACPY( 'Full', N, N, B, LDA, T, LDA )
  756. NTEST = 1 + RSUB + ISORT
  757. RESULT( 1+RSUB+ISORT ) = ULPINV
  758. CALL CGGES3( 'V', 'V', SORT, CLCTES, N, S, LDA, T, LDA,
  759. $ SDIM, ALPHA, BETA, Q, LDQ, Z, LDQ, WORK,
  760. $ LWORK, RWORK, BWORK, IINFO )
  761. IF( IINFO.NE.0 .AND. IINFO.NE.N+2 ) THEN
  762. RESULT( 1+RSUB+ISORT ) = ULPINV
  763. WRITE( NOUNIT, FMT = 9999 )'CGGES3', IINFO, N, JTYPE,
  764. $ IOLDSD
  765. INFO = ABS( IINFO )
  766. GO TO 160
  767. END IF
  768. *
  769. NTEST = 4 + RSUB
  770. *
  771. * Do tests 1--4 (or tests 7--9 when reordering )
  772. *
  773. IF( ISORT.EQ.0 ) THEN
  774. CALL CGET51( 1, N, A, LDA, S, LDA, Q, LDQ, Z, LDQ,
  775. $ WORK, RWORK, RESULT( 1 ) )
  776. CALL CGET51( 1, N, B, LDA, T, LDA, Q, LDQ, Z, LDQ,
  777. $ WORK, RWORK, RESULT( 2 ) )
  778. ELSE
  779. CALL CGET54( N, A, LDA, B, LDA, S, LDA, T, LDA, Q,
  780. $ LDQ, Z, LDQ, WORK, RESULT( 2+RSUB ) )
  781. END IF
  782. *
  783. CALL CGET51( 3, N, B, LDA, T, LDA, Q, LDQ, Q, LDQ, WORK,
  784. $ RWORK, RESULT( 3+RSUB ) )
  785. CALL CGET51( 3, N, B, LDA, T, LDA, Z, LDQ, Z, LDQ, WORK,
  786. $ RWORK, RESULT( 4+RSUB ) )
  787. *
  788. * Do test 5 and 6 (or Tests 10 and 11 when reordering):
  789. * check Schur form of A and compare eigenvalues with
  790. * diagonals.
  791. *
  792. NTEST = 6 + RSUB
  793. TEMP1 = ZERO
  794. *
  795. DO 130 J = 1, N
  796. ILABAD = .FALSE.
  797. TEMP2 = ( ABS1( ALPHA( J )-S( J, J ) ) /
  798. $ MAX( SAFMIN, ABS1( ALPHA( J ) ), ABS1( S( J,
  799. $ J ) ) )+ABS1( BETA( J )-T( J, J ) ) /
  800. $ MAX( SAFMIN, ABS1( BETA( J ) ), ABS1( T( J,
  801. $ J ) ) ) ) / ULP
  802. *
  803. IF( J.LT.N ) THEN
  804. IF( S( J+1, J ).NE.ZERO ) THEN
  805. ILABAD = .TRUE.
  806. RESULT( 5+RSUB ) = ULPINV
  807. END IF
  808. END IF
  809. IF( J.GT.1 ) THEN
  810. IF( S( J, J-1 ).NE.ZERO ) THEN
  811. ILABAD = .TRUE.
  812. RESULT( 5+RSUB ) = ULPINV
  813. END IF
  814. END IF
  815. TEMP1 = MAX( TEMP1, TEMP2 )
  816. IF( ILABAD ) THEN
  817. WRITE( NOUNIT, FMT = 9998 )J, N, JTYPE, IOLDSD
  818. END IF
  819. 130 CONTINUE
  820. RESULT( 6+RSUB ) = TEMP1
  821. *
  822. IF( ISORT.GE.1 ) THEN
  823. *
  824. * Do test 12
  825. *
  826. NTEST = 12
  827. RESULT( 12 ) = ZERO
  828. KNTEIG = 0
  829. DO 140 I = 1, N
  830. IF( CLCTES( ALPHA( I ), BETA( I ) ) )
  831. $ KNTEIG = KNTEIG + 1
  832. 140 CONTINUE
  833. IF( SDIM.NE.KNTEIG )
  834. $ RESULT( 13 ) = ULPINV
  835. END IF
  836. *
  837. 150 CONTINUE
  838. *
  839. * End of Loop -- Check for RESULT(j) > THRESH
  840. *
  841. 160 CONTINUE
  842. *
  843. NTESTT = NTESTT + NTEST
  844. *
  845. * Print out tests which fail.
  846. *
  847. DO 170 JR = 1, NTEST
  848. IF( RESULT( JR ).GE.THRESH ) THEN
  849. *
  850. * If this is the first test to fail,
  851. * print a header to the data file.
  852. *
  853. IF( NERRS.EQ.0 ) THEN
  854. WRITE( NOUNIT, FMT = 9997 )'CGS'
  855. *
  856. * Matrix types
  857. *
  858. WRITE( NOUNIT, FMT = 9996 )
  859. WRITE( NOUNIT, FMT = 9995 )
  860. WRITE( NOUNIT, FMT = 9994 )'Unitary'
  861. *
  862. * Tests performed
  863. *
  864. WRITE( NOUNIT, FMT = 9993 )'unitary', '''',
  865. $ 'transpose', ( '''', J = 1, 8 )
  866. *
  867. END IF
  868. NERRS = NERRS + 1
  869. IF( RESULT( JR ).LT.10000.0 ) THEN
  870. WRITE( NOUNIT, FMT = 9992 )N, JTYPE, IOLDSD, JR,
  871. $ RESULT( JR )
  872. ELSE
  873. WRITE( NOUNIT, FMT = 9991 )N, JTYPE, IOLDSD, JR,
  874. $ RESULT( JR )
  875. END IF
  876. END IF
  877. 170 CONTINUE
  878. *
  879. 180 CONTINUE
  880. 190 CONTINUE
  881. *
  882. * Summary
  883. *
  884. CALL ALASVM( 'CGS', NOUNIT, NERRS, NTESTT, 0 )
  885. *
  886. WORK( 1 ) = MAXWRK
  887. *
  888. RETURN
  889. *
  890. 9999 FORMAT( ' CDRGES3: ', A, ' returned INFO=', I6, '.', / 9X, 'N=',
  891. $ I6, ', JTYPE=', I6, ', ISEED=(', 4( I4, ',' ), I5, ')' )
  892. *
  893. 9998 FORMAT( ' CDRGES3: S not in Schur form at eigenvalue ', I6, '.',
  894. $ / 9X, 'N=', I6, ', JTYPE=', I6, ', ISEED=(', 3( I5, ',' ),
  895. $ I5, ')' )
  896. *
  897. 9997 FORMAT( / 1X, A3, ' -- Complex Generalized Schur from problem ',
  898. $ 'driver' )
  899. *
  900. 9996 FORMAT( ' Matrix types (see CDRGES3 for details): ' )
  901. *
  902. 9995 FORMAT( ' Special Matrices:', 23X,
  903. $ '(J''=transposed Jordan block)',
  904. $ / ' 1=(0,0) 2=(I,0) 3=(0,I) 4=(I,I) 5=(J'',J'') ',
  905. $ '6=(diag(J'',I), diag(I,J''))', / ' Diagonal Matrices: ( ',
  906. $ 'D=diag(0,1,2,...) )', / ' 7=(D,I) 9=(large*D, small*I',
  907. $ ') 11=(large*I, small*D) 13=(large*D, large*I)', /
  908. $ ' 8=(I,D) 10=(small*D, large*I) 12=(small*I, large*D) ',
  909. $ ' 14=(small*D, small*I)', / ' 15=(D, reversed D)' )
  910. 9994 FORMAT( ' Matrices Rotated by Random ', A, ' Matrices U, V:',
  911. $ / ' 16=Transposed Jordan Blocks 19=geometric ',
  912. $ 'alpha, beta=0,1', / ' 17=arithm. alpha&beta ',
  913. $ ' 20=arithmetic alpha, beta=0,1', / ' 18=clustered ',
  914. $ 'alpha, beta=0,1 21=random alpha, beta=0,1',
  915. $ / ' Large & Small Matrices:', / ' 22=(large, small) ',
  916. $ '23=(small,large) 24=(small,small) 25=(large,large)',
  917. $ / ' 26=random O(1) matrices.' )
  918. *
  919. 9993 FORMAT( / ' Tests performed: (S is Schur, T is triangular, ',
  920. $ 'Q and Z are ', A, ',', / 19X,
  921. $ 'l and r are the appropriate left and right', / 19X,
  922. $ 'eigenvectors, resp., a is alpha, b is beta, and', / 19X, A,
  923. $ ' means ', A, '.)', / ' Without ordering: ',
  924. $ / ' 1 = | A - Q S Z', A,
  925. $ ' | / ( |A| n ulp ) 2 = | B - Q T Z', A,
  926. $ ' | / ( |B| n ulp )', / ' 3 = | I - QQ', A,
  927. $ ' | / ( n ulp ) 4 = | I - ZZ', A,
  928. $ ' | / ( n ulp )', / ' 5 = A is in Schur form S',
  929. $ / ' 6 = difference between (alpha,beta)',
  930. $ ' and diagonals of (S,T)', / ' With ordering: ',
  931. $ / ' 7 = | (A,B) - Q (S,T) Z', A, ' | / ( |(A,B)| n ulp )',
  932. $ / ' 8 = | I - QQ', A,
  933. $ ' | / ( n ulp ) 9 = | I - ZZ', A,
  934. $ ' | / ( n ulp )', / ' 10 = A is in Schur form S',
  935. $ / ' 11 = difference between (alpha,beta) and diagonals',
  936. $ ' of (S,T)', / ' 12 = SDIM is the correct number of ',
  937. $ 'selected eigenvalues', / )
  938. 9992 FORMAT( ' Matrix order=', I5, ', type=', I2, ', seed=',
  939. $ 4( I4, ',' ), ' result ', I2, ' is', 0P, F8.2 )
  940. 9991 FORMAT( ' Matrix order=', I5, ', type=', I2, ', seed=',
  941. $ 4( I4, ',' ), ' result ', I2, ' is', 1P, E10.3 )
  942. *
  943. * End of CDRGES3
  944. *
  945. END