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.

dlatms.c 48 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647
  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 doublereal c_b22 = 0.;
  241. static logical c_true = TRUE_;
  242. static logical c_false = FALSE_;
  243. /* > \brief \b DLATMS */
  244. /* =========== DOCUMENTATION =========== */
  245. /* Online html documentation available at */
  246. /* http://www.netlib.org/lapack/explore-html/ */
  247. /* Definition: */
  248. /* =========== */
  249. /* SUBROUTINE DLATMS( M, N, DIST, ISEED, SYM, D, MODE, COND, DMAX, */
  250. /* KL, KU, PACK, A, LDA, WORK, INFO ) */
  251. /* CHARACTER DIST, PACK, SYM */
  252. /* INTEGER INFO, KL, KU, LDA, M, MODE, N */
  253. /* DOUBLE PRECISION COND, DMAX */
  254. /* INTEGER ISEED( 4 ) */
  255. /* DOUBLE PRECISION A( LDA, * ), D( * ), WORK( * ) */
  256. /* > \par Purpose: */
  257. /* ============= */
  258. /* > */
  259. /* > \verbatim */
  260. /* > */
  261. /* > DLATMS generates random matrices with specified singular values */
  262. /* > (or symmetric/hermitian with specified eigenvalues) */
  263. /* > for testing LAPACK programs. */
  264. /* > */
  265. /* > DLATMS operates by applying the following sequence of */
  266. /* > operations: */
  267. /* > */
  268. /* > Set the diagonal to D, where D may be input or */
  269. /* > computed according to MODE, COND, DMAX, and SYM */
  270. /* > as described below. */
  271. /* > */
  272. /* > Generate a matrix with the appropriate band structure, by one */
  273. /* > of two methods: */
  274. /* > */
  275. /* > Method A: */
  276. /* > Generate a dense M x N matrix by multiplying D on the left */
  277. /* > and the right by random unitary matrices, then: */
  278. /* > */
  279. /* > Reduce the bandwidth according to KL and KU, using */
  280. /* > Householder transformations. */
  281. /* > */
  282. /* > Method B: */
  283. /* > Convert the bandwidth-0 (i.e., diagonal) matrix to a */
  284. /* > bandwidth-1 matrix using Givens rotations, "chasing" */
  285. /* > out-of-band elements back, much as in QR; then */
  286. /* > convert the bandwidth-1 to a bandwidth-2 matrix, etc. */
  287. /* > Note that for reasonably small bandwidths (relative to */
  288. /* > M and N) this requires less storage, as a dense matrix */
  289. /* > is not generated. Also, for symmetric matrices, only */
  290. /* > one triangle is generated. */
  291. /* > */
  292. /* > Method A is chosen if the bandwidth is a large fraction of the */
  293. /* > order of the matrix, and LDA is at least M (so a dense */
  294. /* > matrix can be stored.) Method B is chosen if the bandwidth */
  295. /* > is small (< 1/2 N for symmetric, < .3 N+M for */
  296. /* > non-symmetric), or LDA is less than M and not less than the */
  297. /* > bandwidth. */
  298. /* > */
  299. /* > Pack the matrix if desired. Options specified by PACK are: */
  300. /* > no packing */
  301. /* > zero out upper half (if symmetric) */
  302. /* > zero out lower half (if symmetric) */
  303. /* > store the upper half columnwise (if symmetric or upper */
  304. /* > triangular) */
  305. /* > store the lower half columnwise (if symmetric or lower */
  306. /* > triangular) */
  307. /* > store the lower triangle in banded format (if symmetric */
  308. /* > or lower triangular) */
  309. /* > store the upper triangle in banded format (if symmetric */
  310. /* > or upper triangular) */
  311. /* > store the entire matrix in banded format */
  312. /* > If Method B is chosen, and band format is specified, then the */
  313. /* > matrix will be generated in the band format, so no repacking */
  314. /* > will be necessary. */
  315. /* > \endverbatim */
  316. /* Arguments: */
  317. /* ========== */
  318. /* > \param[in] M */
  319. /* > \verbatim */
  320. /* > M is INTEGER */
  321. /* > The number of rows of A. Not modified. */
  322. /* > \endverbatim */
  323. /* > */
  324. /* > \param[in] N */
  325. /* > \verbatim */
  326. /* > N is INTEGER */
  327. /* > The number of columns of A. Not modified. */
  328. /* > \endverbatim */
  329. /* > */
  330. /* > \param[in] DIST */
  331. /* > \verbatim */
  332. /* > DIST is CHARACTER*1 */
  333. /* > On entry, DIST specifies the type of distribution to be used */
  334. /* > to generate the random eigen-/singular values. */
  335. /* > 'U' => UNIFORM( 0, 1 ) ( 'U' for uniform ) */
  336. /* > 'S' => UNIFORM( -1, 1 ) ( 'S' for symmetric ) */
  337. /* > 'N' => NORMAL( 0, 1 ) ( 'N' for normal ) */
  338. /* > Not modified. */
  339. /* > \endverbatim */
  340. /* > */
  341. /* > \param[in,out] ISEED */
  342. /* > \verbatim */
  343. /* > ISEED is INTEGER array, dimension ( 4 ) */
  344. /* > On entry ISEED specifies the seed of the random number */
  345. /* > generator. They should lie between 0 and 4095 inclusive, */
  346. /* > and ISEED(4) should be odd. The random number generator */
  347. /* > uses a linear congruential sequence limited to small */
  348. /* > integers, and so should produce machine independent */
  349. /* > random numbers. The values of ISEED are changed on */
  350. /* > exit, and can be used in the next call to DLATMS */
  351. /* > to continue the same random number sequence. */
  352. /* > Changed on exit. */
  353. /* > \endverbatim */
  354. /* > */
  355. /* > \param[in] SYM */
  356. /* > \verbatim */
  357. /* > SYM is CHARACTER*1 */
  358. /* > If SYM='S' or 'H', the generated matrix is symmetric, with */
  359. /* > eigenvalues specified by D, COND, MODE, and DMAX; they */
  360. /* > may be positive, negative, or zero. */
  361. /* > If SYM='P', the generated matrix is symmetric, with */
  362. /* > eigenvalues (= singular values) specified by D, COND, */
  363. /* > MODE, and DMAX; they will not be negative. */
  364. /* > If SYM='N', the generated matrix is nonsymmetric, with */
  365. /* > singular values specified by D, COND, MODE, and DMAX; */
  366. /* > they will not be negative. */
  367. /* > Not modified. */
  368. /* > \endverbatim */
  369. /* > */
  370. /* > \param[in,out] D */
  371. /* > \verbatim */
  372. /* > D is DOUBLE PRECISION array, dimension ( MIN( M , N ) ) */
  373. /* > This array is used to specify the singular values or */
  374. /* > eigenvalues of A (see SYM, above.) If MODE=0, then D is */
  375. /* > assumed to contain the singular/eigenvalues, otherwise */
  376. /* > they will be computed according to MODE, COND, and DMAX, */
  377. /* > and placed in D. */
  378. /* > Modified if MODE is nonzero. */
  379. /* > \endverbatim */
  380. /* > */
  381. /* > \param[in] MODE */
  382. /* > \verbatim */
  383. /* > MODE is INTEGER */
  384. /* > On entry this describes how the singular/eigenvalues are to */
  385. /* > be specified: */
  386. /* > MODE = 0 means use D as input */
  387. /* > MODE = 1 sets D(1)=1 and D(2:N)=1.0/COND */
  388. /* > MODE = 2 sets D(1:N-1)=1 and D(N)=1.0/COND */
  389. /* > MODE = 3 sets D(I)=COND**(-(I-1)/(N-1)) */
  390. /* > MODE = 4 sets D(i)=1 - (i-1)/(N-1)*(1 - 1/COND) */
  391. /* > MODE = 5 sets D to random numbers in the range */
  392. /* > ( 1/COND , 1 ) such that their logarithms */
  393. /* > are uniformly distributed. */
  394. /* > MODE = 6 set D to random numbers from same distribution */
  395. /* > as the rest of the matrix. */
  396. /* > MODE < 0 has the same meaning as ABS(MODE), except that */
  397. /* > the order of the elements of D is reversed. */
  398. /* > Thus if MODE is positive, D has entries ranging from */
  399. /* > 1 to 1/COND, if negative, from 1/COND to 1, */
  400. /* > If SYM='S' or 'H', and MODE is neither 0, 6, nor -6, then */
  401. /* > the elements of D will also be multiplied by a random */
  402. /* > sign (i.e., +1 or -1.) */
  403. /* > Not modified. */
  404. /* > \endverbatim */
  405. /* > */
  406. /* > \param[in] COND */
  407. /* > \verbatim */
  408. /* > COND is DOUBLE PRECISION */
  409. /* > On entry, this is used as described under MODE above. */
  410. /* > If used, it must be >= 1. Not modified. */
  411. /* > \endverbatim */
  412. /* > */
  413. /* > \param[in] DMAX */
  414. /* > \verbatim */
  415. /* > DMAX is DOUBLE PRECISION */
  416. /* > If MODE is neither -6, 0 nor 6, the contents of D, as */
  417. /* > computed according to MODE and COND, will be scaled by */
  418. /* > DMAX / f2cmax(abs(D(i))); thus, the maximum absolute eigen- or */
  419. /* > singular value (which is to say the norm) will be abs(DMAX). */
  420. /* > Note that DMAX need not be positive: if DMAX is negative */
  421. /* > (or zero), D will be scaled by a negative number (or zero). */
  422. /* > Not modified. */
  423. /* > \endverbatim */
  424. /* > */
  425. /* > \param[in] KL */
  426. /* > \verbatim */
  427. /* > KL is INTEGER */
  428. /* > This specifies the lower bandwidth of the matrix. For */
  429. /* > example, KL=0 implies upper triangular, KL=1 implies upper */
  430. /* > Hessenberg, and KL being at least M-1 means that the matrix */
  431. /* > has full lower bandwidth. KL must equal KU if the matrix */
  432. /* > is symmetric. */
  433. /* > Not modified. */
  434. /* > \endverbatim */
  435. /* > */
  436. /* > \param[in] KU */
  437. /* > \verbatim */
  438. /* > KU is INTEGER */
  439. /* > This specifies the upper bandwidth of the matrix. For */
  440. /* > example, KU=0 implies lower triangular, KU=1 implies lower */
  441. /* > Hessenberg, and KU being at least N-1 means that the matrix */
  442. /* > has full upper bandwidth. KL must equal KU if the matrix */
  443. /* > is symmetric. */
  444. /* > Not modified. */
  445. /* > \endverbatim */
  446. /* > */
  447. /* > \param[in] PACK */
  448. /* > \verbatim */
  449. /* > PACK is CHARACTER*1 */
  450. /* > This specifies packing of matrix as follows: */
  451. /* > 'N' => no packing */
  452. /* > 'U' => zero out all subdiagonal entries (if symmetric) */
  453. /* > 'L' => zero out all superdiagonal entries (if symmetric) */
  454. /* > 'C' => store the upper triangle columnwise */
  455. /* > (only if the matrix is symmetric or upper triangular) */
  456. /* > 'R' => store the lower triangle columnwise */
  457. /* > (only if the matrix is symmetric or lower triangular) */
  458. /* > 'B' => store the lower triangle in band storage scheme */
  459. /* > (only if matrix symmetric or lower triangular) */
  460. /* > 'Q' => store the upper triangle in band storage scheme */
  461. /* > (only if matrix symmetric or upper triangular) */
  462. /* > 'Z' => store the entire matrix in band storage scheme */
  463. /* > (pivoting can be provided for by using this */
  464. /* > option to store A in the trailing rows of */
  465. /* > the allocated storage) */
  466. /* > */
  467. /* > Using these options, the various LAPACK packed and banded */
  468. /* > storage schemes can be obtained: */
  469. /* > GB - use 'Z' */
  470. /* > PB, SB or TB - use 'B' or 'Q' */
  471. /* > PP, SP or TP - use 'C' or 'R' */
  472. /* > */
  473. /* > If two calls to DLATMS differ only in the PACK parameter, */
  474. /* > they will generate mathematically equivalent matrices. */
  475. /* > Not modified. */
  476. /* > \endverbatim */
  477. /* > */
  478. /* > \param[in,out] A */
  479. /* > \verbatim */
  480. /* > A is DOUBLE PRECISION array, dimension ( LDA, N ) */
  481. /* > On exit A is the desired test matrix. A is first generated */
  482. /* > in full (unpacked) form, and then packed, if so specified */
  483. /* > by PACK. Thus, the first M elements of the first N */
  484. /* > columns will always be modified. If PACK specifies a */
  485. /* > packed or banded storage scheme, all LDA elements of the */
  486. /* > first N columns will be modified; the elements of the */
  487. /* > array which do not correspond to elements of the generated */
  488. /* > matrix are set to zero. */
  489. /* > Modified. */
  490. /* > \endverbatim */
  491. /* > */
  492. /* > \param[in] LDA */
  493. /* > \verbatim */
  494. /* > LDA is INTEGER */
  495. /* > LDA specifies the first dimension of A as declared in the */
  496. /* > calling program. If PACK='N', 'U', 'L', 'C', or 'R', then */
  497. /* > LDA must be at least M. If PACK='B' or 'Q', then LDA must */
  498. /* > be at least MIN( KL, M-1) (which is equal to MIN(KU,N-1)). */
  499. /* > If PACK='Z', LDA must be large enough to hold the packed */
  500. /* > array: MIN( KU, N-1) + MIN( KL, M-1) + 1. */
  501. /* > Not modified. */
  502. /* > \endverbatim */
  503. /* > */
  504. /* > \param[out] WORK */
  505. /* > \verbatim */
  506. /* > WORK is DOUBLE PRECISION array, dimension ( 3*MAX( N , M ) ) */
  507. /* > Workspace. */
  508. /* > Modified. */
  509. /* > \endverbatim */
  510. /* > */
  511. /* > \param[out] INFO */
  512. /* > \verbatim */
  513. /* > INFO is INTEGER */
  514. /* > Error code. On exit, INFO will be set to one of the */
  515. /* > following values: */
  516. /* > 0 => normal return */
  517. /* > -1 => M negative or unequal to N and SYM='S', 'H', or 'P' */
  518. /* > -2 => N negative */
  519. /* > -3 => DIST illegal string */
  520. /* > -5 => SYM illegal string */
  521. /* > -7 => MODE not in range -6 to 6 */
  522. /* > -8 => COND less than 1.0, and MODE neither -6, 0 nor 6 */
  523. /* > -10 => KL negative */
  524. /* > -11 => KU negative, or SYM='S' or 'H' and KU not equal to KL */
  525. /* > -12 => PACK illegal string, or PACK='U' or 'L', and SYM='N'; */
  526. /* > or PACK='C' or 'Q' and SYM='N' and KL is not zero; */
  527. /* > or PACK='R' or 'B' and SYM='N' and KU is not zero; */
  528. /* > or PACK='U', 'L', 'C', 'R', 'B', or 'Q', and M is not */
  529. /* > N. */
  530. /* > -14 => LDA is less than M, or PACK='Z' and LDA is less than */
  531. /* > MIN(KU,N-1) + MIN(KL,M-1) + 1. */
  532. /* > 1 => Error return from DLATM1 */
  533. /* > 2 => Cannot scale to DMAX (f2cmax. sing. value is 0) */
  534. /* > 3 => Error return from DLAGGE or SLAGSY */
  535. /* > \endverbatim */
  536. /* Authors: */
  537. /* ======== */
  538. /* > \author Univ. of Tennessee */
  539. /* > \author Univ. of California Berkeley */
  540. /* > \author Univ. of Colorado Denver */
  541. /* > \author NAG Ltd. */
  542. /* > \date December 2016 */
  543. /* > \ingroup double_matgen */
  544. /* ===================================================================== */
  545. /* Subroutine */ void dlatms_(integer *m, integer *n, char *dist, integer *
  546. iseed, char *sym, doublereal *d__, integer *mode, doublereal *cond,
  547. doublereal *dmax__, integer *kl, integer *ku, char *pack, doublereal *
  548. a, integer *lda, doublereal *work, integer *info)
  549. {
  550. /* System generated locals */
  551. integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5, i__6;
  552. doublereal d__1, d__2, d__3;
  553. logical L__1;
  554. /* Local variables */
  555. integer ilda, icol;
  556. doublereal temp;
  557. integer irow, isym;
  558. doublereal c__;
  559. integer i__, j, k;
  560. doublereal s, alpha, angle;
  561. integer ipack;
  562. extern /* Subroutine */ void dscal_(integer *, doublereal *, doublereal *,
  563. integer *);
  564. integer ioffg;
  565. extern logical lsame_(char *, char *);
  566. integer iinfo, idist, mnmin;
  567. extern /* Subroutine */ void dcopy_(integer *, doublereal *, integer *,
  568. doublereal *, integer *);
  569. integer iskew;
  570. doublereal extra, dummy;
  571. extern /* Subroutine */ void dlatm1_(integer *, doublereal *, integer *,
  572. integer *, integer *, doublereal *, integer *, integer *);
  573. integer ic, jc, nc;
  574. extern /* Subroutine */ void dlagge_(integer *, integer *, integer *,
  575. integer *, doublereal *, doublereal *, integer *, integer *,
  576. doublereal *, integer *);
  577. integer il, iendch, ir, jr, ipackg, mr, minlda;
  578. extern doublereal dlarnd_(integer *, integer *);
  579. extern /* Subroutine */ void dlaset_(char *, integer *, integer *,
  580. doublereal *, doublereal *, doublereal *, integer *),
  581. dlartg_(doublereal *, doublereal *, doublereal *, doublereal *,
  582. doublereal *);
  583. extern int xerbla_(char *, integer *, ftnlen);
  584. extern void dlagsy_(
  585. integer *, integer *, doublereal *, doublereal *, integer *,
  586. integer *, doublereal *, integer *), dlarot_(logical *, logical *,
  587. logical *, integer *, doublereal *, doublereal *, doublereal *,
  588. integer *, doublereal *, doublereal *);
  589. logical iltemp, givens;
  590. integer ioffst, irsign;
  591. logical ilextr, topdwn;
  592. integer ir1, ir2, isympk, jch, llb, jkl, jku, uub;
  593. /* -- LAPACK computational routine (version 3.7.0) -- */
  594. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  595. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  596. /* December 2016 */
  597. /* ===================================================================== */
  598. /* 1) Decode and Test the input parameters. */
  599. /* Initialize flags & seed. */
  600. /* Parameter adjustments */
  601. --iseed;
  602. --d__;
  603. a_dim1 = *lda;
  604. a_offset = 1 + a_dim1 * 1;
  605. a -= a_offset;
  606. --work;
  607. /* Function Body */
  608. *info = 0;
  609. /* Quick return if possible */
  610. if (*m == 0 || *n == 0) {
  611. return;
  612. }
  613. /* Decode DIST */
  614. if (lsame_(dist, "U")) {
  615. idist = 1;
  616. } else if (lsame_(dist, "S")) {
  617. idist = 2;
  618. } else if (lsame_(dist, "N")) {
  619. idist = 3;
  620. } else {
  621. idist = -1;
  622. }
  623. /* Decode SYM */
  624. if (lsame_(sym, "N")) {
  625. isym = 1;
  626. irsign = 0;
  627. } else if (lsame_(sym, "P")) {
  628. isym = 2;
  629. irsign = 0;
  630. } else if (lsame_(sym, "S")) {
  631. isym = 2;
  632. irsign = 1;
  633. } else if (lsame_(sym, "H")) {
  634. isym = 2;
  635. irsign = 1;
  636. } else {
  637. isym = -1;
  638. }
  639. /* Decode PACK */
  640. isympk = 0;
  641. if (lsame_(pack, "N")) {
  642. ipack = 0;
  643. } else if (lsame_(pack, "U")) {
  644. ipack = 1;
  645. isympk = 1;
  646. } else if (lsame_(pack, "L")) {
  647. ipack = 2;
  648. isympk = 1;
  649. } else if (lsame_(pack, "C")) {
  650. ipack = 3;
  651. isympk = 2;
  652. } else if (lsame_(pack, "R")) {
  653. ipack = 4;
  654. isympk = 3;
  655. } else if (lsame_(pack, "B")) {
  656. ipack = 5;
  657. isympk = 3;
  658. } else if (lsame_(pack, "Q")) {
  659. ipack = 6;
  660. isympk = 2;
  661. } else if (lsame_(pack, "Z")) {
  662. ipack = 7;
  663. } else {
  664. ipack = -1;
  665. }
  666. /* Set certain internal parameters */
  667. mnmin = f2cmin(*m,*n);
  668. /* Computing MIN */
  669. i__1 = *kl, i__2 = *m - 1;
  670. llb = f2cmin(i__1,i__2);
  671. /* Computing MIN */
  672. i__1 = *ku, i__2 = *n - 1;
  673. uub = f2cmin(i__1,i__2);
  674. /* Computing MIN */
  675. i__1 = *m, i__2 = *n + llb;
  676. mr = f2cmin(i__1,i__2);
  677. /* Computing MIN */
  678. i__1 = *n, i__2 = *m + uub;
  679. nc = f2cmin(i__1,i__2);
  680. if (ipack == 5 || ipack == 6) {
  681. minlda = uub + 1;
  682. } else if (ipack == 7) {
  683. minlda = llb + uub + 1;
  684. } else {
  685. minlda = *m;
  686. }
  687. /* Use Givens rotation method if bandwidth small enough, */
  688. /* or if LDA is too small to store the matrix unpacked. */
  689. givens = FALSE_;
  690. if (isym == 1) {
  691. /* Computing MAX */
  692. i__1 = 1, i__2 = mr + nc;
  693. if ((doublereal) (llb + uub) < (doublereal) f2cmax(i__1,i__2) * .3) {
  694. givens = TRUE_;
  695. }
  696. } else {
  697. if (llb << 1 < *m) {
  698. givens = TRUE_;
  699. }
  700. }
  701. if (*lda < *m && *lda >= minlda) {
  702. givens = TRUE_;
  703. }
  704. /* Set INFO if an error */
  705. if (*m < 0) {
  706. *info = -1;
  707. } else if (*m != *n && isym != 1) {
  708. *info = -1;
  709. } else if (*n < 0) {
  710. *info = -2;
  711. } else if (idist == -1) {
  712. *info = -3;
  713. } else if (isym == -1) {
  714. *info = -5;
  715. } else if (abs(*mode) > 6) {
  716. *info = -7;
  717. } else if (*mode != 0 && abs(*mode) != 6 && *cond < 1.) {
  718. *info = -8;
  719. } else if (*kl < 0) {
  720. *info = -10;
  721. } else if (*ku < 0 || isym != 1 && *kl != *ku) {
  722. *info = -11;
  723. } else if (ipack == -1 || isympk == 1 && isym == 1 || isympk == 2 && isym
  724. == 1 && *kl > 0 || isympk == 3 && isym == 1 && *ku > 0 || isympk
  725. != 0 && *m != *n) {
  726. *info = -12;
  727. } else if (*lda < f2cmax(1,minlda)) {
  728. *info = -14;
  729. }
  730. if (*info != 0) {
  731. i__1 = -(*info);
  732. xerbla_("DLATMS", &i__1, 6);
  733. return;
  734. }
  735. /* Initialize random number generator */
  736. for (i__ = 1; i__ <= 4; ++i__) {
  737. iseed[i__] = (i__1 = iseed[i__], abs(i__1)) % 4096;
  738. /* L10: */
  739. }
  740. if (iseed[4] % 2 != 1) {
  741. ++iseed[4];
  742. }
  743. /* 2) Set up D if indicated. */
  744. /* Compute D according to COND and MODE */
  745. dlatm1_(mode, cond, &irsign, &idist, &iseed[1], &d__[1], &mnmin, &iinfo);
  746. if (iinfo != 0) {
  747. *info = 1;
  748. return;
  749. }
  750. /* Choose Top-Down if D is (apparently) increasing, */
  751. /* Bottom-Up if D is (apparently) decreasing. */
  752. if (abs(d__[1]) <= (d__1 = d__[mnmin], abs(d__1))) {
  753. topdwn = TRUE_;
  754. } else {
  755. topdwn = FALSE_;
  756. }
  757. if (*mode != 0 && abs(*mode) != 6) {
  758. /* Scale by DMAX */
  759. temp = abs(d__[1]);
  760. i__1 = mnmin;
  761. for (i__ = 2; i__ <= i__1; ++i__) {
  762. /* Computing MAX */
  763. d__2 = temp, d__3 = (d__1 = d__[i__], abs(d__1));
  764. temp = f2cmax(d__2,d__3);
  765. /* L20: */
  766. }
  767. if (temp > 0.) {
  768. alpha = *dmax__ / temp;
  769. } else {
  770. *info = 2;
  771. return;
  772. }
  773. dscal_(&mnmin, &alpha, &d__[1], &c__1);
  774. }
  775. /* 3) Generate Banded Matrix using Givens rotations. */
  776. /* Also the special case of UUB=LLB=0 */
  777. /* Compute Addressing constants to cover all */
  778. /* storage formats. Whether GE, SY, GB, or SB, */
  779. /* upper or lower triangle or both, */
  780. /* the (i,j)-th element is in */
  781. /* A( i - ISKEW*j + IOFFST, j ) */
  782. if (ipack > 4) {
  783. ilda = *lda - 1;
  784. iskew = 1;
  785. if (ipack > 5) {
  786. ioffst = uub + 1;
  787. } else {
  788. ioffst = 1;
  789. }
  790. } else {
  791. ilda = *lda;
  792. iskew = 0;
  793. ioffst = 0;
  794. }
  795. /* IPACKG is the format that the matrix is generated in. If this is */
  796. /* different from IPACK, then the matrix must be repacked at the */
  797. /* end. It also signals how to compute the norm, for scaling. */
  798. ipackg = 0;
  799. dlaset_("Full", lda, n, &c_b22, &c_b22, &a[a_offset], lda);
  800. /* Diagonal Matrix -- We are done, unless it */
  801. /* is to be stored SP/PP/TP (PACK='R' or 'C') */
  802. if (llb == 0 && uub == 0) {
  803. i__1 = ilda + 1;
  804. dcopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffst + a_dim1], &i__1)
  805. ;
  806. if (ipack <= 2 || ipack >= 5) {
  807. ipackg = ipack;
  808. }
  809. } else if (givens) {
  810. /* Check whether to use Givens rotations, */
  811. /* Householder transformations, or nothing. */
  812. if (isym == 1) {
  813. /* Non-symmetric -- A = U D V */
  814. if (ipack > 4) {
  815. ipackg = ipack;
  816. } else {
  817. ipackg = 0;
  818. }
  819. i__1 = ilda + 1;
  820. dcopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffst + a_dim1], &
  821. i__1);
  822. if (topdwn) {
  823. jkl = 0;
  824. i__1 = uub;
  825. for (jku = 1; jku <= i__1; ++jku) {
  826. /* Transform from bandwidth JKL, JKU-1 to JKL, JKU */
  827. /* Last row actually rotated is M */
  828. /* Last column actually rotated is MIN( M+JKU, N ) */
  829. /* Computing MIN */
  830. i__3 = *m + jku;
  831. i__2 = f2cmin(i__3,*n) + jkl - 1;
  832. for (jr = 1; jr <= i__2; ++jr) {
  833. extra = 0.;
  834. angle = dlarnd_(&c__1, &iseed[1]) *
  835. 6.2831853071795864769252867663;
  836. c__ = cos(angle);
  837. s = sin(angle);
  838. /* Computing MAX */
  839. i__3 = 1, i__4 = jr - jkl;
  840. icol = f2cmax(i__3,i__4);
  841. if (jr < *m) {
  842. /* Computing MIN */
  843. i__3 = *n, i__4 = jr + jku;
  844. il = f2cmin(i__3,i__4) + 1 - icol;
  845. L__1 = jr > jkl;
  846. dlarot_(&c_true, &L__1, &c_false, &il, &c__, &s, &
  847. a[jr - iskew * icol + ioffst + icol *
  848. a_dim1], &ilda, &extra, &dummy);
  849. }
  850. /* Chase "EXTRA" back up */
  851. ir = jr;
  852. ic = icol;
  853. i__3 = -jkl - jku;
  854. for (jch = jr - jkl; i__3 < 0 ? jch >= 1 : jch <= 1;
  855. jch += i__3) {
  856. if (ir < *m) {
  857. dlartg_(&a[ir + 1 - iskew * (ic + 1) + ioffst
  858. + (ic + 1) * a_dim1], &extra, &c__, &
  859. s, &dummy);
  860. }
  861. /* Computing MAX */
  862. i__4 = 1, i__5 = jch - jku;
  863. irow = f2cmax(i__4,i__5);
  864. il = ir + 2 - irow;
  865. temp = 0.;
  866. iltemp = jch > jku;
  867. d__1 = -s;
  868. dlarot_(&c_false, &iltemp, &c_true, &il, &c__, &
  869. d__1, &a[irow - iskew * ic + ioffst + ic *
  870. a_dim1], &ilda, &temp, &extra);
  871. if (iltemp) {
  872. dlartg_(&a[irow + 1 - iskew * (ic + 1) +
  873. ioffst + (ic + 1) * a_dim1], &temp, &
  874. c__, &s, &dummy);
  875. /* Computing MAX */
  876. i__4 = 1, i__5 = jch - jku - jkl;
  877. icol = f2cmax(i__4,i__5);
  878. il = ic + 2 - icol;
  879. extra = 0.;
  880. L__1 = jch > jku + jkl;
  881. d__1 = -s;
  882. dlarot_(&c_true, &L__1, &c_true, &il, &c__, &
  883. d__1, &a[irow - iskew * icol + ioffst
  884. + icol * a_dim1], &ilda, &extra, &
  885. temp);
  886. ic = icol;
  887. ir = irow;
  888. }
  889. /* L30: */
  890. }
  891. /* L40: */
  892. }
  893. /* L50: */
  894. }
  895. jku = uub;
  896. i__1 = llb;
  897. for (jkl = 1; jkl <= i__1; ++jkl) {
  898. /* Transform from bandwidth JKL-1, JKU to JKL, JKU */
  899. /* Computing MIN */
  900. i__3 = *n + jkl;
  901. i__2 = f2cmin(i__3,*m) + jku - 1;
  902. for (jc = 1; jc <= i__2; ++jc) {
  903. extra = 0.;
  904. angle = dlarnd_(&c__1, &iseed[1]) *
  905. 6.2831853071795864769252867663;
  906. c__ = cos(angle);
  907. s = sin(angle);
  908. /* Computing MAX */
  909. i__3 = 1, i__4 = jc - jku;
  910. irow = f2cmax(i__3,i__4);
  911. if (jc < *n) {
  912. /* Computing MIN */
  913. i__3 = *m, i__4 = jc + jkl;
  914. il = f2cmin(i__3,i__4) + 1 - irow;
  915. L__1 = jc > jku;
  916. dlarot_(&c_false, &L__1, &c_false, &il, &c__, &s,
  917. &a[irow - iskew * jc + ioffst + jc *
  918. a_dim1], &ilda, &extra, &dummy);
  919. }
  920. /* Chase "EXTRA" back up */
  921. ic = jc;
  922. ir = irow;
  923. i__3 = -jkl - jku;
  924. for (jch = jc - jku; i__3 < 0 ? jch >= 1 : jch <= 1;
  925. jch += i__3) {
  926. if (ic < *n) {
  927. dlartg_(&a[ir + 1 - iskew * (ic + 1) + ioffst
  928. + (ic + 1) * a_dim1], &extra, &c__, &
  929. s, &dummy);
  930. }
  931. /* Computing MAX */
  932. i__4 = 1, i__5 = jch - jkl;
  933. icol = f2cmax(i__4,i__5);
  934. il = ic + 2 - icol;
  935. temp = 0.;
  936. iltemp = jch > jkl;
  937. d__1 = -s;
  938. dlarot_(&c_true, &iltemp, &c_true, &il, &c__, &
  939. d__1, &a[ir - iskew * icol + ioffst +
  940. icol * a_dim1], &ilda, &temp, &extra);
  941. if (iltemp) {
  942. dlartg_(&a[ir + 1 - iskew * (icol + 1) +
  943. ioffst + (icol + 1) * a_dim1], &temp,
  944. &c__, &s, &dummy);
  945. /* Computing MAX */
  946. i__4 = 1, i__5 = jch - jkl - jku;
  947. irow = f2cmax(i__4,i__5);
  948. il = ir + 2 - irow;
  949. extra = 0.;
  950. L__1 = jch > jkl + jku;
  951. d__1 = -s;
  952. dlarot_(&c_false, &L__1, &c_true, &il, &c__, &
  953. d__1, &a[irow - iskew * icol + ioffst
  954. + icol * a_dim1], &ilda, &extra, &
  955. temp);
  956. ic = icol;
  957. ir = irow;
  958. }
  959. /* L60: */
  960. }
  961. /* L70: */
  962. }
  963. /* L80: */
  964. }
  965. } else {
  966. /* Bottom-Up -- Start at the bottom right. */
  967. jkl = 0;
  968. i__1 = uub;
  969. for (jku = 1; jku <= i__1; ++jku) {
  970. /* Transform from bandwidth JKL, JKU-1 to JKL, JKU */
  971. /* First row actually rotated is M */
  972. /* First column actually rotated is MIN( M+JKU, N ) */
  973. /* Computing MIN */
  974. i__2 = *m, i__3 = *n + jkl;
  975. iendch = f2cmin(i__2,i__3) - 1;
  976. /* Computing MIN */
  977. i__2 = *m + jku;
  978. i__3 = 1 - jkl;
  979. for (jc = f2cmin(i__2,*n) - 1; jc >= i__3; --jc) {
  980. extra = 0.;
  981. angle = dlarnd_(&c__1, &iseed[1]) *
  982. 6.2831853071795864769252867663;
  983. c__ = cos(angle);
  984. s = sin(angle);
  985. /* Computing MAX */
  986. i__2 = 1, i__4 = jc - jku + 1;
  987. irow = f2cmax(i__2,i__4);
  988. if (jc > 0) {
  989. /* Computing MIN */
  990. i__2 = *m, i__4 = jc + jkl + 1;
  991. il = f2cmin(i__2,i__4) + 1 - irow;
  992. L__1 = jc + jkl < *m;
  993. dlarot_(&c_false, &c_false, &L__1, &il, &c__, &s,
  994. &a[irow - iskew * jc + ioffst + jc *
  995. a_dim1], &ilda, &dummy, &extra);
  996. }
  997. /* Chase "EXTRA" back down */
  998. ic = jc;
  999. i__2 = iendch;
  1000. i__4 = jkl + jku;
  1001. for (jch = jc + jkl; i__4 < 0 ? jch >= i__2 : jch <=
  1002. i__2; jch += i__4) {
  1003. ilextr = ic > 0;
  1004. if (ilextr) {
  1005. dlartg_(&a[jch - iskew * ic + ioffst + ic *
  1006. a_dim1], &extra, &c__, &s, &dummy);
  1007. }
  1008. ic = f2cmax(1,ic);
  1009. /* Computing MIN */
  1010. i__5 = *n - 1, i__6 = jch + jku;
  1011. icol = f2cmin(i__5,i__6);
  1012. iltemp = jch + jku < *n;
  1013. temp = 0.;
  1014. i__5 = icol + 2 - ic;
  1015. dlarot_(&c_true, &ilextr, &iltemp, &i__5, &c__, &
  1016. s, &a[jch - iskew * ic + ioffst + ic *
  1017. a_dim1], &ilda, &extra, &temp);
  1018. if (iltemp) {
  1019. dlartg_(&a[jch - iskew * icol + ioffst + icol
  1020. * a_dim1], &temp, &c__, &s, &dummy);
  1021. /* Computing MIN */
  1022. i__5 = iendch, i__6 = jch + jkl + jku;
  1023. il = f2cmin(i__5,i__6) + 2 - jch;
  1024. extra = 0.;
  1025. L__1 = jch + jkl + jku <= iendch;
  1026. dlarot_(&c_false, &c_true, &L__1, &il, &c__, &
  1027. s, &a[jch - iskew * icol + ioffst +
  1028. icol * a_dim1], &ilda, &temp, &extra);
  1029. ic = icol;
  1030. }
  1031. /* L90: */
  1032. }
  1033. /* L100: */
  1034. }
  1035. /* L110: */
  1036. }
  1037. jku = uub;
  1038. i__1 = llb;
  1039. for (jkl = 1; jkl <= i__1; ++jkl) {
  1040. /* Transform from bandwidth JKL-1, JKU to JKL, JKU */
  1041. /* First row actually rotated is MIN( N+JKL, M ) */
  1042. /* First column actually rotated is N */
  1043. /* Computing MIN */
  1044. i__3 = *n, i__4 = *m + jku;
  1045. iendch = f2cmin(i__3,i__4) - 1;
  1046. /* Computing MIN */
  1047. i__3 = *n + jkl;
  1048. i__4 = 1 - jku;
  1049. for (jr = f2cmin(i__3,*m) - 1; jr >= i__4; --jr) {
  1050. extra = 0.;
  1051. angle = dlarnd_(&c__1, &iseed[1]) *
  1052. 6.2831853071795864769252867663;
  1053. c__ = cos(angle);
  1054. s = sin(angle);
  1055. /* Computing MAX */
  1056. i__3 = 1, i__2 = jr - jkl + 1;
  1057. icol = f2cmax(i__3,i__2);
  1058. if (jr > 0) {
  1059. /* Computing MIN */
  1060. i__3 = *n, i__2 = jr + jku + 1;
  1061. il = f2cmin(i__3,i__2) + 1 - icol;
  1062. L__1 = jr + jku < *n;
  1063. dlarot_(&c_true, &c_false, &L__1, &il, &c__, &s, &
  1064. a[jr - iskew * icol + ioffst + icol *
  1065. a_dim1], &ilda, &dummy, &extra);
  1066. }
  1067. /* Chase "EXTRA" back down */
  1068. ir = jr;
  1069. i__3 = iendch;
  1070. i__2 = jkl + jku;
  1071. for (jch = jr + jku; i__2 < 0 ? jch >= i__3 : jch <=
  1072. i__3; jch += i__2) {
  1073. ilextr = ir > 0;
  1074. if (ilextr) {
  1075. dlartg_(&a[ir - iskew * jch + ioffst + jch *
  1076. a_dim1], &extra, &c__, &s, &dummy);
  1077. }
  1078. ir = f2cmax(1,ir);
  1079. /* Computing MIN */
  1080. i__5 = *m - 1, i__6 = jch + jkl;
  1081. irow = f2cmin(i__5,i__6);
  1082. iltemp = jch + jkl < *m;
  1083. temp = 0.;
  1084. i__5 = irow + 2 - ir;
  1085. dlarot_(&c_false, &ilextr, &iltemp, &i__5, &c__, &
  1086. s, &a[ir - iskew * jch + ioffst + jch *
  1087. a_dim1], &ilda, &extra, &temp);
  1088. if (iltemp) {
  1089. dlartg_(&a[irow - iskew * jch + ioffst + jch *
  1090. a_dim1], &temp, &c__, &s, &dummy);
  1091. /* Computing MIN */
  1092. i__5 = iendch, i__6 = jch + jkl + jku;
  1093. il = f2cmin(i__5,i__6) + 2 - jch;
  1094. extra = 0.;
  1095. L__1 = jch + jkl + jku <= iendch;
  1096. dlarot_(&c_true, &c_true, &L__1, &il, &c__, &
  1097. s, &a[irow - iskew * jch + ioffst +
  1098. jch * a_dim1], &ilda, &temp, &extra);
  1099. ir = irow;
  1100. }
  1101. /* L120: */
  1102. }
  1103. /* L130: */
  1104. }
  1105. /* L140: */
  1106. }
  1107. }
  1108. } else {
  1109. /* Symmetric -- A = U D U' */
  1110. ipackg = ipack;
  1111. ioffg = ioffst;
  1112. if (topdwn) {
  1113. /* Top-Down -- Generate Upper triangle only */
  1114. if (ipack >= 5) {
  1115. ipackg = 6;
  1116. ioffg = uub + 1;
  1117. } else {
  1118. ipackg = 1;
  1119. }
  1120. i__1 = ilda + 1;
  1121. dcopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffg + a_dim1],
  1122. &i__1);
  1123. i__1 = uub;
  1124. for (k = 1; k <= i__1; ++k) {
  1125. i__4 = *n - 1;
  1126. for (jc = 1; jc <= i__4; ++jc) {
  1127. /* Computing MAX */
  1128. i__2 = 1, i__3 = jc - k;
  1129. irow = f2cmax(i__2,i__3);
  1130. /* Computing MIN */
  1131. i__2 = jc + 1, i__3 = k + 2;
  1132. il = f2cmin(i__2,i__3);
  1133. extra = 0.;
  1134. temp = a[jc - iskew * (jc + 1) + ioffg + (jc + 1) *
  1135. a_dim1];
  1136. angle = dlarnd_(&c__1, &iseed[1]) *
  1137. 6.2831853071795864769252867663;
  1138. c__ = cos(angle);
  1139. s = sin(angle);
  1140. L__1 = jc > k;
  1141. dlarot_(&c_false, &L__1, &c_true, &il, &c__, &s, &a[
  1142. irow - iskew * jc + ioffg + jc * a_dim1], &
  1143. ilda, &extra, &temp);
  1144. /* Computing MIN */
  1145. i__3 = k, i__5 = *n - jc;
  1146. i__2 = f2cmin(i__3,i__5) + 1;
  1147. dlarot_(&c_true, &c_true, &c_false, &i__2, &c__, &s, &
  1148. a[(1 - iskew) * jc + ioffg + jc * a_dim1], &
  1149. ilda, &temp, &dummy);
  1150. /* Chase EXTRA back up the matrix */
  1151. icol = jc;
  1152. i__2 = -k;
  1153. for (jch = jc - k; i__2 < 0 ? jch >= 1 : jch <= 1;
  1154. jch += i__2) {
  1155. dlartg_(&a[jch + 1 - iskew * (icol + 1) + ioffg +
  1156. (icol + 1) * a_dim1], &extra, &c__, &s, &
  1157. dummy);
  1158. temp = a[jch - iskew * (jch + 1) + ioffg + (jch +
  1159. 1) * a_dim1];
  1160. i__3 = k + 2;
  1161. d__1 = -s;
  1162. dlarot_(&c_true, &c_true, &c_true, &i__3, &c__, &
  1163. d__1, &a[(1 - iskew) * jch + ioffg + jch *
  1164. a_dim1], &ilda, &temp, &extra);
  1165. /* Computing MAX */
  1166. i__3 = 1, i__5 = jch - k;
  1167. irow = f2cmax(i__3,i__5);
  1168. /* Computing MIN */
  1169. i__3 = jch + 1, i__5 = k + 2;
  1170. il = f2cmin(i__3,i__5);
  1171. extra = 0.;
  1172. L__1 = jch > k;
  1173. d__1 = -s;
  1174. dlarot_(&c_false, &L__1, &c_true, &il, &c__, &
  1175. d__1, &a[irow - iskew * jch + ioffg + jch
  1176. * a_dim1], &ilda, &extra, &temp);
  1177. icol = jch;
  1178. /* L150: */
  1179. }
  1180. /* L160: */
  1181. }
  1182. /* L170: */
  1183. }
  1184. /* If we need lower triangle, copy from upper. Note that */
  1185. /* the order of copying is chosen to work for 'q' -> 'b' */
  1186. if (ipack != ipackg && ipack != 3) {
  1187. i__1 = *n;
  1188. for (jc = 1; jc <= i__1; ++jc) {
  1189. irow = ioffst - iskew * jc;
  1190. /* Computing MIN */
  1191. i__2 = *n, i__3 = jc + uub;
  1192. i__4 = f2cmin(i__2,i__3);
  1193. for (jr = jc; jr <= i__4; ++jr) {
  1194. a[jr + irow + jc * a_dim1] = a[jc - iskew * jr +
  1195. ioffg + jr * a_dim1];
  1196. /* L180: */
  1197. }
  1198. /* L190: */
  1199. }
  1200. if (ipack == 5) {
  1201. i__1 = *n;
  1202. for (jc = *n - uub + 1; jc <= i__1; ++jc) {
  1203. i__4 = uub + 1;
  1204. for (jr = *n + 2 - jc; jr <= i__4; ++jr) {
  1205. a[jr + jc * a_dim1] = 0.;
  1206. /* L200: */
  1207. }
  1208. /* L210: */
  1209. }
  1210. }
  1211. if (ipackg == 6) {
  1212. ipackg = ipack;
  1213. } else {
  1214. ipackg = 0;
  1215. }
  1216. }
  1217. } else {
  1218. /* Bottom-Up -- Generate Lower triangle only */
  1219. if (ipack >= 5) {
  1220. ipackg = 5;
  1221. if (ipack == 6) {
  1222. ioffg = 1;
  1223. }
  1224. } else {
  1225. ipackg = 2;
  1226. }
  1227. i__1 = ilda + 1;
  1228. dcopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffg + a_dim1],
  1229. &i__1);
  1230. i__1 = uub;
  1231. for (k = 1; k <= i__1; ++k) {
  1232. for (jc = *n - 1; jc >= 1; --jc) {
  1233. /* Computing MIN */
  1234. i__4 = *n + 1 - jc, i__2 = k + 2;
  1235. il = f2cmin(i__4,i__2);
  1236. extra = 0.;
  1237. temp = a[(1 - iskew) * jc + 1 + ioffg + jc * a_dim1];
  1238. angle = dlarnd_(&c__1, &iseed[1]) *
  1239. 6.2831853071795864769252867663;
  1240. c__ = cos(angle);
  1241. s = -sin(angle);
  1242. L__1 = *n - jc > k;
  1243. dlarot_(&c_false, &c_true, &L__1, &il, &c__, &s, &a[(
  1244. 1 - iskew) * jc + ioffg + jc * a_dim1], &ilda,
  1245. &temp, &extra);
  1246. /* Computing MAX */
  1247. i__4 = 1, i__2 = jc - k + 1;
  1248. icol = f2cmax(i__4,i__2);
  1249. i__4 = jc + 2 - icol;
  1250. dlarot_(&c_true, &c_false, &c_true, &i__4, &c__, &s, &
  1251. a[jc - iskew * icol + ioffg + icol * a_dim1],
  1252. &ilda, &dummy, &temp);
  1253. /* Chase EXTRA back down the matrix */
  1254. icol = jc;
  1255. i__4 = *n - 1;
  1256. i__2 = k;
  1257. for (jch = jc + k; i__2 < 0 ? jch >= i__4 : jch <=
  1258. i__4; jch += i__2) {
  1259. dlartg_(&a[jch - iskew * icol + ioffg + icol *
  1260. a_dim1], &extra, &c__, &s, &dummy);
  1261. temp = a[(1 - iskew) * jch + 1 + ioffg + jch *
  1262. a_dim1];
  1263. i__3 = k + 2;
  1264. dlarot_(&c_true, &c_true, &c_true, &i__3, &c__, &
  1265. s, &a[jch - iskew * icol + ioffg + icol *
  1266. a_dim1], &ilda, &extra, &temp);
  1267. /* Computing MIN */
  1268. i__3 = *n + 1 - jch, i__5 = k + 2;
  1269. il = f2cmin(i__3,i__5);
  1270. extra = 0.;
  1271. L__1 = *n - jch > k;
  1272. dlarot_(&c_false, &c_true, &L__1, &il, &c__, &s, &
  1273. a[(1 - iskew) * jch + ioffg + jch *
  1274. a_dim1], &ilda, &temp, &extra);
  1275. icol = jch;
  1276. /* L220: */
  1277. }
  1278. /* L230: */
  1279. }
  1280. /* L240: */
  1281. }
  1282. /* If we need upper triangle, copy from lower. Note that */
  1283. /* the order of copying is chosen to work for 'b' -> 'q' */
  1284. if (ipack != ipackg && ipack != 4) {
  1285. for (jc = *n; jc >= 1; --jc) {
  1286. irow = ioffst - iskew * jc;
  1287. /* Computing MAX */
  1288. i__2 = 1, i__4 = jc - uub;
  1289. i__1 = f2cmax(i__2,i__4);
  1290. for (jr = jc; jr >= i__1; --jr) {
  1291. a[jr + irow + jc * a_dim1] = a[jc - iskew * jr +
  1292. ioffg + jr * a_dim1];
  1293. /* L250: */
  1294. }
  1295. /* L260: */
  1296. }
  1297. if (ipack == 6) {
  1298. i__1 = uub;
  1299. for (jc = 1; jc <= i__1; ++jc) {
  1300. i__2 = uub + 1 - jc;
  1301. for (jr = 1; jr <= i__2; ++jr) {
  1302. a[jr + jc * a_dim1] = 0.;
  1303. /* L270: */
  1304. }
  1305. /* L280: */
  1306. }
  1307. }
  1308. if (ipackg == 5) {
  1309. ipackg = ipack;
  1310. } else {
  1311. ipackg = 0;
  1312. }
  1313. }
  1314. }
  1315. }
  1316. } else {
  1317. /* 4) Generate Banded Matrix by first */
  1318. /* Rotating by random Unitary matrices, */
  1319. /* then reducing the bandwidth using Householder */
  1320. /* transformations. */
  1321. /* Note: we should get here only if LDA .ge. N */
  1322. if (isym == 1) {
  1323. /* Non-symmetric -- A = U D V */
  1324. dlagge_(&mr, &nc, &llb, &uub, &d__[1], &a[a_offset], lda, &iseed[
  1325. 1], &work[1], &iinfo);
  1326. } else {
  1327. /* Symmetric -- A = U D U' */
  1328. dlagsy_(m, &llb, &d__[1], &a[a_offset], lda, &iseed[1], &work[1],
  1329. &iinfo);
  1330. }
  1331. if (iinfo != 0) {
  1332. *info = 3;
  1333. return;
  1334. }
  1335. }
  1336. /* 5) Pack the matrix */
  1337. if (ipack != ipackg) {
  1338. if (ipack == 1) {
  1339. /* 'U' -- Upper triangular, not packed */
  1340. i__1 = *m;
  1341. for (j = 1; j <= i__1; ++j) {
  1342. i__2 = *m;
  1343. for (i__ = j + 1; i__ <= i__2; ++i__) {
  1344. a[i__ + j * a_dim1] = 0.;
  1345. /* L290: */
  1346. }
  1347. /* L300: */
  1348. }
  1349. } else if (ipack == 2) {
  1350. /* 'L' -- Lower triangular, not packed */
  1351. i__1 = *m;
  1352. for (j = 2; j <= i__1; ++j) {
  1353. i__2 = j - 1;
  1354. for (i__ = 1; i__ <= i__2; ++i__) {
  1355. a[i__ + j * a_dim1] = 0.;
  1356. /* L310: */
  1357. }
  1358. /* L320: */
  1359. }
  1360. } else if (ipack == 3) {
  1361. /* 'C' -- Upper triangle packed Columnwise. */
  1362. icol = 1;
  1363. irow = 0;
  1364. i__1 = *m;
  1365. for (j = 1; j <= i__1; ++j) {
  1366. i__2 = j;
  1367. for (i__ = 1; i__ <= i__2; ++i__) {
  1368. ++irow;
  1369. if (irow > *lda) {
  1370. irow = 1;
  1371. ++icol;
  1372. }
  1373. a[irow + icol * a_dim1] = a[i__ + j * a_dim1];
  1374. /* L330: */
  1375. }
  1376. /* L340: */
  1377. }
  1378. } else if (ipack == 4) {
  1379. /* 'R' -- Lower triangle packed Columnwise. */
  1380. icol = 1;
  1381. irow = 0;
  1382. i__1 = *m;
  1383. for (j = 1; j <= i__1; ++j) {
  1384. i__2 = *m;
  1385. for (i__ = j; i__ <= i__2; ++i__) {
  1386. ++irow;
  1387. if (irow > *lda) {
  1388. irow = 1;
  1389. ++icol;
  1390. }
  1391. a[irow + icol * a_dim1] = a[i__ + j * a_dim1];
  1392. /* L350: */
  1393. }
  1394. /* L360: */
  1395. }
  1396. } else if (ipack >= 5) {
  1397. /* 'B' -- The lower triangle is packed as a band matrix. */
  1398. /* 'Q' -- The upper triangle is packed as a band matrix. */
  1399. /* 'Z' -- The whole matrix is packed as a band matrix. */
  1400. if (ipack == 5) {
  1401. uub = 0;
  1402. }
  1403. if (ipack == 6) {
  1404. llb = 0;
  1405. }
  1406. i__1 = uub;
  1407. for (j = 1; j <= i__1; ++j) {
  1408. /* Computing MIN */
  1409. i__2 = j + llb;
  1410. for (i__ = f2cmin(i__2,*m); i__ >= 1; --i__) {
  1411. a[i__ - j + uub + 1 + j * a_dim1] = a[i__ + j * a_dim1];
  1412. /* L370: */
  1413. }
  1414. /* L380: */
  1415. }
  1416. i__1 = *n;
  1417. for (j = uub + 2; j <= i__1; ++j) {
  1418. /* Computing MIN */
  1419. i__4 = j + llb;
  1420. i__2 = f2cmin(i__4,*m);
  1421. for (i__ = j - uub; i__ <= i__2; ++i__) {
  1422. a[i__ - j + uub + 1 + j * a_dim1] = a[i__ + j * a_dim1];
  1423. /* L390: */
  1424. }
  1425. /* L400: */
  1426. }
  1427. }
  1428. /* If packed, zero out extraneous elements. */
  1429. /* Symmetric/Triangular Packed -- */
  1430. /* zero out everything after A(IROW,ICOL) */
  1431. if (ipack == 3 || ipack == 4) {
  1432. i__1 = *m;
  1433. for (jc = icol; jc <= i__1; ++jc) {
  1434. i__2 = *lda;
  1435. for (jr = irow + 1; jr <= i__2; ++jr) {
  1436. a[jr + jc * a_dim1] = 0.;
  1437. /* L410: */
  1438. }
  1439. irow = 0;
  1440. /* L420: */
  1441. }
  1442. } else if (ipack >= 5) {
  1443. /* Packed Band -- */
  1444. /* 1st row is now in A( UUB+2-j, j), zero above it */
  1445. /* m-th row is now in A( M+UUB-j,j), zero below it */
  1446. /* last non-zero diagonal is now in A( UUB+LLB+1,j ), */
  1447. /* zero below it, too. */
  1448. ir1 = uub + llb + 2;
  1449. ir2 = uub + *m + 2;
  1450. i__1 = *n;
  1451. for (jc = 1; jc <= i__1; ++jc) {
  1452. i__2 = uub + 1 - jc;
  1453. for (jr = 1; jr <= i__2; ++jr) {
  1454. a[jr + jc * a_dim1] = 0.;
  1455. /* L430: */
  1456. }
  1457. /* Computing MAX */
  1458. /* Computing MIN */
  1459. i__3 = ir1, i__5 = ir2 - jc;
  1460. i__2 = 1, i__4 = f2cmin(i__3,i__5);
  1461. i__6 = *lda;
  1462. for (jr = f2cmax(i__2,i__4); jr <= i__6; ++jr) {
  1463. a[jr + jc * a_dim1] = 0.;
  1464. /* L440: */
  1465. }
  1466. /* L450: */
  1467. }
  1468. }
  1469. }
  1470. return;
  1471. /* End of DLATMS */
  1472. } /* dlatms_ */