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.

zchkbd.f 33 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  1. *> \brief \b ZCHKBD
  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 ZCHKBD( NSIZES, MVAL, NVAL, NTYPES, DOTYPE, NRHS,
  12. * ISEED, THRESH, A, LDA, BD, BE, S1, S2, X, LDX,
  13. * Y, Z, Q, LDQ, PT, LDPT, U, VT, WORK, LWORK,
  14. * RWORK, NOUT, INFO )
  15. *
  16. * .. Scalar Arguments ..
  17. * INTEGER INFO, LDA, LDPT, LDQ, LDX, LWORK, NOUT, NRHS,
  18. * $ NSIZES, NTYPES
  19. * DOUBLE PRECISION THRESH
  20. * ..
  21. * .. Array Arguments ..
  22. * LOGICAL DOTYPE( * )
  23. * INTEGER ISEED( 4 ), MVAL( * ), NVAL( * )
  24. * DOUBLE PRECISION BD( * ), BE( * ), RWORK( * ), S1( * ), S2( * )
  25. * COMPLEX*16 A( LDA, * ), PT( LDPT, * ), Q( LDQ, * ),
  26. * $ U( LDPT, * ), VT( LDPT, * ), WORK( * ),
  27. * $ X( LDX, * ), Y( LDX, * ), Z( LDX, * )
  28. * ..
  29. *
  30. *
  31. *> \par Purpose:
  32. * =============
  33. *>
  34. *> \verbatim
  35. *>
  36. *> ZCHKBD checks the singular value decomposition (SVD) routines.
  37. *>
  38. *> ZGEBRD reduces a complex general m by n matrix A to real upper or
  39. *> lower bidiagonal form by an orthogonal transformation: Q' * A * P = B
  40. *> (or A = Q * B * P'). The matrix B is upper bidiagonal if m >= n
  41. *> and lower bidiagonal if m < n.
  42. *>
  43. *> ZUNGBR generates the orthogonal matrices Q and P' from ZGEBRD.
  44. *> Note that Q and P are not necessarily square.
  45. *>
  46. *> ZBDSQR computes the singular value decomposition of the bidiagonal
  47. *> matrix B as B = U S V'. It is called three times to compute
  48. *> 1) B = U S1 V', where S1 is the diagonal matrix of singular
  49. *> values and the columns of the matrices U and V are the left
  50. *> and right singular vectors, respectively, of B.
  51. *> 2) Same as 1), but the singular values are stored in S2 and the
  52. *> singular vectors are not computed.
  53. *> 3) A = (UQ) S (P'V'), the SVD of the original matrix A.
  54. *> In addition, ZBDSQR has an option to apply the left orthogonal matrix
  55. *> U to a matrix X, useful in least squares applications.
  56. *>
  57. *> For each pair of matrix dimensions (M,N) and each selected matrix
  58. *> type, an M by N matrix A and an M by NRHS matrix X are generated.
  59. *> The problem dimensions are as follows
  60. *> A: M x N
  61. *> Q: M x min(M,N) (but M x M if NRHS > 0)
  62. *> P: min(M,N) x N
  63. *> B: min(M,N) x min(M,N)
  64. *> U, V: min(M,N) x min(M,N)
  65. *> S1, S2 diagonal, order min(M,N)
  66. *> X: M x NRHS
  67. *>
  68. *> For each generated matrix, 14 tests are performed:
  69. *>
  70. *> Test ZGEBRD and ZUNGBR
  71. *>
  72. *> (1) | A - Q B PT | / ( |A| max(M,N) ulp ), PT = P'
  73. *>
  74. *> (2) | I - Q' Q | / ( M ulp )
  75. *>
  76. *> (3) | I - PT PT' | / ( N ulp )
  77. *>
  78. *> Test ZBDSQR on bidiagonal matrix B
  79. *>
  80. *> (4) | B - U S1 VT | / ( |B| min(M,N) ulp ), VT = V'
  81. *>
  82. *> (5) | Y - U Z | / ( |Y| max(min(M,N),k) ulp ), where Y = Q' X
  83. *> and Z = U' Y.
  84. *> (6) | I - U' U | / ( min(M,N) ulp )
  85. *>
  86. *> (7) | I - VT VT' | / ( min(M,N) ulp )
  87. *>
  88. *> (8) S1 contains min(M,N) nonnegative values in decreasing order.
  89. *> (Return 0 if true, 1/ULP if false.)
  90. *>
  91. *> (9) 0 if the true singular values of B are within THRESH of
  92. *> those in S1. 2*THRESH if they are not. (Tested using
  93. *> DSVDCH)
  94. *>
  95. *> (10) | S1 - S2 | / ( |S1| ulp ), where S2 is computed without
  96. *> computing U and V.
  97. *>
  98. *> Test ZBDSQR on matrix A
  99. *>
  100. *> (11) | A - (QU) S (VT PT) | / ( |A| max(M,N) ulp )
  101. *>
  102. *> (12) | X - (QU) Z | / ( |X| max(M,k) ulp )
  103. *>
  104. *> (13) | I - (QU)'(QU) | / ( M ulp )
  105. *>
  106. *> (14) | I - (VT PT) (PT'VT') | / ( N ulp )
  107. *>
  108. *> The possible matrix types are
  109. *>
  110. *> (1) The zero matrix.
  111. *> (2) The identity matrix.
  112. *>
  113. *> (3) A diagonal matrix with evenly spaced entries
  114. *> 1, ..., ULP and random signs.
  115. *> (ULP = (first number larger than 1) - 1 )
  116. *> (4) A diagonal matrix with geometrically spaced entries
  117. *> 1, ..., ULP and random signs.
  118. *> (5) A diagonal matrix with "clustered" entries 1, ULP, ..., ULP
  119. *> and random signs.
  120. *>
  121. *> (6) Same as (3), but multiplied by SQRT( overflow threshold )
  122. *> (7) Same as (3), but multiplied by SQRT( underflow threshold )
  123. *>
  124. *> (8) A matrix of the form U D V, where U and V are orthogonal and
  125. *> D has evenly spaced entries 1, ..., ULP with random signs
  126. *> on the diagonal.
  127. *>
  128. *> (9) A matrix of the form U D V, where U and V are orthogonal and
  129. *> D has geometrically spaced entries 1, ..., ULP with random
  130. *> signs on the diagonal.
  131. *>
  132. *> (10) A matrix of the form U D V, where U and V are orthogonal and
  133. *> D has "clustered" entries 1, ULP,..., ULP with random
  134. *> signs on the diagonal.
  135. *>
  136. *> (11) Same as (8), but multiplied by SQRT( overflow threshold )
  137. *> (12) Same as (8), but multiplied by SQRT( underflow threshold )
  138. *>
  139. *> (13) Rectangular matrix with random entries chosen from (-1,1).
  140. *> (14) Same as (13), but multiplied by SQRT( overflow threshold )
  141. *> (15) Same as (13), but multiplied by SQRT( underflow threshold )
  142. *>
  143. *> Special case:
  144. *> (16) A bidiagonal matrix with random entries chosen from a
  145. *> logarithmic distribution on [ulp^2,ulp^(-2)] (I.e., each
  146. *> entry is e^x, where x is chosen uniformly on
  147. *> [ 2 log(ulp), -2 log(ulp) ] .) For *this* type:
  148. *> (a) ZGEBRD is not called to reduce it to bidiagonal form.
  149. *> (b) the bidiagonal is min(M,N) x min(M,N); if M<N, the
  150. *> matrix will be lower bidiagonal, otherwise upper.
  151. *> (c) only tests 5--8 and 14 are performed.
  152. *>
  153. *> A subset of the full set of matrix types may be selected through
  154. *> the logical array DOTYPE.
  155. *> \endverbatim
  156. *
  157. * Arguments:
  158. * ==========
  159. *
  160. *> \param[in] NSIZES
  161. *> \verbatim
  162. *> NSIZES is INTEGER
  163. *> The number of values of M and N contained in the vectors
  164. *> MVAL and NVAL. The matrix sizes are used in pairs (M,N).
  165. *> \endverbatim
  166. *>
  167. *> \param[in] MVAL
  168. *> \verbatim
  169. *> MVAL is INTEGER array, dimension (NM)
  170. *> The values of the matrix row dimension M.
  171. *> \endverbatim
  172. *>
  173. *> \param[in] NVAL
  174. *> \verbatim
  175. *> NVAL is INTEGER array, dimension (NM)
  176. *> The values of the matrix column dimension N.
  177. *> \endverbatim
  178. *>
  179. *> \param[in] NTYPES
  180. *> \verbatim
  181. *> NTYPES is INTEGER
  182. *> The number of elements in DOTYPE. If it is zero, ZCHKBD
  183. *> does nothing. It must be at least zero. If it is MAXTYP+1
  184. *> and NSIZES is 1, then an additional type, MAXTYP+1 is
  185. *> defined, which is to use whatever matrices are in A and B.
  186. *> This is only useful if DOTYPE(1:MAXTYP) is .FALSE. and
  187. *> DOTYPE(MAXTYP+1) is .TRUE. .
  188. *> \endverbatim
  189. *>
  190. *> \param[in] DOTYPE
  191. *> \verbatim
  192. *> DOTYPE is LOGICAL array, dimension (NTYPES)
  193. *> If DOTYPE(j) is .TRUE., then for each size (m,n), a matrix
  194. *> of type j will be generated. If NTYPES is smaller than the
  195. *> maximum number of types defined (PARAMETER MAXTYP), then
  196. *> types NTYPES+1 through MAXTYP will not be generated. If
  197. *> NTYPES is larger than MAXTYP, DOTYPE(MAXTYP+1) through
  198. *> DOTYPE(NTYPES) will be ignored.
  199. *> \endverbatim
  200. *>
  201. *> \param[in] NRHS
  202. *> \verbatim
  203. *> NRHS is INTEGER
  204. *> The number of columns in the "right-hand side" matrices X, Y,
  205. *> and Z, used in testing ZBDSQR. If NRHS = 0, then the
  206. *> operations on the right-hand side will not be tested.
  207. *> NRHS must be at least 0.
  208. *> \endverbatim
  209. *>
  210. *> \param[in,out] ISEED
  211. *> \verbatim
  212. *> ISEED is INTEGER array, dimension (4)
  213. *> On entry ISEED specifies the seed of the random number
  214. *> generator. The array elements should be between 0 and 4095;
  215. *> if not they will be reduced mod 4096. Also, ISEED(4) must
  216. *> be odd. The values of ISEED are changed on exit, and can be
  217. *> used in the next call to ZCHKBD to continue the same random
  218. *> number sequence.
  219. *> \endverbatim
  220. *>
  221. *> \param[in] THRESH
  222. *> \verbatim
  223. *> THRESH is DOUBLE PRECISION
  224. *> The threshold value for the test ratios. A result is
  225. *> included in the output file if RESULT >= THRESH. To have
  226. *> every test ratio printed, use THRESH = 0. Note that the
  227. *> expected value of the test ratios is O(1), so THRESH should
  228. *> be a reasonably small multiple of 1, e.g., 10 or 100.
  229. *> \endverbatim
  230. *>
  231. *> \param[out] A
  232. *> \verbatim
  233. *> A is COMPLEX*16 array, dimension (LDA,NMAX)
  234. *> where NMAX is the maximum value of N in NVAL.
  235. *> \endverbatim
  236. *>
  237. *> \param[in] LDA
  238. *> \verbatim
  239. *> LDA is INTEGER
  240. *> The leading dimension of the array A. LDA >= max(1,MMAX),
  241. *> where MMAX is the maximum value of M in MVAL.
  242. *> \endverbatim
  243. *>
  244. *> \param[out] BD
  245. *> \verbatim
  246. *> BD is DOUBLE PRECISION array, dimension
  247. *> (max(min(MVAL(j),NVAL(j))))
  248. *> \endverbatim
  249. *>
  250. *> \param[out] BE
  251. *> \verbatim
  252. *> BE is DOUBLE PRECISION array, dimension
  253. *> (max(min(MVAL(j),NVAL(j))))
  254. *> \endverbatim
  255. *>
  256. *> \param[out] S1
  257. *> \verbatim
  258. *> S1 is DOUBLE PRECISION array, dimension
  259. *> (max(min(MVAL(j),NVAL(j))))
  260. *> \endverbatim
  261. *>
  262. *> \param[out] S2
  263. *> \verbatim
  264. *> S2 is DOUBLE PRECISION array, dimension
  265. *> (max(min(MVAL(j),NVAL(j))))
  266. *> \endverbatim
  267. *>
  268. *> \param[out] X
  269. *> \verbatim
  270. *> X is COMPLEX*16 array, dimension (LDX,NRHS)
  271. *> \endverbatim
  272. *>
  273. *> \param[in] LDX
  274. *> \verbatim
  275. *> LDX is INTEGER
  276. *> The leading dimension of the arrays X, Y, and Z.
  277. *> LDX >= max(1,MMAX).
  278. *> \endverbatim
  279. *>
  280. *> \param[out] Y
  281. *> \verbatim
  282. *> Y is COMPLEX*16 array, dimension (LDX,NRHS)
  283. *> \endverbatim
  284. *>
  285. *> \param[out] Z
  286. *> \verbatim
  287. *> Z is COMPLEX*16 array, dimension (LDX,NRHS)
  288. *> \endverbatim
  289. *>
  290. *> \param[out] Q
  291. *> \verbatim
  292. *> Q is COMPLEX*16 array, dimension (LDQ,MMAX)
  293. *> \endverbatim
  294. *>
  295. *> \param[in] LDQ
  296. *> \verbatim
  297. *> LDQ is INTEGER
  298. *> The leading dimension of the array Q. LDQ >= max(1,MMAX).
  299. *> \endverbatim
  300. *>
  301. *> \param[out] PT
  302. *> \verbatim
  303. *> PT is COMPLEX*16 array, dimension (LDPT,NMAX)
  304. *> \endverbatim
  305. *>
  306. *> \param[in] LDPT
  307. *> \verbatim
  308. *> LDPT is INTEGER
  309. *> The leading dimension of the arrays PT, U, and V.
  310. *> LDPT >= max(1, max(min(MVAL(j),NVAL(j)))).
  311. *> \endverbatim
  312. *>
  313. *> \param[out] U
  314. *> \verbatim
  315. *> U is COMPLEX*16 array, dimension
  316. *> (LDPT,max(min(MVAL(j),NVAL(j))))
  317. *> \endverbatim
  318. *>
  319. *> \param[out] VT
  320. *> \verbatim
  321. *> VT is COMPLEX*16 array, dimension
  322. *> (LDPT,max(min(MVAL(j),NVAL(j))))
  323. *> \endverbatim
  324. *>
  325. *> \param[out] WORK
  326. *> \verbatim
  327. *> WORK is COMPLEX*16 array, dimension (LWORK)
  328. *> \endverbatim
  329. *>
  330. *> \param[in] LWORK
  331. *> \verbatim
  332. *> LWORK is INTEGER
  333. *> The number of entries in WORK. This must be at least
  334. *> 3(M+N) and M(M + max(M,N,k) + 1) + N*min(M,N) for all
  335. *> pairs (M,N)=(MM(j),NN(j))
  336. *> \endverbatim
  337. *>
  338. *> \param[out] RWORK
  339. *> \verbatim
  340. *> RWORK is DOUBLE PRECISION array, dimension
  341. *> (5*max(min(M,N)))
  342. *> \endverbatim
  343. *>
  344. *> \param[in] NOUT
  345. *> \verbatim
  346. *> NOUT is INTEGER
  347. *> The FORTRAN unit number for printing out error messages
  348. *> (e.g., if a routine returns IINFO not equal to 0.)
  349. *> \endverbatim
  350. *>
  351. *> \param[out] INFO
  352. *> \verbatim
  353. *> INFO is INTEGER
  354. *> If 0, then everything ran OK.
  355. *> -1: NSIZES < 0
  356. *> -2: Some MM(j) < 0
  357. *> -3: Some NN(j) < 0
  358. *> -4: NTYPES < 0
  359. *> -6: NRHS < 0
  360. *> -8: THRESH < 0
  361. *> -11: LDA < 1 or LDA < MMAX, where MMAX is max( MM(j) ).
  362. *> -17: LDB < 1 or LDB < MMAX.
  363. *> -21: LDQ < 1 or LDQ < MMAX.
  364. *> -23: LDP < 1 or LDP < MNMAX.
  365. *> -27: LWORK too small.
  366. *> If ZLATMR, CLATMS, ZGEBRD, ZUNGBR, or ZBDSQR,
  367. *> returns an error code, the
  368. *> absolute value of it is returned.
  369. *>
  370. *>-----------------------------------------------------------------------
  371. *>
  372. *> Some Local Variables and Parameters:
  373. *> ---- ----- --------- --- ----------
  374. *>
  375. *> ZERO, ONE Real 0 and 1.
  376. *> MAXTYP The number of types defined.
  377. *> NTEST The number of tests performed, or which can
  378. *> be performed so far, for the current matrix.
  379. *> MMAX Largest value in NN.
  380. *> NMAX Largest value in NN.
  381. *> MNMIN min(MM(j), NN(j)) (the dimension of the bidiagonal
  382. *> matrix.)
  383. *> MNMAX The maximum value of MNMIN for j=1,...,NSIZES.
  384. *> NFAIL The number of tests which have exceeded THRESH
  385. *> COND, IMODE Values to be passed to the matrix generators.
  386. *> ANORM Norm of A; passed to matrix generators.
  387. *>
  388. *> OVFL, UNFL Overflow and underflow thresholds.
  389. *> RTOVFL, RTUNFL Square roots of the previous 2 values.
  390. *> ULP, ULPINV Finest relative precision and its inverse.
  391. *>
  392. *> The following four arrays decode JTYPE:
  393. *> KTYPE(j) The general type (1-10) for type "j".
  394. *> KMODE(j) The MODE value to be passed to the matrix
  395. *> generator for type "j".
  396. *> KMAGN(j) The order of magnitude ( O(1),
  397. *> O(overflow^(1/2) ), O(underflow^(1/2) )
  398. *> \endverbatim
  399. *
  400. * Authors:
  401. * ========
  402. *
  403. *> \author Univ. of Tennessee
  404. *> \author Univ. of California Berkeley
  405. *> \author Univ. of Colorado Denver
  406. *> \author NAG Ltd.
  407. *
  408. *> \date June 2016
  409. *
  410. *> \ingroup complex16_eig
  411. *
  412. * =====================================================================
  413. SUBROUTINE ZCHKBD( NSIZES, MVAL, NVAL, NTYPES, DOTYPE, NRHS,
  414. $ ISEED, THRESH, A, LDA, BD, BE, S1, S2, X, LDX,
  415. $ Y, Z, Q, LDQ, PT, LDPT, U, VT, WORK, LWORK,
  416. $ RWORK, NOUT, INFO )
  417. *
  418. * -- LAPACK test routine (version 3.7.0) --
  419. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  420. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  421. * June 2016
  422. *
  423. * .. Scalar Arguments ..
  424. INTEGER INFO, LDA, LDPT, LDQ, LDX, LWORK, NOUT, NRHS,
  425. $ NSIZES, NTYPES
  426. DOUBLE PRECISION THRESH
  427. * ..
  428. * .. Array Arguments ..
  429. LOGICAL DOTYPE( * )
  430. INTEGER ISEED( 4 ), MVAL( * ), NVAL( * )
  431. DOUBLE PRECISION BD( * ), BE( * ), RWORK( * ), S1( * ), S2( * )
  432. COMPLEX*16 A( LDA, * ), PT( LDPT, * ), Q( LDQ, * ),
  433. $ U( LDPT, * ), VT( LDPT, * ), WORK( * ),
  434. $ X( LDX, * ), Y( LDX, * ), Z( LDX, * )
  435. * ..
  436. *
  437. * ======================================================================
  438. *
  439. * .. Parameters ..
  440. DOUBLE PRECISION ZERO, ONE, TWO, HALF
  441. PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0,
  442. $ HALF = 0.5D0 )
  443. COMPLEX*16 CZERO, CONE
  444. PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ),
  445. $ CONE = ( 1.0D+0, 0.0D+0 ) )
  446. INTEGER MAXTYP
  447. PARAMETER ( MAXTYP = 16 )
  448. * ..
  449. * .. Local Scalars ..
  450. LOGICAL BADMM, BADNN, BIDIAG
  451. CHARACTER UPLO
  452. CHARACTER*3 PATH
  453. INTEGER I, IINFO, IMODE, ITYPE, J, JCOL, JSIZE, JTYPE,
  454. $ LOG2UI, M, MINWRK, MMAX, MNMAX, MNMIN, MQ,
  455. $ MTYPES, N, NFAIL, NMAX, NTEST
  456. DOUBLE PRECISION AMNINV, ANORM, COND, OVFL, RTOVFL, RTUNFL,
  457. $ TEMP1, TEMP2, ULP, ULPINV, UNFL
  458. * ..
  459. * .. Local Arrays ..
  460. INTEGER IOLDSD( 4 ), IWORK( 1 ), KMAGN( MAXTYP ),
  461. $ KMODE( MAXTYP ), KTYPE( MAXTYP )
  462. DOUBLE PRECISION DUMMA( 1 ), RESULT( 14 )
  463. * ..
  464. * .. External Functions ..
  465. DOUBLE PRECISION DLAMCH, DLARND
  466. EXTERNAL DLAMCH, DLARND
  467. * ..
  468. * .. External Subroutines ..
  469. EXTERNAL ALASUM, DCOPY, DLABAD, DLAHD2, DSVDCH, XERBLA,
  470. $ ZBDSQR, ZBDT01, ZBDT02, ZBDT03, ZGEBRD, ZGEMM,
  471. $ ZLACPY, ZLASET, ZLATMR, ZLATMS, ZUNGBR, ZUNT01
  472. * ..
  473. * .. Intrinsic Functions ..
  474. INTRINSIC ABS, EXP, INT, LOG, MAX, MIN, SQRT
  475. * ..
  476. * .. Scalars in Common ..
  477. LOGICAL LERR, OK
  478. CHARACTER*32 SRNAMT
  479. INTEGER INFOT, NUNIT
  480. * ..
  481. * .. Common blocks ..
  482. COMMON / INFOC / INFOT, NUNIT, OK, LERR
  483. COMMON / SRNAMC / SRNAMT
  484. * ..
  485. * .. Data statements ..
  486. DATA KTYPE / 1, 2, 5*4, 5*6, 3*9, 10 /
  487. DATA KMAGN / 2*1, 3*1, 2, 3, 3*1, 2, 3, 1, 2, 3, 0 /
  488. DATA KMODE / 2*0, 4, 3, 1, 4, 4, 4, 3, 1, 4, 4, 0,
  489. $ 0, 0, 0 /
  490. * ..
  491. * .. Executable Statements ..
  492. *
  493. * Check for errors
  494. *
  495. INFO = 0
  496. *
  497. BADMM = .FALSE.
  498. BADNN = .FALSE.
  499. MMAX = 1
  500. NMAX = 1
  501. MNMAX = 1
  502. MINWRK = 1
  503. DO 10 J = 1, NSIZES
  504. MMAX = MAX( MMAX, MVAL( J ) )
  505. IF( MVAL( J ).LT.0 )
  506. $ BADMM = .TRUE.
  507. NMAX = MAX( NMAX, NVAL( J ) )
  508. IF( NVAL( J ).LT.0 )
  509. $ BADNN = .TRUE.
  510. MNMAX = MAX( MNMAX, MIN( MVAL( J ), NVAL( J ) ) )
  511. MINWRK = MAX( MINWRK, 3*( MVAL( J )+NVAL( J ) ),
  512. $ MVAL( J )*( MVAL( J )+MAX( MVAL( J ), NVAL( J ),
  513. $ NRHS )+1 )+NVAL( J )*MIN( NVAL( J ), MVAL( J ) ) )
  514. 10 CONTINUE
  515. *
  516. * Check for errors
  517. *
  518. IF( NSIZES.LT.0 ) THEN
  519. INFO = -1
  520. ELSE IF( BADMM ) THEN
  521. INFO = -2
  522. ELSE IF( BADNN ) THEN
  523. INFO = -3
  524. ELSE IF( NTYPES.LT.0 ) THEN
  525. INFO = -4
  526. ELSE IF( NRHS.LT.0 ) THEN
  527. INFO = -6
  528. ELSE IF( LDA.LT.MMAX ) THEN
  529. INFO = -11
  530. ELSE IF( LDX.LT.MMAX ) THEN
  531. INFO = -17
  532. ELSE IF( LDQ.LT.MMAX ) THEN
  533. INFO = -21
  534. ELSE IF( LDPT.LT.MNMAX ) THEN
  535. INFO = -23
  536. ELSE IF( MINWRK.GT.LWORK ) THEN
  537. INFO = -27
  538. END IF
  539. *
  540. IF( INFO.NE.0 ) THEN
  541. CALL XERBLA( 'ZCHKBD', -INFO )
  542. RETURN
  543. END IF
  544. *
  545. * Initialize constants
  546. *
  547. PATH( 1: 1 ) = 'Zomplex precision'
  548. PATH( 2: 3 ) = 'BD'
  549. NFAIL = 0
  550. NTEST = 0
  551. UNFL = DLAMCH( 'Safe minimum' )
  552. OVFL = DLAMCH( 'Overflow' )
  553. CALL DLABAD( UNFL, OVFL )
  554. ULP = DLAMCH( 'Precision' )
  555. ULPINV = ONE / ULP
  556. LOG2UI = INT( LOG( ULPINV ) / LOG( TWO ) )
  557. RTUNFL = SQRT( UNFL )
  558. RTOVFL = SQRT( OVFL )
  559. INFOT = 0
  560. *
  561. * Loop over sizes, types
  562. *
  563. DO 180 JSIZE = 1, NSIZES
  564. M = MVAL( JSIZE )
  565. N = NVAL( JSIZE )
  566. MNMIN = MIN( M, N )
  567. AMNINV = ONE / MAX( M, N, 1 )
  568. *
  569. IF( NSIZES.NE.1 ) THEN
  570. MTYPES = MIN( MAXTYP, NTYPES )
  571. ELSE
  572. MTYPES = MIN( MAXTYP+1, NTYPES )
  573. END IF
  574. *
  575. DO 170 JTYPE = 1, MTYPES
  576. IF( .NOT.DOTYPE( JTYPE ) )
  577. $ GO TO 170
  578. *
  579. DO 20 J = 1, 4
  580. IOLDSD( J ) = ISEED( J )
  581. 20 CONTINUE
  582. *
  583. DO 30 J = 1, 14
  584. RESULT( J ) = -ONE
  585. 30 CONTINUE
  586. *
  587. UPLO = ' '
  588. *
  589. * Compute "A"
  590. *
  591. * Control parameters:
  592. *
  593. * KMAGN KMODE KTYPE
  594. * =1 O(1) clustered 1 zero
  595. * =2 large clustered 2 identity
  596. * =3 small exponential (none)
  597. * =4 arithmetic diagonal, (w/ eigenvalues)
  598. * =5 random symmetric, w/ eigenvalues
  599. * =6 nonsymmetric, w/ singular values
  600. * =7 random diagonal
  601. * =8 random symmetric
  602. * =9 random nonsymmetric
  603. * =10 random bidiagonal (log. distrib.)
  604. *
  605. IF( MTYPES.GT.MAXTYP )
  606. $ GO TO 100
  607. *
  608. ITYPE = KTYPE( JTYPE )
  609. IMODE = KMODE( JTYPE )
  610. *
  611. * Compute norm
  612. *
  613. GO TO ( 40, 50, 60 )KMAGN( JTYPE )
  614. *
  615. 40 CONTINUE
  616. ANORM = ONE
  617. GO TO 70
  618. *
  619. 50 CONTINUE
  620. ANORM = ( RTOVFL*ULP )*AMNINV
  621. GO TO 70
  622. *
  623. 60 CONTINUE
  624. ANORM = RTUNFL*MAX( M, N )*ULPINV
  625. GO TO 70
  626. *
  627. 70 CONTINUE
  628. *
  629. CALL ZLASET( 'Full', LDA, N, CZERO, CZERO, A, LDA )
  630. IINFO = 0
  631. COND = ULPINV
  632. *
  633. BIDIAG = .FALSE.
  634. IF( ITYPE.EQ.1 ) THEN
  635. *
  636. * Zero matrix
  637. *
  638. IINFO = 0
  639. *
  640. ELSE IF( ITYPE.EQ.2 ) THEN
  641. *
  642. * Identity
  643. *
  644. DO 80 JCOL = 1, MNMIN
  645. A( JCOL, JCOL ) = ANORM
  646. 80 CONTINUE
  647. *
  648. ELSE IF( ITYPE.EQ.4 ) THEN
  649. *
  650. * Diagonal Matrix, [Eigen]values Specified
  651. *
  652. CALL ZLATMS( MNMIN, MNMIN, 'S', ISEED, 'N', RWORK, IMODE,
  653. $ COND, ANORM, 0, 0, 'N', A, LDA, WORK,
  654. $ IINFO )
  655. *
  656. ELSE IF( ITYPE.EQ.5 ) THEN
  657. *
  658. * Symmetric, eigenvalues specified
  659. *
  660. CALL ZLATMS( MNMIN, MNMIN, 'S', ISEED, 'S', RWORK, IMODE,
  661. $ COND, ANORM, M, N, 'N', A, LDA, WORK,
  662. $ IINFO )
  663. *
  664. ELSE IF( ITYPE.EQ.6 ) THEN
  665. *
  666. * Nonsymmetric, singular values specified
  667. *
  668. CALL ZLATMS( M, N, 'S', ISEED, 'N', RWORK, IMODE, COND,
  669. $ ANORM, M, N, 'N', A, LDA, WORK, IINFO )
  670. *
  671. ELSE IF( ITYPE.EQ.7 ) THEN
  672. *
  673. * Diagonal, random entries
  674. *
  675. CALL ZLATMR( MNMIN, MNMIN, 'S', ISEED, 'N', WORK, 6, ONE,
  676. $ CONE, 'T', 'N', WORK( MNMIN+1 ), 1, ONE,
  677. $ WORK( 2*MNMIN+1 ), 1, ONE, 'N', IWORK, 0, 0,
  678. $ ZERO, ANORM, 'NO', A, LDA, IWORK, IINFO )
  679. *
  680. ELSE IF( ITYPE.EQ.8 ) THEN
  681. *
  682. * Symmetric, random entries
  683. *
  684. CALL ZLATMR( MNMIN, MNMIN, 'S', ISEED, 'S', WORK, 6, ONE,
  685. $ CONE, 'T', 'N', WORK( MNMIN+1 ), 1, ONE,
  686. $ WORK( M+MNMIN+1 ), 1, ONE, 'N', IWORK, M, N,
  687. $ ZERO, ANORM, 'NO', A, LDA, IWORK, IINFO )
  688. *
  689. ELSE IF( ITYPE.EQ.9 ) THEN
  690. *
  691. * Nonsymmetric, random entries
  692. *
  693. CALL ZLATMR( M, N, 'S', ISEED, 'N', WORK, 6, ONE, CONE,
  694. $ 'T', 'N', WORK( MNMIN+1 ), 1, ONE,
  695. $ WORK( M+MNMIN+1 ), 1, ONE, 'N', IWORK, M, N,
  696. $ ZERO, ANORM, 'NO', A, LDA, IWORK, IINFO )
  697. *
  698. ELSE IF( ITYPE.EQ.10 ) THEN
  699. *
  700. * Bidiagonal, random entries
  701. *
  702. TEMP1 = -TWO*LOG( ULP )
  703. DO 90 J = 1, MNMIN
  704. BD( J ) = EXP( TEMP1*DLARND( 2, ISEED ) )
  705. IF( J.LT.MNMIN )
  706. $ BE( J ) = EXP( TEMP1*DLARND( 2, ISEED ) )
  707. 90 CONTINUE
  708. *
  709. IINFO = 0
  710. BIDIAG = .TRUE.
  711. IF( M.GE.N ) THEN
  712. UPLO = 'U'
  713. ELSE
  714. UPLO = 'L'
  715. END IF
  716. ELSE
  717. IINFO = 1
  718. END IF
  719. *
  720. IF( IINFO.EQ.0 ) THEN
  721. *
  722. * Generate Right-Hand Side
  723. *
  724. IF( BIDIAG ) THEN
  725. CALL ZLATMR( MNMIN, NRHS, 'S', ISEED, 'N', WORK, 6,
  726. $ ONE, CONE, 'T', 'N', WORK( MNMIN+1 ), 1,
  727. $ ONE, WORK( 2*MNMIN+1 ), 1, ONE, 'N',
  728. $ IWORK, MNMIN, NRHS, ZERO, ONE, 'NO', Y,
  729. $ LDX, IWORK, IINFO )
  730. ELSE
  731. CALL ZLATMR( M, NRHS, 'S', ISEED, 'N', WORK, 6, ONE,
  732. $ CONE, 'T', 'N', WORK( M+1 ), 1, ONE,
  733. $ WORK( 2*M+1 ), 1, ONE, 'N', IWORK, M,
  734. $ NRHS, ZERO, ONE, 'NO', X, LDX, IWORK,
  735. $ IINFO )
  736. END IF
  737. END IF
  738. *
  739. * Error Exit
  740. *
  741. IF( IINFO.NE.0 ) THEN
  742. WRITE( NOUT, FMT = 9998 )'Generator', IINFO, M, N,
  743. $ JTYPE, IOLDSD
  744. INFO = ABS( IINFO )
  745. RETURN
  746. END IF
  747. *
  748. 100 CONTINUE
  749. *
  750. * Call ZGEBRD and ZUNGBR to compute B, Q, and P, do tests.
  751. *
  752. IF( .NOT.BIDIAG ) THEN
  753. *
  754. * Compute transformations to reduce A to bidiagonal form:
  755. * B := Q' * A * P.
  756. *
  757. CALL ZLACPY( ' ', M, N, A, LDA, Q, LDQ )
  758. CALL ZGEBRD( M, N, Q, LDQ, BD, BE, WORK, WORK( MNMIN+1 ),
  759. $ WORK( 2*MNMIN+1 ), LWORK-2*MNMIN, IINFO )
  760. *
  761. * Check error code from ZGEBRD.
  762. *
  763. IF( IINFO.NE.0 ) THEN
  764. WRITE( NOUT, FMT = 9998 )'ZGEBRD', IINFO, M, N,
  765. $ JTYPE, IOLDSD
  766. INFO = ABS( IINFO )
  767. RETURN
  768. END IF
  769. *
  770. CALL ZLACPY( ' ', M, N, Q, LDQ, PT, LDPT )
  771. IF( M.GE.N ) THEN
  772. UPLO = 'U'
  773. ELSE
  774. UPLO = 'L'
  775. END IF
  776. *
  777. * Generate Q
  778. *
  779. MQ = M
  780. IF( NRHS.LE.0 )
  781. $ MQ = MNMIN
  782. CALL ZUNGBR( 'Q', M, MQ, N, Q, LDQ, WORK,
  783. $ WORK( 2*MNMIN+1 ), LWORK-2*MNMIN, IINFO )
  784. *
  785. * Check error code from ZUNGBR.
  786. *
  787. IF( IINFO.NE.0 ) THEN
  788. WRITE( NOUT, FMT = 9998 )'ZUNGBR(Q)', IINFO, M, N,
  789. $ JTYPE, IOLDSD
  790. INFO = ABS( IINFO )
  791. RETURN
  792. END IF
  793. *
  794. * Generate P'
  795. *
  796. CALL ZUNGBR( 'P', MNMIN, N, M, PT, LDPT, WORK( MNMIN+1 ),
  797. $ WORK( 2*MNMIN+1 ), LWORK-2*MNMIN, IINFO )
  798. *
  799. * Check error code from ZUNGBR.
  800. *
  801. IF( IINFO.NE.0 ) THEN
  802. WRITE( NOUT, FMT = 9998 )'ZUNGBR(P)', IINFO, M, N,
  803. $ JTYPE, IOLDSD
  804. INFO = ABS( IINFO )
  805. RETURN
  806. END IF
  807. *
  808. * Apply Q' to an M by NRHS matrix X: Y := Q' * X.
  809. *
  810. CALL ZGEMM( 'Conjugate transpose', 'No transpose', M,
  811. $ NRHS, M, CONE, Q, LDQ, X, LDX, CZERO, Y,
  812. $ LDX )
  813. *
  814. * Test 1: Check the decomposition A := Q * B * PT
  815. * 2: Check the orthogonality of Q
  816. * 3: Check the orthogonality of PT
  817. *
  818. CALL ZBDT01( M, N, 1, A, LDA, Q, LDQ, BD, BE, PT, LDPT,
  819. $ WORK, RWORK, RESULT( 1 ) )
  820. CALL ZUNT01( 'Columns', M, MQ, Q, LDQ, WORK, LWORK,
  821. $ RWORK, RESULT( 2 ) )
  822. CALL ZUNT01( 'Rows', MNMIN, N, PT, LDPT, WORK, LWORK,
  823. $ RWORK, RESULT( 3 ) )
  824. END IF
  825. *
  826. * Use ZBDSQR to form the SVD of the bidiagonal matrix B:
  827. * B := U * S1 * VT, and compute Z = U' * Y.
  828. *
  829. CALL DCOPY( MNMIN, BD, 1, S1, 1 )
  830. IF( MNMIN.GT.0 )
  831. $ CALL DCOPY( MNMIN-1, BE, 1, RWORK, 1 )
  832. CALL ZLACPY( ' ', M, NRHS, Y, LDX, Z, LDX )
  833. CALL ZLASET( 'Full', MNMIN, MNMIN, CZERO, CONE, U, LDPT )
  834. CALL ZLASET( 'Full', MNMIN, MNMIN, CZERO, CONE, VT, LDPT )
  835. *
  836. CALL ZBDSQR( UPLO, MNMIN, MNMIN, MNMIN, NRHS, S1, RWORK, VT,
  837. $ LDPT, U, LDPT, Z, LDX, RWORK( MNMIN+1 ),
  838. $ IINFO )
  839. *
  840. * Check error code from ZBDSQR.
  841. *
  842. IF( IINFO.NE.0 ) THEN
  843. WRITE( NOUT, FMT = 9998 )'ZBDSQR(vects)', IINFO, M, N,
  844. $ JTYPE, IOLDSD
  845. INFO = ABS( IINFO )
  846. IF( IINFO.LT.0 ) THEN
  847. RETURN
  848. ELSE
  849. RESULT( 4 ) = ULPINV
  850. GO TO 150
  851. END IF
  852. END IF
  853. *
  854. * Use ZBDSQR to compute only the singular values of the
  855. * bidiagonal matrix B; U, VT, and Z should not be modified.
  856. *
  857. CALL DCOPY( MNMIN, BD, 1, S2, 1 )
  858. IF( MNMIN.GT.0 )
  859. $ CALL DCOPY( MNMIN-1, BE, 1, RWORK, 1 )
  860. *
  861. CALL ZBDSQR( UPLO, MNMIN, 0, 0, 0, S2, RWORK, VT, LDPT, U,
  862. $ LDPT, Z, LDX, RWORK( MNMIN+1 ), IINFO )
  863. *
  864. * Check error code from ZBDSQR.
  865. *
  866. IF( IINFO.NE.0 ) THEN
  867. WRITE( NOUT, FMT = 9998 )'ZBDSQR(values)', IINFO, M, N,
  868. $ JTYPE, IOLDSD
  869. INFO = ABS( IINFO )
  870. IF( IINFO.LT.0 ) THEN
  871. RETURN
  872. ELSE
  873. RESULT( 9 ) = ULPINV
  874. GO TO 150
  875. END IF
  876. END IF
  877. *
  878. * Test 4: Check the decomposition B := U * S1 * VT
  879. * 5: Check the computation Z := U' * Y
  880. * 6: Check the orthogonality of U
  881. * 7: Check the orthogonality of VT
  882. *
  883. CALL ZBDT03( UPLO, MNMIN, 1, BD, BE, U, LDPT, S1, VT, LDPT,
  884. $ WORK, RESULT( 4 ) )
  885. CALL ZBDT02( MNMIN, NRHS, Y, LDX, Z, LDX, U, LDPT, WORK,
  886. $ RWORK, RESULT( 5 ) )
  887. CALL ZUNT01( 'Columns', MNMIN, MNMIN, U, LDPT, WORK, LWORK,
  888. $ RWORK, RESULT( 6 ) )
  889. CALL ZUNT01( 'Rows', MNMIN, MNMIN, VT, LDPT, WORK, LWORK,
  890. $ RWORK, RESULT( 7 ) )
  891. *
  892. * Test 8: Check that the singular values are sorted in
  893. * non-increasing order and are non-negative
  894. *
  895. RESULT( 8 ) = ZERO
  896. DO 110 I = 1, MNMIN - 1
  897. IF( S1( I ).LT.S1( I+1 ) )
  898. $ RESULT( 8 ) = ULPINV
  899. IF( S1( I ).LT.ZERO )
  900. $ RESULT( 8 ) = ULPINV
  901. 110 CONTINUE
  902. IF( MNMIN.GE.1 ) THEN
  903. IF( S1( MNMIN ).LT.ZERO )
  904. $ RESULT( 8 ) = ULPINV
  905. END IF
  906. *
  907. * Test 9: Compare ZBDSQR with and without singular vectors
  908. *
  909. TEMP2 = ZERO
  910. *
  911. DO 120 J = 1, MNMIN
  912. TEMP1 = ABS( S1( J )-S2( J ) ) /
  913. $ MAX( SQRT( UNFL )*MAX( S1( 1 ), ONE ),
  914. $ ULP*MAX( ABS( S1( J ) ), ABS( S2( J ) ) ) )
  915. TEMP2 = MAX( TEMP1, TEMP2 )
  916. 120 CONTINUE
  917. *
  918. RESULT( 9 ) = TEMP2
  919. *
  920. * Test 10: Sturm sequence test of singular values
  921. * Go up by factors of two until it succeeds
  922. *
  923. TEMP1 = THRESH*( HALF-ULP )
  924. *
  925. DO 130 J = 0, LOG2UI
  926. CALL DSVDCH( MNMIN, BD, BE, S1, TEMP1, IINFO )
  927. IF( IINFO.EQ.0 )
  928. $ GO TO 140
  929. TEMP1 = TEMP1*TWO
  930. 130 CONTINUE
  931. *
  932. 140 CONTINUE
  933. RESULT( 10 ) = TEMP1
  934. *
  935. * Use ZBDSQR to form the decomposition A := (QU) S (VT PT)
  936. * from the bidiagonal form A := Q B PT.
  937. *
  938. IF( .NOT.BIDIAG ) THEN
  939. CALL DCOPY( MNMIN, BD, 1, S2, 1 )
  940. IF( MNMIN.GT.0 )
  941. $ CALL DCOPY( MNMIN-1, BE, 1, RWORK, 1 )
  942. *
  943. CALL ZBDSQR( UPLO, MNMIN, N, M, NRHS, S2, RWORK, PT,
  944. $ LDPT, Q, LDQ, Y, LDX, RWORK( MNMIN+1 ),
  945. $ IINFO )
  946. *
  947. * Test 11: Check the decomposition A := Q*U * S2 * VT*PT
  948. * 12: Check the computation Z := U' * Q' * X
  949. * 13: Check the orthogonality of Q*U
  950. * 14: Check the orthogonality of VT*PT
  951. *
  952. CALL ZBDT01( M, N, 0, A, LDA, Q, LDQ, S2, DUMMA, PT,
  953. $ LDPT, WORK, RWORK, RESULT( 11 ) )
  954. CALL ZBDT02( M, NRHS, X, LDX, Y, LDX, Q, LDQ, WORK,
  955. $ RWORK, RESULT( 12 ) )
  956. CALL ZUNT01( 'Columns', M, MQ, Q, LDQ, WORK, LWORK,
  957. $ RWORK, RESULT( 13 ) )
  958. CALL ZUNT01( 'Rows', MNMIN, N, PT, LDPT, WORK, LWORK,
  959. $ RWORK, RESULT( 14 ) )
  960. END IF
  961. *
  962. * End of Loop -- Check for RESULT(j) > THRESH
  963. *
  964. 150 CONTINUE
  965. DO 160 J = 1, 14
  966. IF( RESULT( J ).GE.THRESH ) THEN
  967. IF( NFAIL.EQ.0 )
  968. $ CALL DLAHD2( NOUT, PATH )
  969. WRITE( NOUT, FMT = 9999 )M, N, JTYPE, IOLDSD, J,
  970. $ RESULT( J )
  971. NFAIL = NFAIL + 1
  972. END IF
  973. 160 CONTINUE
  974. IF( .NOT.BIDIAG ) THEN
  975. NTEST = NTEST + 14
  976. ELSE
  977. NTEST = NTEST + 5
  978. END IF
  979. *
  980. 170 CONTINUE
  981. 180 CONTINUE
  982. *
  983. * Summary
  984. *
  985. CALL ALASUM( PATH, NOUT, NFAIL, NTEST, 0 )
  986. *
  987. RETURN
  988. *
  989. * End of ZCHKBD
  990. *
  991. 9999 FORMAT( ' M=', I5, ', N=', I5, ', type ', I2, ', seed=',
  992. $ 4( I4, ',' ), ' test(', I2, ')=', G11.4 )
  993. 9998 FORMAT( ' ZCHKBD: ', A, ' returned INFO=', I6, '.', / 9X, 'M=',
  994. $ I6, ', N=', I6, ', JTYPE=', I6, ', ISEED=(', 3( I5, ',' ),
  995. $ I5, ')' )
  996. *
  997. END