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.

dlatmt.c 48 kB

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