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.

zlatme.c 30 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/Cd(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. #define z_abs(z) (cabs(Cd(z)))
  229. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  230. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  231. #define myexit_() break;
  232. #define mycycle_() continue;
  233. #define myceiling_(w) {ceil(w)}
  234. #define myhuge_(w) {HUGE_VAL}
  235. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  236. #define mymaxloc_(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  237. /* procedure parameter types for -A and -C++ */
  238. /* Table of constant values */
  239. static doublecomplex c_b1 = {0.,0.};
  240. static doublecomplex c_b2 = {1.,0.};
  241. static integer c__1 = 1;
  242. static integer c__0 = 0;
  243. static integer c__5 = 5;
  244. /* > \brief \b ZLATME */
  245. /* =========== DOCUMENTATION =========== */
  246. /* Online html documentation available at */
  247. /* http://www.netlib.org/lapack/explore-html/ */
  248. /* Definition: */
  249. /* =========== */
  250. /* SUBROUTINE ZLATME( N, DIST, ISEED, D, MODE, COND, DMAX, */
  251. /* RSIGN, */
  252. /* UPPER, SIM, DS, MODES, CONDS, KL, KU, ANORM, */
  253. /* A, */
  254. /* LDA, WORK, INFO ) */
  255. /* CHARACTER DIST, RSIGN, SIM, UPPER */
  256. /* INTEGER INFO, KL, KU, LDA, MODE, MODES, N */
  257. /* DOUBLE PRECISION ANORM, COND, CONDS */
  258. /* COMPLEX*16 DMAX */
  259. /* INTEGER ISEED( 4 ) */
  260. /* DOUBLE PRECISION DS( * ) */
  261. /* COMPLEX*16 A( LDA, * ), D( * ), WORK( * ) */
  262. /* > \par Purpose: */
  263. /* ============= */
  264. /* > */
  265. /* > \verbatim */
  266. /* > */
  267. /* > ZLATME generates random non-symmetric square matrices with */
  268. /* > specified eigenvalues for testing LAPACK programs. */
  269. /* > */
  270. /* > ZLATME operates by applying the following sequence of */
  271. /* > operations: */
  272. /* > */
  273. /* > 1. Set the diagonal to D, where D may be input or */
  274. /* > computed according to MODE, COND, DMAX, and RSIGN */
  275. /* > as described below. */
  276. /* > */
  277. /* > 2. If UPPER='T', the upper triangle of A is set to random values */
  278. /* > out of distribution DIST. */
  279. /* > */
  280. /* > 3. If SIM='T', A is multiplied on the left by a random matrix */
  281. /* > X, whose singular values are specified by DS, MODES, and */
  282. /* > CONDS, and on the right by X inverse. */
  283. /* > */
  284. /* > 4. If KL < N-1, the lower bandwidth is reduced to KL using */
  285. /* > Householder transformations. If KU < N-1, the upper */
  286. /* > bandwidth is reduced to KU. */
  287. /* > */
  288. /* > 5. If ANORM is not negative, the matrix is scaled to have */
  289. /* > maximum-element-norm ANORM. */
  290. /* > */
  291. /* > (Note: since the matrix cannot be reduced beyond Hessenberg form, */
  292. /* > no packing options are available.) */
  293. /* > \endverbatim */
  294. /* Arguments: */
  295. /* ========== */
  296. /* > \param[in] N */
  297. /* > \verbatim */
  298. /* > N is INTEGER */
  299. /* > The number of columns (or rows) of A. Not modified. */
  300. /* > \endverbatim */
  301. /* > */
  302. /* > \param[in] DIST */
  303. /* > \verbatim */
  304. /* > DIST is CHARACTER*1 */
  305. /* > On entry, DIST specifies the type of distribution to be used */
  306. /* > to generate the random eigen-/singular values, and on the */
  307. /* > upper triangle (see UPPER). */
  308. /* > 'U' => UNIFORM( 0, 1 ) ( 'U' for uniform ) */
  309. /* > 'S' => UNIFORM( -1, 1 ) ( 'S' for symmetric ) */
  310. /* > 'N' => NORMAL( 0, 1 ) ( 'N' for normal ) */
  311. /* > 'D' => uniform on the complex disc |z| < 1. */
  312. /* > Not modified. */
  313. /* > \endverbatim */
  314. /* > */
  315. /* > \param[in,out] ISEED */
  316. /* > \verbatim */
  317. /* > ISEED is INTEGER array, dimension ( 4 ) */
  318. /* > On entry ISEED specifies the seed of the random number */
  319. /* > generator. They should lie between 0 and 4095 inclusive, */
  320. /* > and ISEED(4) should be odd. The random number generator */
  321. /* > uses a linear congruential sequence limited to small */
  322. /* > integers, and so should produce machine independent */
  323. /* > random numbers. The values of ISEED are changed on */
  324. /* > exit, and can be used in the next call to ZLATME */
  325. /* > to continue the same random number sequence. */
  326. /* > Changed on exit. */
  327. /* > \endverbatim */
  328. /* > */
  329. /* > \param[in,out] D */
  330. /* > \verbatim */
  331. /* > D is COMPLEX*16 array, dimension ( N ) */
  332. /* > This array is used to specify the eigenvalues of A. If */
  333. /* > MODE=0, then D is assumed to contain the eigenvalues */
  334. /* > otherwise they will be computed according to MODE, COND, */
  335. /* > DMAX, and RSIGN and placed in D. */
  336. /* > Modified if MODE is nonzero. */
  337. /* > \endverbatim */
  338. /* > */
  339. /* > \param[in] MODE */
  340. /* > \verbatim */
  341. /* > MODE is INTEGER */
  342. /* > On entry this describes how the eigenvalues are to */
  343. /* > be specified: */
  344. /* > MODE = 0 means use D as input */
  345. /* > MODE = 1 sets D(1)=1 and D(2:N)=1.0/COND */
  346. /* > MODE = 2 sets D(1:N-1)=1 and D(N)=1.0/COND */
  347. /* > MODE = 3 sets D(I)=COND**(-(I-1)/(N-1)) */
  348. /* > MODE = 4 sets D(i)=1 - (i-1)/(N-1)*(1 - 1/COND) */
  349. /* > MODE = 5 sets D to random numbers in the range */
  350. /* > ( 1/COND , 1 ) such that their logarithms */
  351. /* > are uniformly distributed. */
  352. /* > MODE = 6 set D to random numbers from same distribution */
  353. /* > as the rest of the matrix. */
  354. /* > MODE < 0 has the same meaning as ABS(MODE), except that */
  355. /* > the order of the elements of D is reversed. */
  356. /* > Thus if MODE is between 1 and 4, D has entries ranging */
  357. /* > from 1 to 1/COND, if between -1 and -4, D has entries */
  358. /* > ranging from 1/COND to 1, */
  359. /* > Not modified. */
  360. /* > \endverbatim */
  361. /* > */
  362. /* > \param[in] COND */
  363. /* > \verbatim */
  364. /* > COND is DOUBLE PRECISION */
  365. /* > On entry, this is used as described under MODE above. */
  366. /* > If used, it must be >= 1. Not modified. */
  367. /* > \endverbatim */
  368. /* > */
  369. /* > \param[in] DMAX */
  370. /* > \verbatim */
  371. /* > DMAX is COMPLEX*16 */
  372. /* > If MODE is neither -6, 0 nor 6, the contents of D, as */
  373. /* > computed according to MODE and COND, will be scaled by */
  374. /* > DMAX / f2cmax(abs(D(i))). Note that DMAX need not be */
  375. /* > positive or real: if DMAX is negative or complex (or zero), */
  376. /* > D will be scaled by a negative or complex number (or zero). */
  377. /* > If RSIGN='F' then the largest (absolute) eigenvalue will be */
  378. /* > equal to DMAX. */
  379. /* > Not modified. */
  380. /* > \endverbatim */
  381. /* > */
  382. /* > \param[in] RSIGN */
  383. /* > \verbatim */
  384. /* > RSIGN is CHARACTER*1 */
  385. /* > If MODE is not 0, 6, or -6, and RSIGN='T', then the */
  386. /* > elements of D, as computed according to MODE and COND, will */
  387. /* > be multiplied by a random complex number from the unit */
  388. /* > circle |z| = 1. If RSIGN='F', they will not be. RSIGN may */
  389. /* > only have the values 'T' or 'F'. */
  390. /* > Not modified. */
  391. /* > \endverbatim */
  392. /* > */
  393. /* > \param[in] UPPER */
  394. /* > \verbatim */
  395. /* > UPPER is CHARACTER*1 */
  396. /* > If UPPER='T', then the elements of A above the diagonal */
  397. /* > will be set to random numbers out of DIST. If UPPER='F', */
  398. /* > they will not. UPPER may only have the values 'T' or 'F'. */
  399. /* > Not modified. */
  400. /* > \endverbatim */
  401. /* > */
  402. /* > \param[in] SIM */
  403. /* > \verbatim */
  404. /* > SIM is CHARACTER*1 */
  405. /* > If SIM='T', then A will be operated on by a "similarity */
  406. /* > transform", i.e., multiplied on the left by a matrix X and */
  407. /* > on the right by X inverse. X = U S V, where U and V are */
  408. /* > random unitary matrices and S is a (diagonal) matrix of */
  409. /* > singular values specified by DS, MODES, and CONDS. If */
  410. /* > SIM='F', then A will not be transformed. */
  411. /* > Not modified. */
  412. /* > \endverbatim */
  413. /* > */
  414. /* > \param[in,out] DS */
  415. /* > \verbatim */
  416. /* > DS is DOUBLE PRECISION array, dimension ( N ) */
  417. /* > This array is used to specify the singular values of X, */
  418. /* > in the same way that D specifies the eigenvalues of A. */
  419. /* > If MODE=0, the DS contains the singular values, which */
  420. /* > may not be zero. */
  421. /* > Modified if MODE is nonzero. */
  422. /* > \endverbatim */
  423. /* > */
  424. /* > \param[in] MODES */
  425. /* > \verbatim */
  426. /* > MODES is INTEGER */
  427. /* > \endverbatim */
  428. /* > */
  429. /* > \param[in] CONDS */
  430. /* > \verbatim */
  431. /* > CONDS is DOUBLE PRECISION */
  432. /* > Similar to MODE and COND, but for specifying the diagonal */
  433. /* > of S. MODES=-6 and +6 are not allowed (since they would */
  434. /* > result in randomly ill-conditioned eigenvalues.) */
  435. /* > \endverbatim */
  436. /* > */
  437. /* > \param[in] KL */
  438. /* > \verbatim */
  439. /* > KL is INTEGER */
  440. /* > This specifies the lower bandwidth of the matrix. KL=1 */
  441. /* > specifies upper Hessenberg form. If KL is at least N-1, */
  442. /* > then A will have full lower bandwidth. */
  443. /* > Not modified. */
  444. /* > \endverbatim */
  445. /* > */
  446. /* > \param[in] KU */
  447. /* > \verbatim */
  448. /* > KU is INTEGER */
  449. /* > This specifies the upper bandwidth of the matrix. KU=1 */
  450. /* > specifies lower Hessenberg form. If KU is at least N-1, */
  451. /* > then A will have full upper bandwidth; if KU and KL */
  452. /* > are both at least N-1, then A will be dense. Only one of */
  453. /* > KU and KL may be less than N-1. */
  454. /* > Not modified. */
  455. /* > \endverbatim */
  456. /* > */
  457. /* > \param[in] ANORM */
  458. /* > \verbatim */
  459. /* > ANORM is DOUBLE PRECISION */
  460. /* > If ANORM is not negative, then A will be scaled by a non- */
  461. /* > negative real number to make the maximum-element-norm of A */
  462. /* > to be ANORM. */
  463. /* > Not modified. */
  464. /* > \endverbatim */
  465. /* > */
  466. /* > \param[out] A */
  467. /* > \verbatim */
  468. /* > A is COMPLEX*16 array, dimension ( LDA, N ) */
  469. /* > On exit A is the desired test matrix. */
  470. /* > Modified. */
  471. /* > \endverbatim */
  472. /* > */
  473. /* > \param[in] LDA */
  474. /* > \verbatim */
  475. /* > LDA is INTEGER */
  476. /* > LDA specifies the first dimension of A as declared in the */
  477. /* > calling program. LDA must be at least M. */
  478. /* > Not modified. */
  479. /* > \endverbatim */
  480. /* > */
  481. /* > \param[out] WORK */
  482. /* > \verbatim */
  483. /* > WORK is COMPLEX*16 array, dimension ( 3*N ) */
  484. /* > Workspace. */
  485. /* > Modified. */
  486. /* > \endverbatim */
  487. /* > */
  488. /* > \param[out] INFO */
  489. /* > \verbatim */
  490. /* > INFO is INTEGER */
  491. /* > Error code. On exit, INFO will be set to one of the */
  492. /* > following values: */
  493. /* > 0 => normal return */
  494. /* > -1 => N negative */
  495. /* > -2 => DIST illegal string */
  496. /* > -5 => MODE not in range -6 to 6 */
  497. /* > -6 => COND less than 1.0, and MODE neither -6, 0 nor 6 */
  498. /* > -9 => RSIGN is not 'T' or 'F' */
  499. /* > -10 => UPPER is not 'T' or 'F' */
  500. /* > -11 => SIM is not 'T' or 'F' */
  501. /* > -12 => MODES=0 and DS has a zero singular value. */
  502. /* > -13 => MODES is not in the range -5 to 5. */
  503. /* > -14 => MODES is nonzero and CONDS is less than 1. */
  504. /* > -15 => KL is less than 1. */
  505. /* > -16 => KU is less than 1, or KL and KU are both less than */
  506. /* > N-1. */
  507. /* > -19 => LDA is less than M. */
  508. /* > 1 => Error return from ZLATM1 (computing D) */
  509. /* > 2 => Cannot scale to DMAX (f2cmax. eigenvalue is 0) */
  510. /* > 3 => Error return from DLATM1 (computing DS) */
  511. /* > 4 => Error return from ZLARGE */
  512. /* > 5 => Zero singular value from DLATM1. */
  513. /* > \endverbatim */
  514. /* Authors: */
  515. /* ======== */
  516. /* > \author Univ. of Tennessee */
  517. /* > \author Univ. of California Berkeley */
  518. /* > \author Univ. of Colorado Denver */
  519. /* > \author NAG Ltd. */
  520. /* > \date December 2016 */
  521. /* > \ingroup complex16_matgen */
  522. /* ===================================================================== */
  523. /* Subroutine */ void zlatme_(integer *n, char *dist, integer *iseed,
  524. doublecomplex *d__, integer *mode, doublereal *cond, doublecomplex *
  525. dmax__, char *rsign, char *upper, char *sim, doublereal *ds, integer *
  526. modes, doublereal *conds, integer *kl, integer *ku, doublereal *anorm,
  527. doublecomplex *a, integer *lda, doublecomplex *work, integer *info)
  528. {
  529. /* System generated locals */
  530. integer a_dim1, a_offset, i__1, i__2;
  531. doublereal d__1, d__2;
  532. doublecomplex z__1, z__2;
  533. /* Local variables */
  534. logical bads;
  535. integer isim;
  536. doublereal temp;
  537. integer i__, j;
  538. doublecomplex alpha;
  539. extern logical lsame_(char *, char *);
  540. integer iinfo;
  541. doublereal tempa[1];
  542. integer icols;
  543. extern /* Subroutine */ void zgerc_(integer *, integer *, doublecomplex *,
  544. doublecomplex *, integer *, doublecomplex *, integer *,
  545. doublecomplex *, integer *);
  546. integer idist;
  547. extern /* Subroutine */ void zscal_(integer *, doublecomplex *,
  548. doublecomplex *, integer *), zgemv_(char *, integer *, integer *,
  549. doublecomplex *, doublecomplex *, integer *, doublecomplex *,
  550. integer *, doublecomplex *, doublecomplex *, integer *);
  551. integer irows;
  552. extern /* Subroutine */ void zcopy_(integer *, doublecomplex *, integer *,
  553. doublecomplex *, integer *), dlatm1_(integer *, doublereal *,
  554. integer *, integer *, integer *, doublereal *, integer *, integer
  555. *), zlatm1_(integer *, doublereal *, integer *, integer *,
  556. integer *, doublecomplex *, integer *, integer *);
  557. integer ic, jc, ir;
  558. doublereal ralpha;
  559. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  560. extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
  561. integer *, doublereal *);
  562. extern /* Subroutine */ void zdscal_(integer *, doublereal *,
  563. doublecomplex *, integer *), zlarge_(integer *, doublecomplex *,
  564. integer *, integer *, doublecomplex *, integer *), zlarfg_(
  565. integer *, doublecomplex *, doublecomplex *, integer *,
  566. doublecomplex *), zlacgv_(integer *, doublecomplex *, integer *);
  567. //extern /* Double Complex */ VOID zlarnd_(doublecomplex *, integer *,
  568. extern doublecomplex zlarnd_(integer *,
  569. integer *);
  570. integer irsign;
  571. extern /* Subroutine */ void zlaset_(char *, integer *, integer *,
  572. doublecomplex *, doublecomplex *, doublecomplex *, integer *);
  573. integer iupper;
  574. extern /* Subroutine */ void zlarnv_(integer *, integer *, integer *,
  575. doublecomplex *);
  576. doublecomplex xnorms;
  577. integer jcr;
  578. doublecomplex tau;
  579. /* -- LAPACK computational routine (version 3.7.0) -- */
  580. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  581. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  582. /* December 2016 */
  583. /* ===================================================================== */
  584. /* 1) Decode and Test the input parameters. */
  585. /* Initialize flags & seed. */
  586. /* Parameter adjustments */
  587. --iseed;
  588. --d__;
  589. --ds;
  590. a_dim1 = *lda;
  591. a_offset = 1 + a_dim1 * 1;
  592. a -= a_offset;
  593. --work;
  594. /* Function Body */
  595. *info = 0;
  596. /* Quick return if possible */
  597. if (*n == 0) {
  598. return;
  599. }
  600. /* Decode DIST */
  601. if (lsame_(dist, "U")) {
  602. idist = 1;
  603. } else if (lsame_(dist, "S")) {
  604. idist = 2;
  605. } else if (lsame_(dist, "N")) {
  606. idist = 3;
  607. } else if (lsame_(dist, "D")) {
  608. idist = 4;
  609. } else {
  610. idist = -1;
  611. }
  612. /* Decode RSIGN */
  613. if (lsame_(rsign, "T")) {
  614. irsign = 1;
  615. } else if (lsame_(rsign, "F")) {
  616. irsign = 0;
  617. } else {
  618. irsign = -1;
  619. }
  620. /* Decode UPPER */
  621. if (lsame_(upper, "T")) {
  622. iupper = 1;
  623. } else if (lsame_(upper, "F")) {
  624. iupper = 0;
  625. } else {
  626. iupper = -1;
  627. }
  628. /* Decode SIM */
  629. if (lsame_(sim, "T")) {
  630. isim = 1;
  631. } else if (lsame_(sim, "F")) {
  632. isim = 0;
  633. } else {
  634. isim = -1;
  635. }
  636. /* Check DS, if MODES=0 and ISIM=1 */
  637. bads = FALSE_;
  638. if (*modes == 0 && isim == 1) {
  639. i__1 = *n;
  640. for (j = 1; j <= i__1; ++j) {
  641. if (ds[j] == 0.) {
  642. bads = TRUE_;
  643. }
  644. /* L10: */
  645. }
  646. }
  647. /* Set INFO if an error */
  648. if (*n < 0) {
  649. *info = -1;
  650. } else if (idist == -1) {
  651. *info = -2;
  652. } else if (abs(*mode) > 6) {
  653. *info = -5;
  654. } else if (*mode != 0 && abs(*mode) != 6 && *cond < 1.) {
  655. *info = -6;
  656. } else if (irsign == -1) {
  657. *info = -9;
  658. } else if (iupper == -1) {
  659. *info = -10;
  660. } else if (isim == -1) {
  661. *info = -11;
  662. } else if (bads) {
  663. *info = -12;
  664. } else if (isim == 1 && abs(*modes) > 5) {
  665. *info = -13;
  666. } else if (isim == 1 && *modes != 0 && *conds < 1.) {
  667. *info = -14;
  668. } else if (*kl < 1) {
  669. *info = -15;
  670. } else if (*ku < 1 || *ku < *n - 1 && *kl < *n - 1) {
  671. *info = -16;
  672. } else if (*lda < f2cmax(1,*n)) {
  673. *info = -19;
  674. }
  675. if (*info != 0) {
  676. i__1 = -(*info);
  677. xerbla_("ZLATME", &i__1, 6);
  678. return;
  679. }
  680. /* Initialize random number generator */
  681. for (i__ = 1; i__ <= 4; ++i__) {
  682. iseed[i__] = (i__1 = iseed[i__], abs(i__1)) % 4096;
  683. /* L20: */
  684. }
  685. if (iseed[4] % 2 != 1) {
  686. ++iseed[4];
  687. }
  688. /* 2) Set up diagonal of A */
  689. /* Compute D according to COND and MODE */
  690. zlatm1_(mode, cond, &irsign, &idist, &iseed[1], &d__[1], n, &iinfo);
  691. if (iinfo != 0) {
  692. *info = 1;
  693. return;
  694. }
  695. if (*mode != 0 && abs(*mode) != 6) {
  696. /* Scale by DMAX */
  697. temp = z_abs(&d__[1]);
  698. i__1 = *n;
  699. for (i__ = 2; i__ <= i__1; ++i__) {
  700. /* Computing MAX */
  701. d__1 = temp, d__2 = z_abs(&d__[i__]);
  702. temp = f2cmax(d__1,d__2);
  703. /* L30: */
  704. }
  705. if (temp > 0.) {
  706. z__1.r = dmax__->r / temp, z__1.i = dmax__->i / temp;
  707. alpha.r = z__1.r, alpha.i = z__1.i;
  708. } else {
  709. *info = 2;
  710. return;
  711. }
  712. zscal_(n, &alpha, &d__[1], &c__1);
  713. }
  714. zlaset_("Full", n, n, &c_b1, &c_b1, &a[a_offset], lda);
  715. i__1 = *lda + 1;
  716. zcopy_(n, &d__[1], &c__1, &a[a_offset], &i__1);
  717. /* 3) If UPPER='T', set upper triangle of A to random numbers. */
  718. if (iupper != 0) {
  719. i__1 = *n;
  720. for (jc = 2; jc <= i__1; ++jc) {
  721. i__2 = jc - 1;
  722. zlarnv_(&idist, &iseed[1], &i__2, &a[jc * a_dim1 + 1]);
  723. /* L40: */
  724. }
  725. }
  726. /* 4) If SIM='T', apply similarity transformation. */
  727. /* -1 */
  728. /* Transform is X A X , where X = U S V, thus */
  729. /* it is U S V A V' (1/S) U' */
  730. if (isim != 0) {
  731. /* Compute S (singular values of the eigenvector matrix) */
  732. /* according to CONDS and MODES */
  733. dlatm1_(modes, conds, &c__0, &c__0, &iseed[1], &ds[1], n, &iinfo);
  734. if (iinfo != 0) {
  735. *info = 3;
  736. return;
  737. }
  738. /* Multiply by V and V' */
  739. zlarge_(n, &a[a_offset], lda, &iseed[1], &work[1], &iinfo);
  740. if (iinfo != 0) {
  741. *info = 4;
  742. return;
  743. }
  744. /* Multiply by S and (1/S) */
  745. i__1 = *n;
  746. for (j = 1; j <= i__1; ++j) {
  747. zdscal_(n, &ds[j], &a[j + a_dim1], lda);
  748. if (ds[j] != 0.) {
  749. d__1 = 1. / ds[j];
  750. zdscal_(n, &d__1, &a[j * a_dim1 + 1], &c__1);
  751. } else {
  752. *info = 5;
  753. return;
  754. }
  755. /* L50: */
  756. }
  757. /* Multiply by U and U' */
  758. zlarge_(n, &a[a_offset], lda, &iseed[1], &work[1], &iinfo);
  759. if (iinfo != 0) {
  760. *info = 4;
  761. return;
  762. }
  763. }
  764. /* 5) Reduce the bandwidth. */
  765. if (*kl < *n - 1) {
  766. /* Reduce bandwidth -- kill column */
  767. i__1 = *n - 1;
  768. for (jcr = *kl + 1; jcr <= i__1; ++jcr) {
  769. ic = jcr - *kl;
  770. irows = *n + 1 - jcr;
  771. icols = *n + *kl - jcr;
  772. zcopy_(&irows, &a[jcr + ic * a_dim1], &c__1, &work[1], &c__1);
  773. xnorms.r = work[1].r, xnorms.i = work[1].i;
  774. zlarfg_(&irows, &xnorms, &work[2], &c__1, &tau);
  775. d_cnjg(&z__1, &tau);
  776. tau.r = z__1.r, tau.i = z__1.i;
  777. work[1].r = 1., work[1].i = 0.;
  778. //zlarnd_(&z__1, &c__5, &iseed[1]);
  779. z__1=zlarnd_(&c__5, &iseed[1]);
  780. alpha.r = z__1.r, alpha.i = z__1.i;
  781. zgemv_("C", &irows, &icols, &c_b2, &a[jcr + (ic + 1) * a_dim1],
  782. lda, &work[1], &c__1, &c_b1, &work[irows + 1], &c__1);
  783. z__1.r = -tau.r, z__1.i = -tau.i;
  784. zgerc_(&irows, &icols, &z__1, &work[1], &c__1, &work[irows + 1], &
  785. c__1, &a[jcr + (ic + 1) * a_dim1], lda);
  786. zgemv_("N", n, &irows, &c_b2, &a[jcr * a_dim1 + 1], lda, &work[1],
  787. &c__1, &c_b1, &work[irows + 1], &c__1);
  788. d_cnjg(&z__2, &tau);
  789. z__1.r = -z__2.r, z__1.i = -z__2.i;
  790. zgerc_(n, &irows, &z__1, &work[irows + 1], &c__1, &work[1], &c__1,
  791. &a[jcr * a_dim1 + 1], lda);
  792. i__2 = jcr + ic * a_dim1;
  793. a[i__2].r = xnorms.r, a[i__2].i = xnorms.i;
  794. i__2 = irows - 1;
  795. zlaset_("Full", &i__2, &c__1, &c_b1, &c_b1, &a[jcr + 1 + ic *
  796. a_dim1], lda);
  797. i__2 = icols + 1;
  798. zscal_(&i__2, &alpha, &a[jcr + ic * a_dim1], lda);
  799. d_cnjg(&z__1, &alpha);
  800. zscal_(n, &z__1, &a[jcr * a_dim1 + 1], &c__1);
  801. /* L60: */
  802. }
  803. } else if (*ku < *n - 1) {
  804. /* Reduce upper bandwidth -- kill a row at a time. */
  805. i__1 = *n - 1;
  806. for (jcr = *ku + 1; jcr <= i__1; ++jcr) {
  807. ir = jcr - *ku;
  808. irows = *n + *ku - jcr;
  809. icols = *n + 1 - jcr;
  810. zcopy_(&icols, &a[ir + jcr * a_dim1], lda, &work[1], &c__1);
  811. xnorms.r = work[1].r, xnorms.i = work[1].i;
  812. zlarfg_(&icols, &xnorms, &work[2], &c__1, &tau);
  813. d_cnjg(&z__1, &tau);
  814. tau.r = z__1.r, tau.i = z__1.i;
  815. work[1].r = 1., work[1].i = 0.;
  816. i__2 = icols - 1;
  817. zlacgv_(&i__2, &work[2], &c__1);
  818. //zlarnd_(&z__1, &c__5, &iseed[1]);
  819. z__1 = zlarnd_(&c__5, &iseed[1]);
  820. alpha.r = z__1.r, alpha.i = z__1.i;
  821. zgemv_("N", &irows, &icols, &c_b2, &a[ir + 1 + jcr * a_dim1], lda,
  822. &work[1], &c__1, &c_b1, &work[icols + 1], &c__1);
  823. z__1.r = -tau.r, z__1.i = -tau.i;
  824. zgerc_(&irows, &icols, &z__1, &work[icols + 1], &c__1, &work[1], &
  825. c__1, &a[ir + 1 + jcr * a_dim1], lda);
  826. zgemv_("C", &icols, n, &c_b2, &a[jcr + a_dim1], lda, &work[1], &
  827. c__1, &c_b1, &work[icols + 1], &c__1);
  828. d_cnjg(&z__2, &tau);
  829. z__1.r = -z__2.r, z__1.i = -z__2.i;
  830. zgerc_(&icols, n, &z__1, &work[1], &c__1, &work[icols + 1], &c__1,
  831. &a[jcr + a_dim1], lda);
  832. i__2 = ir + jcr * a_dim1;
  833. a[i__2].r = xnorms.r, a[i__2].i = xnorms.i;
  834. i__2 = icols - 1;
  835. zlaset_("Full", &c__1, &i__2, &c_b1, &c_b1, &a[ir + (jcr + 1) *
  836. a_dim1], lda);
  837. i__2 = irows + 1;
  838. zscal_(&i__2, &alpha, &a[ir + jcr * a_dim1], &c__1);
  839. d_cnjg(&z__1, &alpha);
  840. zscal_(n, &z__1, &a[jcr + a_dim1], lda);
  841. /* L70: */
  842. }
  843. }
  844. /* Scale the matrix to have norm ANORM */
  845. if (*anorm >= 0.) {
  846. temp = zlange_("M", n, n, &a[a_offset], lda, tempa);
  847. if (temp > 0.) {
  848. ralpha = *anorm / temp;
  849. i__1 = *n;
  850. for (j = 1; j <= i__1; ++j) {
  851. zdscal_(n, &ralpha, &a[j * a_dim1 + 1], &c__1);
  852. /* L80: */
  853. }
  854. }
  855. }
  856. return;
  857. /* End of ZLATME */
  858. } /* zlatme_ */