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.

dlatme.c 32 kB

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