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.

slatme.c 31 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  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 integer c__1 = 1;
  240. static real c_b23 = 0.f;
  241. static integer c__0 = 0;
  242. static real c_b39 = 1.f;
  243. /* > \brief \b SLATME */
  244. /* =========== DOCUMENTATION =========== */
  245. /* Online html documentation available at */
  246. /* http://www.netlib.org/lapack/explore-html/ */
  247. /* Definition: */
  248. /* =========== */
  249. /* SUBROUTINE SLATME( N, DIST, ISEED, D, MODE, COND, DMAX, EI, */
  250. /* RSIGN, */
  251. /* UPPER, SIM, DS, MODES, CONDS, KL, KU, ANORM, */
  252. /* A, */
  253. /* LDA, WORK, INFO ) */
  254. /* CHARACTER DIST, RSIGN, SIM, UPPER */
  255. /* INTEGER INFO, KL, KU, LDA, MODE, MODES, N */
  256. /* REAL ANORM, COND, CONDS, DMAX */
  257. /* CHARACTER EI( * ) */
  258. /* INTEGER ISEED( 4 ) */
  259. /* REAL A( LDA, * ), D( * ), DS( * ), WORK( * ) */
  260. /* > \par Purpose: */
  261. /* ============= */
  262. /* > */
  263. /* > \verbatim */
  264. /* > */
  265. /* > SLATME generates random non-symmetric square matrices with */
  266. /* > specified eigenvalues for testing LAPACK programs. */
  267. /* > */
  268. /* > SLATME operates by applying the following sequence of */
  269. /* > operations: */
  270. /* > */
  271. /* > 1. Set the diagonal to D, where D may be input or */
  272. /* > computed according to MODE, COND, DMAX, and RSIGN */
  273. /* > as described below. */
  274. /* > */
  275. /* > 2. If complex conjugate pairs are desired (MODE=0 and EI(1)='R', */
  276. /* > or MODE=5), certain pairs of adjacent elements of D are */
  277. /* > interpreted as the real and complex parts of a complex */
  278. /* > conjugate pair; A thus becomes block diagonal, with 1x1 */
  279. /* > and 2x2 blocks. */
  280. /* > */
  281. /* > 3. If UPPER='T', the upper triangle of A is set to random values */
  282. /* > out of distribution DIST. */
  283. /* > */
  284. /* > 4. If SIM='T', A is multiplied on the left by a random matrix */
  285. /* > X, whose singular values are specified by DS, MODES, and */
  286. /* > CONDS, and on the right by X inverse. */
  287. /* > */
  288. /* > 5. If KL < N-1, the lower bandwidth is reduced to KL using */
  289. /* > Householder transformations. If KU < N-1, the upper */
  290. /* > bandwidth is reduced to KU. */
  291. /* > */
  292. /* > 6. If ANORM is not negative, the matrix is scaled to have */
  293. /* > maximum-element-norm ANORM. */
  294. /* > */
  295. /* > (Note: since the matrix cannot be reduced beyond Hessenberg form, */
  296. /* > no packing options are available.) */
  297. /* > \endverbatim */
  298. /* Arguments: */
  299. /* ========== */
  300. /* > \param[in] N */
  301. /* > \verbatim */
  302. /* > N is INTEGER */
  303. /* > The number of columns (or rows) of A. Not modified. */
  304. /* > \endverbatim */
  305. /* > */
  306. /* > \param[in] DIST */
  307. /* > \verbatim */
  308. /* > DIST is CHARACTER*1 */
  309. /* > On entry, DIST specifies the type of distribution to be used */
  310. /* > to generate the random eigen-/singular values, and for the */
  311. /* > upper triangle (see UPPER). */
  312. /* > 'U' => UNIFORM( 0, 1 ) ( 'U' for uniform ) */
  313. /* > 'S' => UNIFORM( -1, 1 ) ( 'S' for symmetric ) */
  314. /* > 'N' => NORMAL( 0, 1 ) ( 'N' for normal ) */
  315. /* > Not modified. */
  316. /* > \endverbatim */
  317. /* > */
  318. /* > \param[in,out] ISEED */
  319. /* > \verbatim */
  320. /* > ISEED is INTEGER array, dimension ( 4 ) */
  321. /* > On entry ISEED specifies the seed of the random number */
  322. /* > generator. They should lie between 0 and 4095 inclusive, */
  323. /* > and ISEED(4) should be odd. The random number generator */
  324. /* > uses a linear congruential sequence limited to small */
  325. /* > integers, and so should produce machine independent */
  326. /* > random numbers. The values of ISEED are changed on */
  327. /* > exit, and can be used in the next call to SLATME */
  328. /* > to continue the same random number sequence. */
  329. /* > Changed on exit. */
  330. /* > \endverbatim */
  331. /* > */
  332. /* > \param[in,out] D */
  333. /* > \verbatim */
  334. /* > D is REAL array, dimension ( N ) */
  335. /* > This array is used to specify the eigenvalues of A. If */
  336. /* > MODE=0, then D is assumed to contain the eigenvalues (but */
  337. /* > see the description of EI), otherwise they will be */
  338. /* > computed according to MODE, COND, DMAX, and RSIGN and */
  339. /* > placed in D. */
  340. /* > Modified if MODE is nonzero. */
  341. /* > \endverbatim */
  342. /* > */
  343. /* > \param[in] MODE */
  344. /* > \verbatim */
  345. /* > MODE is INTEGER */
  346. /* > On entry this describes how the eigenvalues are to */
  347. /* > be specified: */
  348. /* > MODE = 0 means use D (with EI) as input */
  349. /* > MODE = 1 sets D(1)=1 and D(2:N)=1.0/COND */
  350. /* > MODE = 2 sets D(1:N-1)=1 and D(N)=1.0/COND */
  351. /* > MODE = 3 sets D(I)=COND**(-(I-1)/(N-1)) */
  352. /* > MODE = 4 sets D(i)=1 - (i-1)/(N-1)*(1 - 1/COND) */
  353. /* > MODE = 5 sets D to random numbers in the range */
  354. /* > ( 1/COND , 1 ) such that their logarithms */
  355. /* > are uniformly distributed. Each odd-even pair */
  356. /* > of elements will be either used as two real */
  357. /* > eigenvalues or as the real and imaginary part */
  358. /* > of a complex conjugate pair of eigenvalues; */
  359. /* > the choice of which is done is random, with */
  360. /* > 50-50 probability, for each pair. */
  361. /* > MODE = 6 set D to random numbers from same distribution */
  362. /* > as the rest of the matrix. */
  363. /* > MODE < 0 has the same meaning as ABS(MODE), except that */
  364. /* > the order of the elements of D is reversed. */
  365. /* > Thus if MODE is between 1 and 4, D has entries ranging */
  366. /* > from 1 to 1/COND, if between -1 and -4, D has entries */
  367. /* > ranging from 1/COND to 1, */
  368. /* > Not modified. */
  369. /* > \endverbatim */
  370. /* > */
  371. /* > \param[in] COND */
  372. /* > \verbatim */
  373. /* > COND is REAL */
  374. /* > On entry, this is used as described under MODE above. */
  375. /* > If used, it must be >= 1. Not modified. */
  376. /* > \endverbatim */
  377. /* > */
  378. /* > \param[in] DMAX */
  379. /* > \verbatim */
  380. /* > DMAX is REAL */
  381. /* > If MODE is neither -6, 0 nor 6, the contents of D, as */
  382. /* > computed according to MODE and COND, will be scaled by */
  383. /* > DMAX / f2cmax(abs(D(i))). Note that DMAX need not be */
  384. /* > positive: if DMAX is negative (or zero), D will be */
  385. /* > scaled by a negative number (or zero). */
  386. /* > Not modified. */
  387. /* > \endverbatim */
  388. /* > */
  389. /* > \param[in] EI */
  390. /* > \verbatim */
  391. /* > EI is CHARACTER*1 array, dimension ( N ) */
  392. /* > If MODE is 0, and EI(1) is not ' ' (space character), */
  393. /* > this array specifies which elements of D (on input) are */
  394. /* > real eigenvalues and which are the real and imaginary parts */
  395. /* > of a complex conjugate pair of eigenvalues. The elements */
  396. /* > of EI may then only have the values 'R' and 'I'. If */
  397. /* > EI(j)='R' and EI(j+1)='I', then the j-th eigenvalue is */
  398. /* > CMPLX( D(j) , D(j+1) ), and the (j+1)-th is the complex */
  399. /* > conjugate thereof. If EI(j)=EI(j+1)='R', then the j-th */
  400. /* > eigenvalue is D(j) (i.e., real). EI(1) may not be 'I', */
  401. /* > nor may two adjacent elements of EI both have the value 'I'. */
  402. /* > If MODE is not 0, then EI is ignored. If MODE is 0 and */
  403. /* > EI(1)=' ', then the eigenvalues will all be real. */
  404. /* > Not modified. */
  405. /* > \endverbatim */
  406. /* > */
  407. /* > \param[in] RSIGN */
  408. /* > \verbatim */
  409. /* > RSIGN is CHARACTER*1 */
  410. /* > If MODE is not 0, 6, or -6, and RSIGN='T', then the */
  411. /* > elements of D, as computed according to MODE and COND, will */
  412. /* > be multiplied by a random sign (+1 or -1). If RSIGN='F', */
  413. /* > they will not be. RSIGN may only have the values 'T' or */
  414. /* > 'F'. */
  415. /* > Not modified. */
  416. /* > \endverbatim */
  417. /* > */
  418. /* > \param[in] UPPER */
  419. /* > \verbatim */
  420. /* > UPPER is CHARACTER*1 */
  421. /* > If UPPER='T', then the elements of A above the diagonal */
  422. /* > (and above the 2x2 diagonal blocks, if A has complex */
  423. /* > eigenvalues) will be set to random numbers out of DIST. */
  424. /* > If UPPER='F', they will not. UPPER may only have the */
  425. /* > values 'T' or 'F'. */
  426. /* > Not modified. */
  427. /* > \endverbatim */
  428. /* > */
  429. /* > \param[in] SIM */
  430. /* > \verbatim */
  431. /* > SIM is CHARACTER*1 */
  432. /* > If SIM='T', then A will be operated on by a "similarity */
  433. /* > transform", i.e., multiplied on the left by a matrix X and */
  434. /* > on the right by X inverse. X = U S V, where U and V are */
  435. /* > random unitary matrices and S is a (diagonal) matrix of */
  436. /* > singular values specified by DS, MODES, and CONDS. If */
  437. /* > SIM='F', then A will not be transformed. */
  438. /* > Not modified. */
  439. /* > \endverbatim */
  440. /* > */
  441. /* > \param[in,out] DS */
  442. /* > \verbatim */
  443. /* > DS is REAL array, dimension ( N ) */
  444. /* > This array is used to specify the singular values of X, */
  445. /* > in the same way that D specifies the eigenvalues of A. */
  446. /* > If MODE=0, the DS contains the singular values, which */
  447. /* > may not be zero. */
  448. /* > Modified if MODE is nonzero. */
  449. /* > \endverbatim */
  450. /* > */
  451. /* > \param[in] MODES */
  452. /* > \verbatim */
  453. /* > MODES is INTEGER */
  454. /* > \endverbatim */
  455. /* > */
  456. /* > \param[in] CONDS */
  457. /* > \verbatim */
  458. /* > CONDS is REAL */
  459. /* > Same as MODE and COND, but for specifying the diagonal */
  460. /* > of S. MODES=-6 and +6 are not allowed (since they would */
  461. /* > result in randomly ill-conditioned eigenvalues.) */
  462. /* > \endverbatim */
  463. /* > */
  464. /* > \param[in] KL */
  465. /* > \verbatim */
  466. /* > KL is INTEGER */
  467. /* > This specifies the lower bandwidth of the matrix. KL=1 */
  468. /* > specifies upper Hessenberg form. If KL is at least N-1, */
  469. /* > then A will have full lower bandwidth. KL must be at */
  470. /* > least 1. */
  471. /* > Not modified. */
  472. /* > \endverbatim */
  473. /* > */
  474. /* > \param[in] KU */
  475. /* > \verbatim */
  476. /* > KU is INTEGER */
  477. /* > This specifies the upper bandwidth of the matrix. KU=1 */
  478. /* > specifies lower Hessenberg form. If KU is at least N-1, */
  479. /* > then A will have full upper bandwidth; if KU and KL */
  480. /* > are both at least N-1, then A will be dense. Only one of */
  481. /* > KU and KL may be less than N-1. KU must be at least 1. */
  482. /* > Not modified. */
  483. /* > \endverbatim */
  484. /* > */
  485. /* > \param[in] ANORM */
  486. /* > \verbatim */
  487. /* > ANORM is REAL */
  488. /* > If ANORM is not negative, then A will be scaled by a non- */
  489. /* > negative real number to make the maximum-element-norm of A */
  490. /* > to be ANORM. */
  491. /* > Not modified. */
  492. /* > \endverbatim */
  493. /* > */
  494. /* > \param[out] A */
  495. /* > \verbatim */
  496. /* > A is REAL array, dimension ( LDA, N ) */
  497. /* > On exit A is the desired test matrix. */
  498. /* > Modified. */
  499. /* > \endverbatim */
  500. /* > */
  501. /* > \param[in] LDA */
  502. /* > \verbatim */
  503. /* > LDA is INTEGER */
  504. /* > LDA specifies the first dimension of A as declared in the */
  505. /* > calling program. LDA must be at least N. */
  506. /* > Not modified. */
  507. /* > \endverbatim */
  508. /* > */
  509. /* > \param[out] WORK */
  510. /* > \verbatim */
  511. /* > WORK is REAL array, dimension ( 3*N ) */
  512. /* > Workspace. */
  513. /* > Modified. */
  514. /* > \endverbatim */
  515. /* > */
  516. /* > \param[out] INFO */
  517. /* > \verbatim */
  518. /* > INFO is INTEGER */
  519. /* > Error code. On exit, INFO will be set to one of the */
  520. /* > following values: */
  521. /* > 0 => normal return */
  522. /* > -1 => N negative */
  523. /* > -2 => DIST illegal string */
  524. /* > -5 => MODE not in range -6 to 6 */
  525. /* > -6 => COND less than 1.0, and MODE neither -6, 0 nor 6 */
  526. /* > -8 => EI(1) is not ' ' or 'R', EI(j) is not 'R' or 'I', or */
  527. /* > two adjacent elements of EI are 'I'. */
  528. /* > -9 => RSIGN is not 'T' or 'F' */
  529. /* > -10 => UPPER is not 'T' or 'F' */
  530. /* > -11 => SIM is not 'T' or 'F' */
  531. /* > -12 => MODES=0 and DS has a zero singular value. */
  532. /* > -13 => MODES is not in the range -5 to 5. */
  533. /* > -14 => MODES is nonzero and CONDS is less than 1. */
  534. /* > -15 => KL is less than 1. */
  535. /* > -16 => KU is less than 1, or KL and KU are both less than */
  536. /* > N-1. */
  537. /* > -19 => LDA is less than N. */
  538. /* > 1 => Error return from SLATM1 (computing D) */
  539. /* > 2 => Cannot scale to DMAX (f2cmax. eigenvalue is 0) */
  540. /* > 3 => Error return from SLATM1 (computing DS) */
  541. /* > 4 => Error return from SLARGE */
  542. /* > 5 => Zero singular value from SLATM1. */
  543. /* > \endverbatim */
  544. /* Authors: */
  545. /* ======== */
  546. /* > \author Univ. of Tennessee */
  547. /* > \author Univ. of California Berkeley */
  548. /* > \author Univ. of Colorado Denver */
  549. /* > \author NAG Ltd. */
  550. /* > \date December 2016 */
  551. /* > \ingroup real_matgen */
  552. /* ===================================================================== */
  553. /* Subroutine */ void slatme_(integer *n, char *dist, integer *iseed, real *
  554. d__, integer *mode, real *cond, real *dmax__, char *ei, char *rsign,
  555. char *upper, char *sim, real *ds, integer *modes, real *conds,
  556. integer *kl, integer *ku, real *anorm, real *a, integer *lda, real *
  557. work, integer *info)
  558. {
  559. /* System generated locals */
  560. integer a_dim1, a_offset, i__1, i__2;
  561. real r__1, r__2, r__3;
  562. /* Local variables */
  563. logical bads;
  564. extern /* Subroutine */ void sger_(integer *, integer *, real *, real *,
  565. integer *, real *, integer *, real *, integer *);
  566. integer isim;
  567. real temp;
  568. logical badei;
  569. integer i__, j;
  570. real alpha;
  571. extern logical lsame_(char *, char *);
  572. integer iinfo;
  573. extern /* Subroutine */ void sscal_(integer *, real *, real *, integer *);
  574. real tempa[1];
  575. integer icols;
  576. logical useei;
  577. integer idist;
  578. extern /* Subroutine */ void sgemv_(char *, integer *, integer *, real *,
  579. real *, integer *, real *, integer *, real *, real *, integer *), scopy_(integer *, real *, integer *, real *, integer *);
  580. integer irows;
  581. extern /* Subroutine */ void slatm1_(integer *, real *, integer *, integer
  582. *, integer *, real *, integer *, integer *);
  583. integer ic, jc, ir, jr;
  584. extern real slange_(char *, integer *, integer *, real *, integer *, real
  585. *);
  586. extern /* Subroutine */ void slarge_(integer *, real *, integer *, integer
  587. *, real *, integer *), slarfg_(integer *, real *, real *, integer
  588. *, real *);
  589. extern int xerbla_(char *, integer *, ftnlen);
  590. extern real slaran_(integer *);
  591. integer irsign;
  592. extern /* Subroutine */ void slaset_(char *, integer *, integer *, real *,
  593. real *, real *, integer *);
  594. integer iupper;
  595. extern /* Subroutine */ void slarnv_(integer *, integer *, integer *, real
  596. *);
  597. real xnorms;
  598. integer jcr;
  599. real tau;
  600. /* -- LAPACK computational routine (version 3.7.0) -- */
  601. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  602. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  603. /* December 2016 */
  604. /* ===================================================================== */
  605. /* 1) Decode and Test the input parameters. */
  606. /* Initialize flags & seed. */
  607. /* Parameter adjustments */
  608. --iseed;
  609. --d__;
  610. --ei;
  611. --ds;
  612. a_dim1 = *lda;
  613. a_offset = 1 + a_dim1 * 1;
  614. a -= a_offset;
  615. --work;
  616. /* Function Body */
  617. *info = 0;
  618. /* Quick return if possible */
  619. if (*n == 0) {
  620. return;
  621. }
  622. /* Decode DIST */
  623. if (lsame_(dist, "U")) {
  624. idist = 1;
  625. } else if (lsame_(dist, "S")) {
  626. idist = 2;
  627. } else if (lsame_(dist, "N")) {
  628. idist = 3;
  629. } else {
  630. idist = -1;
  631. }
  632. /* Check EI */
  633. useei = TRUE_;
  634. badei = FALSE_;
  635. if (lsame_(ei + 1, " ") || *mode != 0) {
  636. useei = FALSE_;
  637. } else {
  638. if (lsame_(ei + 1, "R")) {
  639. i__1 = *n;
  640. for (j = 2; j <= i__1; ++j) {
  641. if (lsame_(ei + j, "I")) {
  642. if (lsame_(ei + (j - 1), "I")) {
  643. badei = TRUE_;
  644. }
  645. } else {
  646. if (! lsame_(ei + j, "R")) {
  647. badei = TRUE_;
  648. }
  649. }
  650. /* L10: */
  651. }
  652. } else {
  653. badei = TRUE_;
  654. }
  655. }
  656. /* Decode RSIGN */
  657. if (lsame_(rsign, "T")) {
  658. irsign = 1;
  659. } else if (lsame_(rsign, "F")) {
  660. irsign = 0;
  661. } else {
  662. irsign = -1;
  663. }
  664. /* Decode UPPER */
  665. if (lsame_(upper, "T")) {
  666. iupper = 1;
  667. } else if (lsame_(upper, "F")) {
  668. iupper = 0;
  669. } else {
  670. iupper = -1;
  671. }
  672. /* Decode SIM */
  673. if (lsame_(sim, "T")) {
  674. isim = 1;
  675. } else if (lsame_(sim, "F")) {
  676. isim = 0;
  677. } else {
  678. isim = -1;
  679. }
  680. /* Check DS, if MODES=0 and ISIM=1 */
  681. bads = FALSE_;
  682. if (*modes == 0 && isim == 1) {
  683. i__1 = *n;
  684. for (j = 1; j <= i__1; ++j) {
  685. if (ds[j] == 0.f) {
  686. bads = TRUE_;
  687. }
  688. /* L20: */
  689. }
  690. }
  691. /* Set INFO if an error */
  692. if (*n < 0) {
  693. *info = -1;
  694. } else if (idist == -1) {
  695. *info = -2;
  696. } else if (abs(*mode) > 6) {
  697. *info = -5;
  698. } else if (*mode != 0 && abs(*mode) != 6 && *cond < 1.f) {
  699. *info = -6;
  700. } else if (badei) {
  701. *info = -8;
  702. } else if (irsign == -1) {
  703. *info = -9;
  704. } else if (iupper == -1) {
  705. *info = -10;
  706. } else if (isim == -1) {
  707. *info = -11;
  708. } else if (bads) {
  709. *info = -12;
  710. } else if (isim == 1 && abs(*modes) > 5) {
  711. *info = -13;
  712. } else if (isim == 1 && *modes != 0 && *conds < 1.f) {
  713. *info = -14;
  714. } else if (*kl < 1) {
  715. *info = -15;
  716. } else if (*ku < 1 || *ku < *n - 1 && *kl < *n - 1) {
  717. *info = -16;
  718. } else if (*lda < f2cmax(1,*n)) {
  719. *info = -19;
  720. }
  721. if (*info != 0) {
  722. i__1 = -(*info);
  723. xerbla_("SLATME", &i__1, 6);
  724. return;
  725. }
  726. /* Initialize random number generator */
  727. for (i__ = 1; i__ <= 4; ++i__) {
  728. iseed[i__] = (i__1 = iseed[i__], abs(i__1)) % 4096;
  729. /* L30: */
  730. }
  731. if (iseed[4] % 2 != 1) {
  732. ++iseed[4];
  733. }
  734. /* 2) Set up diagonal of A */
  735. /* Compute D according to COND and MODE */
  736. slatm1_(mode, cond, &irsign, &idist, &iseed[1], &d__[1], n, &iinfo);
  737. if (iinfo != 0) {
  738. *info = 1;
  739. return;
  740. }
  741. if (*mode != 0 && abs(*mode) != 6) {
  742. /* Scale by DMAX */
  743. temp = abs(d__[1]);
  744. i__1 = *n;
  745. for (i__ = 2; i__ <= i__1; ++i__) {
  746. /* Computing MAX */
  747. r__2 = temp, r__3 = (r__1 = d__[i__], abs(r__1));
  748. temp = f2cmax(r__2,r__3);
  749. /* L40: */
  750. }
  751. if (temp > 0.f) {
  752. alpha = *dmax__ / temp;
  753. } else if (*dmax__ != 0.f) {
  754. *info = 2;
  755. return;
  756. } else {
  757. alpha = 0.f;
  758. }
  759. sscal_(n, &alpha, &d__[1], &c__1);
  760. }
  761. slaset_("Full", n, n, &c_b23, &c_b23, &a[a_offset], lda);
  762. i__1 = *lda + 1;
  763. scopy_(n, &d__[1], &c__1, &a[a_offset], &i__1);
  764. /* Set up complex conjugate pairs */
  765. if (*mode == 0) {
  766. if (useei) {
  767. i__1 = *n;
  768. for (j = 2; j <= i__1; ++j) {
  769. if (lsame_(ei + j, "I")) {
  770. a[j - 1 + j * a_dim1] = a[j + j * a_dim1];
  771. a[j + (j - 1) * a_dim1] = -a[j + j * a_dim1];
  772. a[j + j * a_dim1] = a[j - 1 + (j - 1) * a_dim1];
  773. }
  774. /* L50: */
  775. }
  776. }
  777. } else if (abs(*mode) == 5) {
  778. i__1 = *n;
  779. for (j = 2; j <= i__1; j += 2) {
  780. if (slaran_(&iseed[1]) > .5f) {
  781. a[j - 1 + j * a_dim1] = a[j + j * a_dim1];
  782. a[j + (j - 1) * a_dim1] = -a[j + j * a_dim1];
  783. a[j + j * a_dim1] = a[j - 1 + (j - 1) * a_dim1];
  784. }
  785. /* L60: */
  786. }
  787. }
  788. /* 3) If UPPER='T', set upper triangle of A to random numbers. */
  789. /* (but don't modify the corners of 2x2 blocks.) */
  790. if (iupper != 0) {
  791. i__1 = *n;
  792. for (jc = 2; jc <= i__1; ++jc) {
  793. if (a[jc - 1 + jc * a_dim1] != 0.f) {
  794. jr = jc - 2;
  795. } else {
  796. jr = jc - 1;
  797. }
  798. slarnv_(&idist, &iseed[1], &jr, &a[jc * a_dim1 + 1]);
  799. /* L70: */
  800. }
  801. }
  802. /* 4) If SIM='T', apply similarity transformation. */
  803. /* -1 */
  804. /* Transform is X A X , where X = U S V, thus */
  805. /* it is U S V A V' (1/S) U' */
  806. if (isim != 0) {
  807. /* Compute S (singular values of the eigenvector matrix) */
  808. /* according to CONDS and MODES */
  809. slatm1_(modes, conds, &c__0, &c__0, &iseed[1], &ds[1], n, &iinfo);
  810. if (iinfo != 0) {
  811. *info = 3;
  812. return;
  813. }
  814. /* Multiply by V and V' */
  815. slarge_(n, &a[a_offset], lda, &iseed[1], &work[1], &iinfo);
  816. if (iinfo != 0) {
  817. *info = 4;
  818. return;
  819. }
  820. /* Multiply by S and (1/S) */
  821. i__1 = *n;
  822. for (j = 1; j <= i__1; ++j) {
  823. sscal_(n, &ds[j], &a[j + a_dim1], lda);
  824. if (ds[j] != 0.f) {
  825. r__1 = 1.f / ds[j];
  826. sscal_(n, &r__1, &a[j * a_dim1 + 1], &c__1);
  827. } else {
  828. *info = 5;
  829. return;
  830. }
  831. /* L80: */
  832. }
  833. /* Multiply by U and U' */
  834. slarge_(n, &a[a_offset], lda, &iseed[1], &work[1], &iinfo);
  835. if (iinfo != 0) {
  836. *info = 4;
  837. return;
  838. }
  839. }
  840. /* 5) Reduce the bandwidth. */
  841. if (*kl < *n - 1) {
  842. /* Reduce bandwidth -- kill column */
  843. i__1 = *n - 1;
  844. for (jcr = *kl + 1; jcr <= i__1; ++jcr) {
  845. ic = jcr - *kl;
  846. irows = *n + 1 - jcr;
  847. icols = *n + *kl - jcr;
  848. scopy_(&irows, &a[jcr + ic * a_dim1], &c__1, &work[1], &c__1);
  849. xnorms = work[1];
  850. slarfg_(&irows, &xnorms, &work[2], &c__1, &tau);
  851. work[1] = 1.f;
  852. sgemv_("T", &irows, &icols, &c_b39, &a[jcr + (ic + 1) * a_dim1],
  853. lda, &work[1], &c__1, &c_b23, &work[irows + 1], &c__1);
  854. r__1 = -tau;
  855. sger_(&irows, &icols, &r__1, &work[1], &c__1, &work[irows + 1], &
  856. c__1, &a[jcr + (ic + 1) * a_dim1], lda);
  857. sgemv_("N", n, &irows, &c_b39, &a[jcr * a_dim1 + 1], lda, &work[1]
  858. , &c__1, &c_b23, &work[irows + 1], &c__1);
  859. r__1 = -tau;
  860. sger_(n, &irows, &r__1, &work[irows + 1], &c__1, &work[1], &c__1,
  861. &a[jcr * a_dim1 + 1], lda);
  862. a[jcr + ic * a_dim1] = xnorms;
  863. i__2 = irows - 1;
  864. slaset_("Full", &i__2, &c__1, &c_b23, &c_b23, &a[jcr + 1 + ic *
  865. a_dim1], lda);
  866. /* L90: */
  867. }
  868. } else if (*ku < *n - 1) {
  869. /* Reduce upper bandwidth -- kill a row at a time. */
  870. i__1 = *n - 1;
  871. for (jcr = *ku + 1; jcr <= i__1; ++jcr) {
  872. ir = jcr - *ku;
  873. irows = *n + *ku - jcr;
  874. icols = *n + 1 - jcr;
  875. scopy_(&icols, &a[ir + jcr * a_dim1], lda, &work[1], &c__1);
  876. xnorms = work[1];
  877. slarfg_(&icols, &xnorms, &work[2], &c__1, &tau);
  878. work[1] = 1.f;
  879. sgemv_("N", &irows, &icols, &c_b39, &a[ir + 1 + jcr * a_dim1],
  880. lda, &work[1], &c__1, &c_b23, &work[icols + 1], &c__1);
  881. r__1 = -tau;
  882. sger_(&irows, &icols, &r__1, &work[icols + 1], &c__1, &work[1], &
  883. c__1, &a[ir + 1 + jcr * a_dim1], lda);
  884. sgemv_("C", &icols, n, &c_b39, &a[jcr + a_dim1], lda, &work[1], &
  885. c__1, &c_b23, &work[icols + 1], &c__1);
  886. r__1 = -tau;
  887. sger_(&icols, n, &r__1, &work[1], &c__1, &work[icols + 1], &c__1,
  888. &a[jcr + a_dim1], lda);
  889. a[ir + jcr * a_dim1] = xnorms;
  890. i__2 = icols - 1;
  891. slaset_("Full", &c__1, &i__2, &c_b23, &c_b23, &a[ir + (jcr + 1) *
  892. a_dim1], lda);
  893. /* L100: */
  894. }
  895. }
  896. /* Scale the matrix to have norm ANORM */
  897. if (*anorm >= 0.f) {
  898. temp = slange_("M", n, n, &a[a_offset], lda, tempa);
  899. if (temp > 0.f) {
  900. alpha = *anorm / temp;
  901. i__1 = *n;
  902. for (j = 1; j <= i__1; ++j) {
  903. sscal_(n, &alpha, &a[j * a_dim1 + 1], &c__1);
  904. /* L110: */
  905. }
  906. }
  907. }
  908. return;
  909. /* End of SLATME */
  910. } /* slatme_ */