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.

clatme.c 30 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  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]/df(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 complex c_b1 = {0.f,0.f};
  240. static complex c_b2 = {1.f,0.f};
  241. static integer c__1 = 1;
  242. static integer c__0 = 0;
  243. static integer c__5 = 5;
  244. /* > \brief \b CLATME */
  245. /* =========== DOCUMENTATION =========== */
  246. /* Online html documentation available at */
  247. /* http://www.netlib.org/lapack/explore-html/ */
  248. /* Definition: */
  249. /* =========== */
  250. /* SUBROUTINE CLATME( 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. /* REAL ANORM, COND, CONDS */
  258. /* COMPLEX DMAX */
  259. /* INTEGER ISEED( 4 ) */
  260. /* REAL DS( * ) */
  261. /* COMPLEX A( LDA, * ), D( * ), WORK( * ) */
  262. /* > \par Purpose: */
  263. /* ============= */
  264. /* > */
  265. /* > \verbatim */
  266. /* > */
  267. /* > CLATME generates random non-symmetric square matrices with */
  268. /* > specified eigenvalues for testing LAPACK programs. */
  269. /* > */
  270. /* > CLATME 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 CLATME */
  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 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 REAL */
  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 */
  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 REAL 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 REAL */
  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 REAL */
  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 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 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 CLATM1 (computing D) */
  509. /* > 2 => Cannot scale to DMAX (f2cmax. eigenvalue is 0) */
  510. /* > 3 => Error return from SLATM1 (computing DS) */
  511. /* > 4 => Error return from CLARGE */
  512. /* > 5 => Zero singular value from SLATM1. */
  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 complex_matgen */
  522. /* ===================================================================== */
  523. /* Subroutine */ void clatme_(integer *n, char *dist, integer *iseed, complex *
  524. d__, integer *mode, real *cond, complex *dmax__, char *rsign, char *
  525. upper, char *sim, real *ds, integer *modes, real *conds, integer *kl,
  526. integer *ku, real *anorm, complex *a, integer *lda, complex *work,
  527. integer *info)
  528. {
  529. /* System generated locals */
  530. integer a_dim1, a_offset, i__1, i__2;
  531. real r__1, r__2;
  532. complex q__1, q__2;
  533. /* Local variables */
  534. logical bads;
  535. integer isim;
  536. real temp;
  537. integer i__, j;
  538. extern /* Subroutine */ void cgerc_(integer *, integer *, complex *,
  539. complex *, integer *, complex *, integer *, complex *, integer *);
  540. complex alpha;
  541. extern /* Subroutine */ void cscal_(integer *, complex *, complex *,
  542. integer *);
  543. extern logical lsame_(char *, char *);
  544. extern /* Subroutine */ void cgemv_(char *, integer *, integer *, complex *
  545. , complex *, integer *, complex *, integer *, complex *, complex *
  546. , integer *);
  547. integer iinfo;
  548. real tempa[1];
  549. integer icols, idist;
  550. extern /* Subroutine */ void ccopy_(integer *, complex *, integer *,
  551. complex *, integer *);
  552. integer irows;
  553. extern /* Subroutine */ void clatm1_(integer *, real *, integer *, integer
  554. *, integer *, complex *, integer *, integer *), slatm1_(integer *,
  555. real *, integer *, integer *, integer *, real *, integer *,
  556. integer *);
  557. integer ic, jc;
  558. extern real clange_(char *, integer *, integer *, complex *, integer *,
  559. real *);
  560. integer ir;
  561. extern /* Subroutine */ void clarge_(integer *, complex *, integer *,
  562. integer *, complex *, integer *), clarfg_(integer *, complex *,
  563. complex *, integer *, complex *), clacgv_(integer *, complex *,
  564. integer *);
  565. //extern /* Complex */ VOID clarnd_(complex *, integer *, integer *);
  566. extern complex clarnd_(integer *, integer *);
  567. real ralpha;
  568. extern /* Subroutine */ void csscal_(integer *, real *, complex *, integer
  569. *), claset_(char *, integer *, integer *, complex *, complex *,
  570. complex *, integer *);
  571. extern int xerbla_(char *, integer *, ftnlen);
  572. extern void clarnv_(integer *, integer *, integer *, complex *);
  573. integer irsign, iupper;
  574. complex xnorms;
  575. integer jcr;
  576. complex tau;
  577. /* -- LAPACK computational routine (version 3.7.0) -- */
  578. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  579. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  580. /* December 2016 */
  581. /* ===================================================================== */
  582. /* 1) Decode and Test the input parameters. */
  583. /* Initialize flags & seed. */
  584. /* Parameter adjustments */
  585. --iseed;
  586. --d__;
  587. --ds;
  588. a_dim1 = *lda;
  589. a_offset = 1 + a_dim1 * 1;
  590. a -= a_offset;
  591. --work;
  592. /* Function Body */
  593. *info = 0;
  594. /* Quick return if possible */
  595. if (*n == 0) {
  596. return;
  597. }
  598. /* Decode DIST */
  599. if (lsame_(dist, "U")) {
  600. idist = 1;
  601. } else if (lsame_(dist, "S")) {
  602. idist = 2;
  603. } else if (lsame_(dist, "N")) {
  604. idist = 3;
  605. } else if (lsame_(dist, "D")) {
  606. idist = 4;
  607. } else {
  608. idist = -1;
  609. }
  610. /* Decode RSIGN */
  611. if (lsame_(rsign, "T")) {
  612. irsign = 1;
  613. } else if (lsame_(rsign, "F")) {
  614. irsign = 0;
  615. } else {
  616. irsign = -1;
  617. }
  618. /* Decode UPPER */
  619. if (lsame_(upper, "T")) {
  620. iupper = 1;
  621. } else if (lsame_(upper, "F")) {
  622. iupper = 0;
  623. } else {
  624. iupper = -1;
  625. }
  626. /* Decode SIM */
  627. if (lsame_(sim, "T")) {
  628. isim = 1;
  629. } else if (lsame_(sim, "F")) {
  630. isim = 0;
  631. } else {
  632. isim = -1;
  633. }
  634. /* Check DS, if MODES=0 and ISIM=1 */
  635. bads = FALSE_;
  636. if (*modes == 0 && isim == 1) {
  637. i__1 = *n;
  638. for (j = 1; j <= i__1; ++j) {
  639. if (ds[j] == 0.f) {
  640. bads = TRUE_;
  641. }
  642. /* L10: */
  643. }
  644. }
  645. /* Set INFO if an error */
  646. if (*n < 0) {
  647. *info = -1;
  648. } else if (idist == -1) {
  649. *info = -2;
  650. } else if (abs(*mode) > 6) {
  651. *info = -5;
  652. } else if (*mode != 0 && abs(*mode) != 6 && *cond < 1.f) {
  653. *info = -6;
  654. } else if (irsign == -1) {
  655. *info = -9;
  656. } else if (iupper == -1) {
  657. *info = -10;
  658. } else if (isim == -1) {
  659. *info = -11;
  660. } else if (bads) {
  661. *info = -12;
  662. } else if (isim == 1 && abs(*modes) > 5) {
  663. *info = -13;
  664. } else if (isim == 1 && *modes != 0 && *conds < 1.f) {
  665. *info = -14;
  666. } else if (*kl < 1) {
  667. *info = -15;
  668. } else if (*ku < 1 || *ku < *n - 1 && *kl < *n - 1) {
  669. *info = -16;
  670. } else if (*lda < f2cmax(1,*n)) {
  671. *info = -19;
  672. }
  673. if (*info != 0) {
  674. i__1 = -(*info);
  675. xerbla_("CLATME", &i__1, 6);
  676. return;
  677. }
  678. /* Initialize random number generator */
  679. for (i__ = 1; i__ <= 4; ++i__) {
  680. iseed[i__] = (i__1 = iseed[i__], abs(i__1)) % 4096;
  681. /* L20: */
  682. }
  683. if (iseed[4] % 2 != 1) {
  684. ++iseed[4];
  685. }
  686. /* 2) Set up diagonal of A */
  687. /* Compute D according to COND and MODE */
  688. clatm1_(mode, cond, &irsign, &idist, &iseed[1], &d__[1], n, &iinfo);
  689. if (iinfo != 0) {
  690. *info = 1;
  691. return;
  692. }
  693. if (*mode != 0 && abs(*mode) != 6) {
  694. /* Scale by DMAX */
  695. temp = c_abs(&d__[1]);
  696. i__1 = *n;
  697. for (i__ = 2; i__ <= i__1; ++i__) {
  698. /* Computing MAX */
  699. r__1 = temp, r__2 = c_abs(&d__[i__]);
  700. temp = f2cmax(r__1,r__2);
  701. /* L30: */
  702. }
  703. if (temp > 0.f) {
  704. q__1.r = dmax__->r / temp, q__1.i = dmax__->i / temp;
  705. alpha.r = q__1.r, alpha.i = q__1.i;
  706. } else {
  707. *info = 2;
  708. return;
  709. }
  710. cscal_(n, &alpha, &d__[1], &c__1);
  711. }
  712. claset_("Full", n, n, &c_b1, &c_b1, &a[a_offset], lda);
  713. i__1 = *lda + 1;
  714. ccopy_(n, &d__[1], &c__1, &a[a_offset], &i__1);
  715. /* 3) If UPPER='T', set upper triangle of A to random numbers. */
  716. if (iupper != 0) {
  717. i__1 = *n;
  718. for (jc = 2; jc <= i__1; ++jc) {
  719. i__2 = jc - 1;
  720. clarnv_(&idist, &iseed[1], &i__2, &a[jc * a_dim1 + 1]);
  721. /* L40: */
  722. }
  723. }
  724. /* 4) If SIM='T', apply similarity transformation. */
  725. /* -1 */
  726. /* Transform is X A X , where X = U S V, thus */
  727. /* it is U S V A V' (1/S) U' */
  728. if (isim != 0) {
  729. /* Compute S (singular values of the eigenvector matrix) */
  730. /* according to CONDS and MODES */
  731. slatm1_(modes, conds, &c__0, &c__0, &iseed[1], &ds[1], n, &iinfo);
  732. if (iinfo != 0) {
  733. *info = 3;
  734. return;
  735. }
  736. /* Multiply by V and V' */
  737. clarge_(n, &a[a_offset], lda, &iseed[1], &work[1], &iinfo);
  738. if (iinfo != 0) {
  739. *info = 4;
  740. return;
  741. }
  742. /* Multiply by S and (1/S) */
  743. i__1 = *n;
  744. for (j = 1; j <= i__1; ++j) {
  745. csscal_(n, &ds[j], &a[j + a_dim1], lda);
  746. if (ds[j] != 0.f) {
  747. r__1 = 1.f / ds[j];
  748. csscal_(n, &r__1, &a[j * a_dim1 + 1], &c__1);
  749. } else {
  750. *info = 5;
  751. return;
  752. }
  753. /* L50: */
  754. }
  755. /* Multiply by U and U' */
  756. clarge_(n, &a[a_offset], lda, &iseed[1], &work[1], &iinfo);
  757. if (iinfo != 0) {
  758. *info = 4;
  759. return;
  760. }
  761. }
  762. /* 5) Reduce the bandwidth. */
  763. if (*kl < *n - 1) {
  764. /* Reduce bandwidth -- kill column */
  765. i__1 = *n - 1;
  766. for (jcr = *kl + 1; jcr <= i__1; ++jcr) {
  767. ic = jcr - *kl;
  768. irows = *n + 1 - jcr;
  769. icols = *n + *kl - jcr;
  770. ccopy_(&irows, &a[jcr + ic * a_dim1], &c__1, &work[1], &c__1);
  771. xnorms.r = work[1].r, xnorms.i = work[1].i;
  772. clarfg_(&irows, &xnorms, &work[2], &c__1, &tau);
  773. r_cnjg(&q__1, &tau);
  774. tau.r = q__1.r, tau.i = q__1.i;
  775. work[1].r = 1.f, work[1].i = 0.f;
  776. //clarnd_(&q__1, &c__5, &iseed[1]);
  777. q__1=clarnd_(&c__5, &iseed[1]);
  778. alpha.r = q__1.r, alpha.i = q__1.i;
  779. cgemv_("C", &irows, &icols, &c_b2, &a[jcr + (ic + 1) * a_dim1],
  780. lda, &work[1], &c__1, &c_b1, &work[irows + 1], &c__1);
  781. q__1.r = -tau.r, q__1.i = -tau.i;
  782. cgerc_(&irows, &icols, &q__1, &work[1], &c__1, &work[irows + 1], &
  783. c__1, &a[jcr + (ic + 1) * a_dim1], lda);
  784. cgemv_("N", n, &irows, &c_b2, &a[jcr * a_dim1 + 1], lda, &work[1],
  785. &c__1, &c_b1, &work[irows + 1], &c__1);
  786. r_cnjg(&q__2, &tau);
  787. q__1.r = -q__2.r, q__1.i = -q__2.i;
  788. cgerc_(n, &irows, &q__1, &work[irows + 1], &c__1, &work[1], &c__1,
  789. &a[jcr * a_dim1 + 1], lda);
  790. i__2 = jcr + ic * a_dim1;
  791. a[i__2].r = xnorms.r, a[i__2].i = xnorms.i;
  792. i__2 = irows - 1;
  793. claset_("Full", &i__2, &c__1, &c_b1, &c_b1, &a[jcr + 1 + ic *
  794. a_dim1], lda);
  795. i__2 = icols + 1;
  796. cscal_(&i__2, &alpha, &a[jcr + ic * a_dim1], lda);
  797. r_cnjg(&q__1, &alpha);
  798. cscal_(n, &q__1, &a[jcr * a_dim1 + 1], &c__1);
  799. /* L60: */
  800. }
  801. } else if (*ku < *n - 1) {
  802. /* Reduce upper bandwidth -- kill a row at a time. */
  803. i__1 = *n - 1;
  804. for (jcr = *ku + 1; jcr <= i__1; ++jcr) {
  805. ir = jcr - *ku;
  806. irows = *n + *ku - jcr;
  807. icols = *n + 1 - jcr;
  808. ccopy_(&icols, &a[ir + jcr * a_dim1], lda, &work[1], &c__1);
  809. xnorms.r = work[1].r, xnorms.i = work[1].i;
  810. clarfg_(&icols, &xnorms, &work[2], &c__1, &tau);
  811. r_cnjg(&q__1, &tau);
  812. tau.r = q__1.r, tau.i = q__1.i;
  813. work[1].r = 1.f, work[1].i = 0.f;
  814. i__2 = icols - 1;
  815. clacgv_(&i__2, &work[2], &c__1);
  816. //clarnd_(&q__1, &c__5, &iseed[1]);
  817. q__1=clarnd_(&c__5, &iseed[1]);
  818. alpha.r = q__1.r, alpha.i = q__1.i;
  819. cgemv_("N", &irows, &icols, &c_b2, &a[ir + 1 + jcr * a_dim1], lda,
  820. &work[1], &c__1, &c_b1, &work[icols + 1], &c__1);
  821. q__1.r = -tau.r, q__1.i = -tau.i;
  822. cgerc_(&irows, &icols, &q__1, &work[icols + 1], &c__1, &work[1], &
  823. c__1, &a[ir + 1 + jcr * a_dim1], lda);
  824. cgemv_("C", &icols, n, &c_b2, &a[jcr + a_dim1], lda, &work[1], &
  825. c__1, &c_b1, &work[icols + 1], &c__1);
  826. r_cnjg(&q__2, &tau);
  827. q__1.r = -q__2.r, q__1.i = -q__2.i;
  828. cgerc_(&icols, n, &q__1, &work[1], &c__1, &work[icols + 1], &c__1,
  829. &a[jcr + a_dim1], lda);
  830. i__2 = ir + jcr * a_dim1;
  831. a[i__2].r = xnorms.r, a[i__2].i = xnorms.i;
  832. i__2 = icols - 1;
  833. claset_("Full", &c__1, &i__2, &c_b1, &c_b1, &a[ir + (jcr + 1) *
  834. a_dim1], lda);
  835. i__2 = irows + 1;
  836. cscal_(&i__2, &alpha, &a[ir + jcr * a_dim1], &c__1);
  837. r_cnjg(&q__1, &alpha);
  838. cscal_(n, &q__1, &a[jcr + a_dim1], lda);
  839. /* L70: */
  840. }
  841. }
  842. /* Scale the matrix to have norm ANORM */
  843. if (*anorm >= 0.f) {
  844. temp = clange_("M", n, n, &a[a_offset], lda, tempa);
  845. if (temp > 0.f) {
  846. ralpha = *anorm / temp;
  847. i__1 = *n;
  848. for (j = 1; j <= i__1; ++j) {
  849. csscal_(n, &ralpha, &a[j * a_dim1 + 1], &c__1);
  850. /* L80: */
  851. }
  852. }
  853. }
  854. return;
  855. /* End of CLATME */
  856. } /* clatme_ */