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.

slatmt.c 48 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef int logical;
  52. typedef short int shortlogical;
  53. typedef char logical1;
  54. typedef char integer1;
  55. #define TRUE_ (1)
  56. #define FALSE_ (0)
  57. /* Extern is for use with -E */
  58. #ifndef Extern
  59. #define Extern extern
  60. #endif
  61. /* I/O stuff */
  62. typedef int flag;
  63. typedef int ftnlen;
  64. typedef int ftnint;
  65. /*external read, write*/
  66. typedef struct
  67. { flag cierr;
  68. ftnint ciunit;
  69. flag ciend;
  70. char *cifmt;
  71. ftnint cirec;
  72. } cilist;
  73. /*internal read, write*/
  74. typedef struct
  75. { flag icierr;
  76. char *iciunit;
  77. flag iciend;
  78. char *icifmt;
  79. ftnint icirlen;
  80. ftnint icirnum;
  81. } icilist;
  82. /*open*/
  83. typedef struct
  84. { flag oerr;
  85. ftnint ounit;
  86. char *ofnm;
  87. ftnlen ofnmlen;
  88. char *osta;
  89. char *oacc;
  90. char *ofm;
  91. ftnint orl;
  92. char *oblnk;
  93. } olist;
  94. /*close*/
  95. typedef struct
  96. { flag cerr;
  97. ftnint cunit;
  98. char *csta;
  99. } cllist;
  100. /*rewind, backspace, endfile*/
  101. typedef struct
  102. { flag aerr;
  103. ftnint aunit;
  104. } alist;
  105. /* inquire */
  106. typedef struct
  107. { flag inerr;
  108. ftnint inunit;
  109. char *infile;
  110. ftnlen infilen;
  111. ftnint *inex; /*parameters in standard's order*/
  112. ftnint *inopen;
  113. ftnint *innum;
  114. ftnint *innamed;
  115. char *inname;
  116. ftnlen innamlen;
  117. char *inacc;
  118. ftnlen inacclen;
  119. char *inseq;
  120. ftnlen inseqlen;
  121. char *indir;
  122. ftnlen indirlen;
  123. char *infmt;
  124. ftnlen infmtlen;
  125. char *inform;
  126. ftnint informlen;
  127. char *inunf;
  128. ftnlen inunflen;
  129. ftnint *inrecl;
  130. ftnint *innrec;
  131. char *inblank;
  132. ftnlen inblanklen;
  133. } inlist;
  134. #define VOID void
  135. union Multitype { /* for multiple entry points */
  136. integer1 g;
  137. shortint h;
  138. integer i;
  139. /* longint j; */
  140. real r;
  141. doublereal d;
  142. complex c;
  143. doublecomplex z;
  144. };
  145. typedef union Multitype Multitype;
  146. struct Vardesc { /* for Namelist */
  147. char *name;
  148. char *addr;
  149. ftnlen *dims;
  150. int type;
  151. };
  152. typedef struct Vardesc Vardesc;
  153. struct Namelist {
  154. char *name;
  155. Vardesc **vars;
  156. int nvars;
  157. };
  158. typedef struct Namelist Namelist;
  159. #define abs(x) ((x) >= 0 ? (x) : -(x))
  160. #define dabs(x) (fabs(x))
  161. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  162. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  163. #define dmin(a,b) (f2cmin(a,b))
  164. #define dmax(a,b) (f2cmax(a,b))
  165. #define bit_test(a,b) ((a) >> (b) & 1)
  166. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  167. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  168. #define abort_() { sig_die("Fortran abort routine called", 1); }
  169. #define c_abs(z) (cabsf(Cf(z)))
  170. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  171. #ifdef _MSC_VER
  172. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  173. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  174. #else
  175. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  176. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  177. #endif
  178. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  179. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  180. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  181. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  182. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  183. #define d_abs(x) (fabs(*(x)))
  184. #define d_acos(x) (acos(*(x)))
  185. #define d_asin(x) (asin(*(x)))
  186. #define d_atan(x) (atan(*(x)))
  187. #define d_atn2(x, y) (atan2(*(x),*(y)))
  188. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  189. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  190. #define d_cos(x) (cos(*(x)))
  191. #define d_cosh(x) (cosh(*(x)))
  192. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  193. #define d_exp(x) (exp(*(x)))
  194. #define d_imag(z) (cimag(Cd(z)))
  195. #define r_imag(z) (cimagf(Cf(z)))
  196. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  198. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  200. #define d_log(x) (log(*(x)))
  201. #define d_mod(x, y) (fmod(*(x), *(y)))
  202. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  203. #define d_nint(x) u_nint(*(x))
  204. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  205. #define d_sign(a,b) u_sign(*(a),*(b))
  206. #define r_sign(a,b) u_sign(*(a),*(b))
  207. #define d_sin(x) (sin(*(x)))
  208. #define d_sinh(x) (sinh(*(x)))
  209. #define d_sqrt(x) (sqrt(*(x)))
  210. #define d_tan(x) (tan(*(x)))
  211. #define d_tanh(x) (tanh(*(x)))
  212. #define i_abs(x) abs(*(x))
  213. #define i_dnnt(x) ((integer)u_nint(*(x)))
  214. #define i_len(s, n) (n)
  215. #define i_nint(x) ((integer)u_nint(*(x)))
  216. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  217. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  218. #define pow_si(B,E) spow_ui(*(B),*(E))
  219. #define pow_ri(B,E) spow_ui(*(B),*(E))
  220. #define pow_di(B,E) dpow_ui(*(B),*(E))
  221. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  222. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  223. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  224. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  225. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  226. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  227. #define sig_die(s, kill) { exit(1); }
  228. #define s_stop(s, n) {exit(0);}
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #define F2C_proc_par_types 1
  240. /* Table of constant values */
  241. static integer c__1 = 1;
  242. static real c_b22 = 0.f;
  243. static logical c_true = TRUE_;
  244. static logical c_false = FALSE_;
  245. /* > \brief \b SLATMT */
  246. /* =========== DOCUMENTATION =========== */
  247. /* Online html documentation available at */
  248. /* http://www.netlib.org/lapack/explore-html/ */
  249. /* Definition: */
  250. /* =========== */
  251. /* SUBROUTINE SLATMT( M, N, DIST, ISEED, SYM, D, MODE, COND, DMAX, */
  252. /* RANK, KL, KU, PACK, A, LDA, WORK, INFO ) */
  253. /* REAL COND, DMAX */
  254. /* INTEGER INFO, KL, KU, LDA, M, MODE, N, RANK */
  255. /* CHARACTER DIST, PACK, SYM */
  256. /* REAL A( LDA, * ), D( * ), WORK( * ) */
  257. /* INTEGER ISEED( 4 ) */
  258. /* > \par Purpose: */
  259. /* ============= */
  260. /* > */
  261. /* > \verbatim */
  262. /* > */
  263. /* > SLATMT generates random matrices with specified singular values */
  264. /* > (or symmetric/hermitian with specified eigenvalues) */
  265. /* > for testing LAPACK programs. */
  266. /* > */
  267. /* > SLATMT operates by applying the following sequence of */
  268. /* > operations: */
  269. /* > */
  270. /* > Set the diagonal to D, where D may be input or */
  271. /* > computed according to MODE, COND, DMAX, and SYM */
  272. /* > as described below. */
  273. /* > */
  274. /* > Generate a matrix with the appropriate band structure, by one */
  275. /* > of two methods: */
  276. /* > */
  277. /* > Method A: */
  278. /* > Generate a dense M x N matrix by multiplying D on the left */
  279. /* > and the right by random unitary matrices, then: */
  280. /* > */
  281. /* > Reduce the bandwidth according to KL and KU, using */
  282. /* > Householder transformations. */
  283. /* > */
  284. /* > Method B: */
  285. /* > Convert the bandwidth-0 (i.e., diagonal) matrix to a */
  286. /* > bandwidth-1 matrix using Givens rotations, "chasing" */
  287. /* > out-of-band elements back, much as in QR; then */
  288. /* > convert the bandwidth-1 to a bandwidth-2 matrix, etc. */
  289. /* > Note that for reasonably small bandwidths (relative to */
  290. /* > M and N) this requires less storage, as a dense matrix */
  291. /* > is not generated. Also, for symmetric matrices, only */
  292. /* > one triangle is generated. */
  293. /* > */
  294. /* > Method A is chosen if the bandwidth is a large fraction of the */
  295. /* > order of the matrix, and LDA is at least M (so a dense */
  296. /* > matrix can be stored.) Method B is chosen if the bandwidth */
  297. /* > is small (< 1/2 N for symmetric, < .3 N+M for */
  298. /* > non-symmetric), or LDA is less than M and not less than the */
  299. /* > bandwidth. */
  300. /* > */
  301. /* > Pack the matrix if desired. Options specified by PACK are: */
  302. /* > no packing */
  303. /* > zero out upper half (if symmetric) */
  304. /* > zero out lower half (if symmetric) */
  305. /* > store the upper half columnwise (if symmetric or upper */
  306. /* > triangular) */
  307. /* > store the lower half columnwise (if symmetric or lower */
  308. /* > triangular) */
  309. /* > store the lower triangle in banded format (if symmetric */
  310. /* > or lower triangular) */
  311. /* > store the upper triangle in banded format (if symmetric */
  312. /* > or upper triangular) */
  313. /* > store the entire matrix in banded format */
  314. /* > If Method B is chosen, and band format is specified, then the */
  315. /* > matrix will be generated in the band format, so no repacking */
  316. /* > will be necessary. */
  317. /* > \endverbatim */
  318. /* Arguments: */
  319. /* ========== */
  320. /* > \param[in] M */
  321. /* > \verbatim */
  322. /* > M is INTEGER */
  323. /* > The number of rows of A. Not modified. */
  324. /* > \endverbatim */
  325. /* > */
  326. /* > \param[in] N */
  327. /* > \verbatim */
  328. /* > N is INTEGER */
  329. /* > The number of columns of A. Not modified. */
  330. /* > \endverbatim */
  331. /* > */
  332. /* > \param[in] DIST */
  333. /* > \verbatim */
  334. /* > DIST is CHARACTER*1 */
  335. /* > On entry, DIST specifies the type of distribution to be used */
  336. /* > to generate the random eigen-/singular values. */
  337. /* > 'U' => UNIFORM( 0, 1 ) ( 'U' for uniform ) */
  338. /* > 'S' => UNIFORM( -1, 1 ) ( 'S' for symmetric ) */
  339. /* > 'N' => NORMAL( 0, 1 ) ( 'N' for normal ) */
  340. /* > Not modified. */
  341. /* > \endverbatim */
  342. /* > */
  343. /* > \param[in,out] ISEED */
  344. /* > \verbatim */
  345. /* > ISEED is INTEGER array, dimension ( 4 ) */
  346. /* > On entry ISEED specifies the seed of the random number */
  347. /* > generator. They should lie between 0 and 4095 inclusive, */
  348. /* > and ISEED(4) should be odd. The random number generator */
  349. /* > uses a linear congruential sequence limited to small */
  350. /* > integers, and so should produce machine independent */
  351. /* > random numbers. The values of ISEED are changed on */
  352. /* > exit, and can be used in the next call to SLATMT */
  353. /* > to continue the same random number sequence. */
  354. /* > Changed on exit. */
  355. /* > \endverbatim */
  356. /* > */
  357. /* > \param[in] SYM */
  358. /* > \verbatim */
  359. /* > SYM is CHARACTER*1 */
  360. /* > If SYM='S' or 'H', the generated matrix is symmetric, with */
  361. /* > eigenvalues specified by D, COND, MODE, and DMAX; they */
  362. /* > may be positive, negative, or zero. */
  363. /* > If SYM='P', the generated matrix is symmetric, with */
  364. /* > eigenvalues (= singular values) specified by D, COND, */
  365. /* > MODE, and DMAX; they will not be negative. */
  366. /* > If SYM='N', the generated matrix is nonsymmetric, with */
  367. /* > singular values specified by D, COND, MODE, and DMAX; */
  368. /* > they will not be negative. */
  369. /* > Not modified. */
  370. /* > \endverbatim */
  371. /* > */
  372. /* > \param[in,out] D */
  373. /* > \verbatim */
  374. /* > D is REAL array, dimension ( MIN( M , N ) ) */
  375. /* > This array is used to specify the singular values or */
  376. /* > eigenvalues of A (see SYM, above.) If MODE=0, then D is */
  377. /* > assumed to contain the singular/eigenvalues, otherwise */
  378. /* > they will be computed according to MODE, COND, and DMAX, */
  379. /* > and placed in D. */
  380. /* > Modified if MODE is nonzero. */
  381. /* > \endverbatim */
  382. /* > */
  383. /* > \param[in] MODE */
  384. /* > \verbatim */
  385. /* > MODE is INTEGER */
  386. /* > On entry this describes how the singular/eigenvalues are to */
  387. /* > be specified: */
  388. /* > MODE = 0 means use D as input */
  389. /* > */
  390. /* > MODE = 1 sets D(1)=1 and D(2:RANK)=1.0/COND */
  391. /* > MODE = 2 sets D(1:RANK-1)=1 and D(RANK)=1.0/COND */
  392. /* > MODE = 3 sets D(I)=COND**(-(I-1)/(RANK-1)) */
  393. /* > */
  394. /* > MODE = 4 sets D(i)=1 - (i-1)/(N-1)*(1 - 1/COND) */
  395. /* > MODE = 5 sets D to random numbers in the range */
  396. /* > ( 1/COND , 1 ) such that their logarithms */
  397. /* > are uniformly distributed. */
  398. /* > MODE = 6 set D to random numbers from same distribution */
  399. /* > as the rest of the matrix. */
  400. /* > MODE < 0 has the same meaning as ABS(MODE), except that */
  401. /* > the order of the elements of D is reversed. */
  402. /* > Thus if MODE is positive, D has entries ranging from */
  403. /* > 1 to 1/COND, if negative, from 1/COND to 1, */
  404. /* > If SYM='S' or 'H', and MODE is neither 0, 6, nor -6, then */
  405. /* > the elements of D will also be multiplied by a random */
  406. /* > sign (i.e., +1 or -1.) */
  407. /* > Not modified. */
  408. /* > \endverbatim */
  409. /* > */
  410. /* > \param[in] COND */
  411. /* > \verbatim */
  412. /* > COND is REAL */
  413. /* > On entry, this is used as described under MODE above. */
  414. /* > If used, it must be >= 1. Not modified. */
  415. /* > \endverbatim */
  416. /* > */
  417. /* > \param[in] DMAX */
  418. /* > \verbatim */
  419. /* > DMAX is REAL */
  420. /* > If MODE is neither -6, 0 nor 6, the contents of D, as */
  421. /* > computed according to MODE and COND, will be scaled by */
  422. /* > DMAX / f2cmax(abs(D(i))); thus, the maximum absolute eigen- or */
  423. /* > singular value (which is to say the norm) will be abs(DMAX). */
  424. /* > Note that DMAX need not be positive: if DMAX is negative */
  425. /* > (or zero), D will be scaled by a negative number (or zero). */
  426. /* > Not modified. */
  427. /* > \endverbatim */
  428. /* > */
  429. /* > \param[in] RANK */
  430. /* > \verbatim */
  431. /* > RANK is INTEGER */
  432. /* > The rank of matrix to be generated for modes 1,2,3 only. */
  433. /* > D( RANK+1:N ) = 0. */
  434. /* > Not modified. */
  435. /* > \endverbatim */
  436. /* > */
  437. /* > \param[in] KL */
  438. /* > \verbatim */
  439. /* > KL is INTEGER */
  440. /* > This specifies the lower bandwidth of the matrix. For */
  441. /* > example, KL=0 implies upper triangular, KL=1 implies upper */
  442. /* > Hessenberg, and KL being at least M-1 means that the matrix */
  443. /* > has full lower bandwidth. KL must equal KU if the matrix */
  444. /* > is symmetric. */
  445. /* > Not modified. */
  446. /* > \endverbatim */
  447. /* > */
  448. /* > \param[in] KU */
  449. /* > \verbatim */
  450. /* > KU is INTEGER */
  451. /* > This specifies the upper bandwidth of the matrix. For */
  452. /* > example, KU=0 implies lower triangular, KU=1 implies lower */
  453. /* > Hessenberg, and KU being at least N-1 means that the matrix */
  454. /* > has full upper bandwidth. KL must equal KU if the matrix */
  455. /* > is symmetric. */
  456. /* > Not modified. */
  457. /* > \endverbatim */
  458. /* > */
  459. /* > \param[in] PACK */
  460. /* > \verbatim */
  461. /* > PACK is CHARACTER*1 */
  462. /* > This specifies packing of matrix as follows: */
  463. /* > 'N' => no packing */
  464. /* > 'U' => zero out all subdiagonal entries (if symmetric) */
  465. /* > 'L' => zero out all superdiagonal entries (if symmetric) */
  466. /* > 'C' => store the upper triangle columnwise */
  467. /* > (only if the matrix is symmetric or upper triangular) */
  468. /* > 'R' => store the lower triangle columnwise */
  469. /* > (only if the matrix is symmetric or lower triangular) */
  470. /* > 'B' => store the lower triangle in band storage scheme */
  471. /* > (only if matrix symmetric or lower triangular) */
  472. /* > 'Q' => store the upper triangle in band storage scheme */
  473. /* > (only if matrix symmetric or upper triangular) */
  474. /* > 'Z' => store the entire matrix in band storage scheme */
  475. /* > (pivoting can be provided for by using this */
  476. /* > option to store A in the trailing rows of */
  477. /* > the allocated storage) */
  478. /* > */
  479. /* > Using these options, the various LAPACK packed and banded */
  480. /* > storage schemes can be obtained: */
  481. /* > GB - use 'Z' */
  482. /* > PB, SB or TB - use 'B' or 'Q' */
  483. /* > PP, SP or TP - use 'C' or 'R' */
  484. /* > */
  485. /* > If two calls to SLATMT differ only in the PACK parameter, */
  486. /* > they will generate mathematically equivalent matrices. */
  487. /* > Not modified. */
  488. /* > \endverbatim */
  489. /* > */
  490. /* > \param[in,out] A */
  491. /* > \verbatim */
  492. /* > A is REAL array, dimension ( LDA, N ) */
  493. /* > On exit A is the desired test matrix. A is first generated */
  494. /* > in full (unpacked) form, and then packed, if so specified */
  495. /* > by PACK. Thus, the first M elements of the first N */
  496. /* > columns will always be modified. If PACK specifies a */
  497. /* > packed or banded storage scheme, all LDA elements of the */
  498. /* > first N columns will be modified; the elements of the */
  499. /* > array which do not correspond to elements of the generated */
  500. /* > matrix are set to zero. */
  501. /* > Modified. */
  502. /* > \endverbatim */
  503. /* > */
  504. /* > \param[in] LDA */
  505. /* > \verbatim */
  506. /* > LDA is INTEGER */
  507. /* > LDA specifies the first dimension of A as declared in the */
  508. /* > calling program. If PACK='N', 'U', 'L', 'C', or 'R', then */
  509. /* > LDA must be at least M. If PACK='B' or 'Q', then LDA must */
  510. /* > be at least MIN( KL, M-1) (which is equal to MIN(KU,N-1)). */
  511. /* > If PACK='Z', LDA must be large enough to hold the packed */
  512. /* > array: MIN( KU, N-1) + MIN( KL, M-1) + 1. */
  513. /* > Not modified. */
  514. /* > \endverbatim */
  515. /* > */
  516. /* > \param[out] WORK */
  517. /* > \verbatim */
  518. /* > WORK is REAL array, dimension ( 3*MAX( N , M ) ) */
  519. /* > Workspace. */
  520. /* > Modified. */
  521. /* > \endverbatim */
  522. /* > */
  523. /* > \param[out] INFO */
  524. /* > \verbatim */
  525. /* > INFO is INTEGER */
  526. /* > Error code. On exit, INFO will be set to one of the */
  527. /* > following values: */
  528. /* > 0 => normal return */
  529. /* > -1 => M negative or unequal to N and SYM='S', 'H', or 'P' */
  530. /* > -2 => N negative */
  531. /* > -3 => DIST illegal string */
  532. /* > -5 => SYM illegal string */
  533. /* > -7 => MODE not in range -6 to 6 */
  534. /* > -8 => COND less than 1.0, and MODE neither -6, 0 nor 6 */
  535. /* > -10 => KL negative */
  536. /* > -11 => KU negative, or SYM='S' or 'H' and KU not equal to KL */
  537. /* > -12 => PACK illegal string, or PACK='U' or 'L', and SYM='N'; */
  538. /* > or PACK='C' or 'Q' and SYM='N' and KL is not zero; */
  539. /* > or PACK='R' or 'B' and SYM='N' and KU is not zero; */
  540. /* > or PACK='U', 'L', 'C', 'R', 'B', or 'Q', and M is not */
  541. /* > N. */
  542. /* > -14 => LDA is less than M, or PACK='Z' and LDA is less than */
  543. /* > MIN(KU,N-1) + MIN(KL,M-1) + 1. */
  544. /* > 1 => Error return from SLATM7 */
  545. /* > 2 => Cannot scale to DMAX (f2cmax. sing. value is 0) */
  546. /* > 3 => Error return from SLAGGE or SLAGSY */
  547. /* > \endverbatim */
  548. /* Authors: */
  549. /* ======== */
  550. /* > \author Univ. of Tennessee */
  551. /* > \author Univ. of California Berkeley */
  552. /* > \author Univ. of Colorado Denver */
  553. /* > \author NAG Ltd. */
  554. /* > \date December 2016 */
  555. /* > \ingroup real_matgen */
  556. /* ===================================================================== */
  557. /* Subroutine */ void slatmt_(integer *m, integer *n, char *dist, integer *
  558. iseed, char *sym, real *d__, integer *mode, real *cond, real *dmax__,
  559. integer *rank, integer *kl, integer *ku, char *pack, real *a, integer
  560. *lda, real *work, integer *info)
  561. {
  562. /* System generated locals */
  563. integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5, i__6;
  564. real r__1, r__2, r__3;
  565. logical L__1;
  566. /* Local variables */
  567. integer ilda, icol;
  568. real temp;
  569. integer irow, isym;
  570. real c__;
  571. integer i__, j, k;
  572. real s, alpha, angle;
  573. integer ipack, ioffg;
  574. extern logical lsame_(char *, char *);
  575. integer iinfo;
  576. extern /* Subroutine */ void sscal_(integer *, real *, real *, integer *);
  577. integer idist, mnmin, iskew;
  578. real extra, dummy;
  579. extern /* Subroutine */ void scopy_(integer *, real *, integer *, real *,
  580. integer *), slatm7_(integer *, real *, integer *, integer *,
  581. integer *, real *, integer *, integer *, integer *);
  582. integer ic, jc, nc, il, iendch, ir, jr, ipackg, mr;
  583. extern /* Subroutine */ void slagge_(integer *, integer *, integer *,
  584. integer *, real *, real *, integer *, integer *, real *, integer *
  585. );
  586. integer minlda;
  587. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  588. extern real slarnd_(integer *, integer *);
  589. integer ioffst, irsign;
  590. logical givens, iltemp;
  591. extern /* Subroutine */ void slartg_(real *, real *, real *, real *, real *
  592. ), slaset_(char *, integer *, integer *, real *, real *, real *,
  593. integer *), slagsy_(integer *, integer *, real *, real *,
  594. integer *, integer *, real *, integer *), slarot_(logical *,
  595. logical *, logical *, integer *, real *, real *, real *, integer *
  596. , real *, real *);
  597. logical ilextr, topdwn;
  598. integer ir1, ir2, isympk, jch, llb, jkl, jku, uub;
  599. /* -- LAPACK computational routine (version 3.7.0) -- */
  600. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  601. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  602. /* December 2016 */
  603. /* ===================================================================== */
  604. /* 1) Decode and Test the input parameters. */
  605. /* Initialize flags & seed. */
  606. /* Parameter adjustments */
  607. --iseed;
  608. --d__;
  609. a_dim1 = *lda;
  610. a_offset = 1 + a_dim1 * 1;
  611. a -= a_offset;
  612. --work;
  613. /* Function Body */
  614. *info = 0;
  615. /* Quick return if possible */
  616. if (*m == 0 || *n == 0) {
  617. return;
  618. }
  619. /* Decode DIST */
  620. if (lsame_(dist, "U")) {
  621. idist = 1;
  622. } else if (lsame_(dist, "S")) {
  623. idist = 2;
  624. } else if (lsame_(dist, "N")) {
  625. idist = 3;
  626. } else {
  627. idist = -1;
  628. }
  629. /* Decode SYM */
  630. if (lsame_(sym, "N")) {
  631. isym = 1;
  632. irsign = 0;
  633. } else if (lsame_(sym, "P")) {
  634. isym = 2;
  635. irsign = 0;
  636. } else if (lsame_(sym, "S")) {
  637. isym = 2;
  638. irsign = 1;
  639. } else if (lsame_(sym, "H")) {
  640. isym = 2;
  641. irsign = 1;
  642. } else {
  643. isym = -1;
  644. }
  645. /* Decode PACK */
  646. isympk = 0;
  647. if (lsame_(pack, "N")) {
  648. ipack = 0;
  649. } else if (lsame_(pack, "U")) {
  650. ipack = 1;
  651. isympk = 1;
  652. } else if (lsame_(pack, "L")) {
  653. ipack = 2;
  654. isympk = 1;
  655. } else if (lsame_(pack, "C")) {
  656. ipack = 3;
  657. isympk = 2;
  658. } else if (lsame_(pack, "R")) {
  659. ipack = 4;
  660. isympk = 3;
  661. } else if (lsame_(pack, "B")) {
  662. ipack = 5;
  663. isympk = 3;
  664. } else if (lsame_(pack, "Q")) {
  665. ipack = 6;
  666. isympk = 2;
  667. } else if (lsame_(pack, "Z")) {
  668. ipack = 7;
  669. } else {
  670. ipack = -1;
  671. }
  672. /* Set certain internal parameters */
  673. mnmin = f2cmin(*m,*n);
  674. /* Computing MIN */
  675. i__1 = *kl, i__2 = *m - 1;
  676. llb = f2cmin(i__1,i__2);
  677. /* Computing MIN */
  678. i__1 = *ku, i__2 = *n - 1;
  679. uub = f2cmin(i__1,i__2);
  680. /* Computing MIN */
  681. i__1 = *m, i__2 = *n + llb;
  682. mr = f2cmin(i__1,i__2);
  683. /* Computing MIN */
  684. i__1 = *n, i__2 = *m + uub;
  685. nc = f2cmin(i__1,i__2);
  686. if (ipack == 5 || ipack == 6) {
  687. minlda = uub + 1;
  688. } else if (ipack == 7) {
  689. minlda = llb + uub + 1;
  690. } else {
  691. minlda = *m;
  692. }
  693. /* Use Givens rotation method if bandwidth small enough, */
  694. /* or if LDA is too small to store the matrix unpacked. */
  695. givens = FALSE_;
  696. if (isym == 1) {
  697. /* Computing MAX */
  698. i__1 = 1, i__2 = mr + nc;
  699. if ((real) (llb + uub) < (real) f2cmax(i__1,i__2) * .3f) {
  700. givens = TRUE_;
  701. }
  702. } else {
  703. if (llb << 1 < *m) {
  704. givens = TRUE_;
  705. }
  706. }
  707. if (*lda < *m && *lda >= minlda) {
  708. givens = TRUE_;
  709. }
  710. /* Set INFO if an error */
  711. if (*m < 0) {
  712. *info = -1;
  713. } else if (*m != *n && isym != 1) {
  714. *info = -1;
  715. } else if (*n < 0) {
  716. *info = -2;
  717. } else if (idist == -1) {
  718. *info = -3;
  719. } else if (isym == -1) {
  720. *info = -5;
  721. } else if (abs(*mode) > 6) {
  722. *info = -7;
  723. } else if (*mode != 0 && abs(*mode) != 6 && *cond < 1.f) {
  724. *info = -8;
  725. } else if (*kl < 0) {
  726. *info = -10;
  727. } else if (*ku < 0 || isym != 1 && *kl != *ku) {
  728. *info = -11;
  729. } else if (ipack == -1 || isympk == 1 && isym == 1 || isympk == 2 && isym
  730. == 1 && *kl > 0 || isympk == 3 && isym == 1 && *ku > 0 || isympk
  731. != 0 && *m != *n) {
  732. *info = -12;
  733. } else if (*lda < f2cmax(1,minlda)) {
  734. *info = -14;
  735. }
  736. if (*info != 0) {
  737. i__1 = -(*info);
  738. xerbla_("SLATMT", &i__1, 6);
  739. return;
  740. }
  741. /* Initialize random number generator */
  742. for (i__ = 1; i__ <= 4; ++i__) {
  743. iseed[i__] = (i__1 = iseed[i__], abs(i__1)) % 4096;
  744. /* L100: */
  745. }
  746. if (iseed[4] % 2 != 1) {
  747. ++iseed[4];
  748. }
  749. /* 2) Set up D if indicated. */
  750. /* Compute D according to COND and MODE */
  751. slatm7_(mode, cond, &irsign, &idist, &iseed[1], &d__[1], &mnmin, rank, &
  752. iinfo);
  753. if (iinfo != 0) {
  754. *info = 1;
  755. return;
  756. }
  757. /* Choose Top-Down if D is (apparently) increasing, */
  758. /* Bottom-Up if D is (apparently) decreasing. */
  759. if (abs(d__[1]) <= (r__1 = d__[*rank], abs(r__1))) {
  760. topdwn = TRUE_;
  761. } else {
  762. topdwn = FALSE_;
  763. }
  764. if (*mode != 0 && abs(*mode) != 6) {
  765. /* Scale by DMAX */
  766. temp = abs(d__[1]);
  767. i__1 = *rank;
  768. for (i__ = 2; i__ <= i__1; ++i__) {
  769. /* Computing MAX */
  770. r__2 = temp, r__3 = (r__1 = d__[i__], abs(r__1));
  771. temp = f2cmax(r__2,r__3);
  772. /* L110: */
  773. }
  774. if (temp > 0.f) {
  775. alpha = *dmax__ / temp;
  776. } else {
  777. *info = 2;
  778. return;
  779. }
  780. sscal_(rank, &alpha, &d__[1], &c__1);
  781. }
  782. /* 3) Generate Banded Matrix using Givens rotations. */
  783. /* Also the special case of UUB=LLB=0 */
  784. /* Compute Addressing constants to cover all */
  785. /* storage formats. Whether GE, SY, GB, or SB, */
  786. /* upper or lower triangle or both, */
  787. /* the (i,j)-th element is in */
  788. /* A( i - ISKEW*j + IOFFST, j ) */
  789. if (ipack > 4) {
  790. ilda = *lda - 1;
  791. iskew = 1;
  792. if (ipack > 5) {
  793. ioffst = uub + 1;
  794. } else {
  795. ioffst = 1;
  796. }
  797. } else {
  798. ilda = *lda;
  799. iskew = 0;
  800. ioffst = 0;
  801. }
  802. /* IPACKG is the format that the matrix is generated in. If this is */
  803. /* different from IPACK, then the matrix must be repacked at the */
  804. /* end. It also signals how to compute the norm, for scaling. */
  805. ipackg = 0;
  806. slaset_("Full", lda, n, &c_b22, &c_b22, &a[a_offset], lda);
  807. /* Diagonal Matrix -- We are done, unless it */
  808. /* is to be stored SP/PP/TP (PACK='R' or 'C') */
  809. if (llb == 0 && uub == 0) {
  810. i__1 = ilda + 1;
  811. scopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffst + a_dim1], &i__1)
  812. ;
  813. if (ipack <= 2 || ipack >= 5) {
  814. ipackg = ipack;
  815. }
  816. } else if (givens) {
  817. /* Check whether to use Givens rotations, */
  818. /* Householder transformations, or nothing. */
  819. if (isym == 1) {
  820. /* Non-symmetric -- A = U D V */
  821. if (ipack > 4) {
  822. ipackg = ipack;
  823. } else {
  824. ipackg = 0;
  825. }
  826. i__1 = ilda + 1;
  827. scopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffst + a_dim1], &
  828. i__1);
  829. if (topdwn) {
  830. jkl = 0;
  831. i__1 = uub;
  832. for (jku = 1; jku <= i__1; ++jku) {
  833. /* Transform from bandwidth JKL, JKU-1 to JKL, JKU */
  834. /* Last row actually rotated is M */
  835. /* Last column actually rotated is MIN( M+JKU, N ) */
  836. /* Computing MIN */
  837. i__3 = *m + jku;
  838. i__2 = f2cmin(i__3,*n) + jkl - 1;
  839. for (jr = 1; jr <= i__2; ++jr) {
  840. extra = 0.f;
  841. angle = slarnd_(&c__1, &iseed[1]) *
  842. 6.2831853071795864769252867663f;
  843. c__ = cos(angle);
  844. s = sin(angle);
  845. /* Computing MAX */
  846. i__3 = 1, i__4 = jr - jkl;
  847. icol = f2cmax(i__3,i__4);
  848. if (jr < *m) {
  849. /* Computing MIN */
  850. i__3 = *n, i__4 = jr + jku;
  851. il = f2cmin(i__3,i__4) + 1 - icol;
  852. L__1 = jr > jkl;
  853. slarot_(&c_true, &L__1, &c_false, &il, &c__, &s, &
  854. a[jr - iskew * icol + ioffst + icol *
  855. a_dim1], &ilda, &extra, &dummy);
  856. }
  857. /* Chase "EXTRA" back up */
  858. ir = jr;
  859. ic = icol;
  860. i__3 = -jkl - jku;
  861. for (jch = jr - jkl; i__3 < 0 ? jch >= 1 : jch <= 1;
  862. jch += i__3) {
  863. if (ir < *m) {
  864. slartg_(&a[ir + 1 - iskew * (ic + 1) + ioffst
  865. + (ic + 1) * a_dim1], &extra, &c__, &
  866. s, &dummy);
  867. }
  868. /* Computing MAX */
  869. i__4 = 1, i__5 = jch - jku;
  870. irow = f2cmax(i__4,i__5);
  871. il = ir + 2 - irow;
  872. temp = 0.f;
  873. iltemp = jch > jku;
  874. r__1 = -s;
  875. slarot_(&c_false, &iltemp, &c_true, &il, &c__, &
  876. r__1, &a[irow - iskew * ic + ioffst + ic *
  877. a_dim1], &ilda, &temp, &extra);
  878. if (iltemp) {
  879. slartg_(&a[irow + 1 - iskew * (ic + 1) +
  880. ioffst + (ic + 1) * a_dim1], &temp, &
  881. c__, &s, &dummy);
  882. /* Computing MAX */
  883. i__4 = 1, i__5 = jch - jku - jkl;
  884. icol = f2cmax(i__4,i__5);
  885. il = ic + 2 - icol;
  886. extra = 0.f;
  887. L__1 = jch > jku + jkl;
  888. r__1 = -s;
  889. slarot_(&c_true, &L__1, &c_true, &il, &c__, &
  890. r__1, &a[irow - iskew * icol + ioffst
  891. + icol * a_dim1], &ilda, &extra, &
  892. temp);
  893. ic = icol;
  894. ir = irow;
  895. }
  896. /* L120: */
  897. }
  898. /* L130: */
  899. }
  900. /* L140: */
  901. }
  902. jku = uub;
  903. i__1 = llb;
  904. for (jkl = 1; jkl <= i__1; ++jkl) {
  905. /* Transform from bandwidth JKL-1, JKU to JKL, JKU */
  906. /* Computing MIN */
  907. i__3 = *n + jkl;
  908. i__2 = f2cmin(i__3,*m) + jku - 1;
  909. for (jc = 1; jc <= i__2; ++jc) {
  910. extra = 0.f;
  911. angle = slarnd_(&c__1, &iseed[1]) *
  912. 6.2831853071795864769252867663f;
  913. c__ = cos(angle);
  914. s = sin(angle);
  915. /* Computing MAX */
  916. i__3 = 1, i__4 = jc - jku;
  917. irow = f2cmax(i__3,i__4);
  918. if (jc < *n) {
  919. /* Computing MIN */
  920. i__3 = *m, i__4 = jc + jkl;
  921. il = f2cmin(i__3,i__4) + 1 - irow;
  922. L__1 = jc > jku;
  923. slarot_(&c_false, &L__1, &c_false, &il, &c__, &s,
  924. &a[irow - iskew * jc + ioffst + jc *
  925. a_dim1], &ilda, &extra, &dummy);
  926. }
  927. /* Chase "EXTRA" back up */
  928. ic = jc;
  929. ir = irow;
  930. i__3 = -jkl - jku;
  931. for (jch = jc - jku; i__3 < 0 ? jch >= 1 : jch <= 1;
  932. jch += i__3) {
  933. if (ic < *n) {
  934. slartg_(&a[ir + 1 - iskew * (ic + 1) + ioffst
  935. + (ic + 1) * a_dim1], &extra, &c__, &
  936. s, &dummy);
  937. }
  938. /* Computing MAX */
  939. i__4 = 1, i__5 = jch - jkl;
  940. icol = f2cmax(i__4,i__5);
  941. il = ic + 2 - icol;
  942. temp = 0.f;
  943. iltemp = jch > jkl;
  944. r__1 = -s;
  945. slarot_(&c_true, &iltemp, &c_true, &il, &c__, &
  946. r__1, &a[ir - iskew * icol + ioffst +
  947. icol * a_dim1], &ilda, &temp, &extra);
  948. if (iltemp) {
  949. slartg_(&a[ir + 1 - iskew * (icol + 1) +
  950. ioffst + (icol + 1) * a_dim1], &temp,
  951. &c__, &s, &dummy);
  952. /* Computing MAX */
  953. i__4 = 1, i__5 = jch - jkl - jku;
  954. irow = f2cmax(i__4,i__5);
  955. il = ir + 2 - irow;
  956. extra = 0.f;
  957. L__1 = jch > jkl + jku;
  958. r__1 = -s;
  959. slarot_(&c_false, &L__1, &c_true, &il, &c__, &
  960. r__1, &a[irow - iskew * icol + ioffst
  961. + icol * a_dim1], &ilda, &extra, &
  962. temp);
  963. ic = icol;
  964. ir = irow;
  965. }
  966. /* L150: */
  967. }
  968. /* L160: */
  969. }
  970. /* L170: */
  971. }
  972. } else {
  973. /* Bottom-Up -- Start at the bottom right. */
  974. jkl = 0;
  975. i__1 = uub;
  976. for (jku = 1; jku <= i__1; ++jku) {
  977. /* Transform from bandwidth JKL, JKU-1 to JKL, JKU */
  978. /* First row actually rotated is M */
  979. /* First column actually rotated is MIN( M+JKU, N ) */
  980. /* Computing MIN */
  981. i__2 = *m, i__3 = *n + jkl;
  982. iendch = f2cmin(i__2,i__3) - 1;
  983. /* Computing MIN */
  984. i__2 = *m + jku;
  985. i__3 = 1 - jkl;
  986. for (jc = f2cmin(i__2,*n) - 1; jc >= i__3; --jc) {
  987. extra = 0.f;
  988. angle = slarnd_(&c__1, &iseed[1]) *
  989. 6.2831853071795864769252867663f;
  990. c__ = cos(angle);
  991. s = sin(angle);
  992. /* Computing MAX */
  993. i__2 = 1, i__4 = jc - jku + 1;
  994. irow = f2cmax(i__2,i__4);
  995. if (jc > 0) {
  996. /* Computing MIN */
  997. i__2 = *m, i__4 = jc + jkl + 1;
  998. il = f2cmin(i__2,i__4) + 1 - irow;
  999. L__1 = jc + jkl < *m;
  1000. slarot_(&c_false, &c_false, &L__1, &il, &c__, &s,
  1001. &a[irow - iskew * jc + ioffst + jc *
  1002. a_dim1], &ilda, &dummy, &extra);
  1003. }
  1004. /* Chase "EXTRA" back down */
  1005. ic = jc;
  1006. i__2 = iendch;
  1007. i__4 = jkl + jku;
  1008. for (jch = jc + jkl; i__4 < 0 ? jch >= i__2 : jch <=
  1009. i__2; jch += i__4) {
  1010. ilextr = ic > 0;
  1011. if (ilextr) {
  1012. slartg_(&a[jch - iskew * ic + ioffst + ic *
  1013. a_dim1], &extra, &c__, &s, &dummy);
  1014. }
  1015. ic = f2cmax(1,ic);
  1016. /* Computing MIN */
  1017. i__5 = *n - 1, i__6 = jch + jku;
  1018. icol = f2cmin(i__5,i__6);
  1019. iltemp = jch + jku < *n;
  1020. temp = 0.f;
  1021. i__5 = icol + 2 - ic;
  1022. slarot_(&c_true, &ilextr, &iltemp, &i__5, &c__, &
  1023. s, &a[jch - iskew * ic + ioffst + ic *
  1024. a_dim1], &ilda, &extra, &temp);
  1025. if (iltemp) {
  1026. slartg_(&a[jch - iskew * icol + ioffst + icol
  1027. * a_dim1], &temp, &c__, &s, &dummy);
  1028. /* Computing MIN */
  1029. i__5 = iendch, i__6 = jch + jkl + jku;
  1030. il = f2cmin(i__5,i__6) + 2 - jch;
  1031. extra = 0.f;
  1032. L__1 = jch + jkl + jku <= iendch;
  1033. slarot_(&c_false, &c_true, &L__1, &il, &c__, &
  1034. s, &a[jch - iskew * icol + ioffst +
  1035. icol * a_dim1], &ilda, &temp, &extra);
  1036. ic = icol;
  1037. }
  1038. /* L180: */
  1039. }
  1040. /* L190: */
  1041. }
  1042. /* L200: */
  1043. }
  1044. jku = uub;
  1045. i__1 = llb;
  1046. for (jkl = 1; jkl <= i__1; ++jkl) {
  1047. /* Transform from bandwidth JKL-1, JKU to JKL, JKU */
  1048. /* First row actually rotated is MIN( N+JKL, M ) */
  1049. /* First column actually rotated is N */
  1050. /* Computing MIN */
  1051. i__3 = *n, i__4 = *m + jku;
  1052. iendch = f2cmin(i__3,i__4) - 1;
  1053. /* Computing MIN */
  1054. i__3 = *n + jkl;
  1055. i__4 = 1 - jku;
  1056. for (jr = f2cmin(i__3,*m) - 1; jr >= i__4; --jr) {
  1057. extra = 0.f;
  1058. angle = slarnd_(&c__1, &iseed[1]) *
  1059. 6.2831853071795864769252867663f;
  1060. c__ = cos(angle);
  1061. s = sin(angle);
  1062. /* Computing MAX */
  1063. i__3 = 1, i__2 = jr - jkl + 1;
  1064. icol = f2cmax(i__3,i__2);
  1065. if (jr > 0) {
  1066. /* Computing MIN */
  1067. i__3 = *n, i__2 = jr + jku + 1;
  1068. il = f2cmin(i__3,i__2) + 1 - icol;
  1069. L__1 = jr + jku < *n;
  1070. slarot_(&c_true, &c_false, &L__1, &il, &c__, &s, &
  1071. a[jr - iskew * icol + ioffst + icol *
  1072. a_dim1], &ilda, &dummy, &extra);
  1073. }
  1074. /* Chase "EXTRA" back down */
  1075. ir = jr;
  1076. i__3 = iendch;
  1077. i__2 = jkl + jku;
  1078. for (jch = jr + jku; i__2 < 0 ? jch >= i__3 : jch <=
  1079. i__3; jch += i__2) {
  1080. ilextr = ir > 0;
  1081. if (ilextr) {
  1082. slartg_(&a[ir - iskew * jch + ioffst + jch *
  1083. a_dim1], &extra, &c__, &s, &dummy);
  1084. }
  1085. ir = f2cmax(1,ir);
  1086. /* Computing MIN */
  1087. i__5 = *m - 1, i__6 = jch + jkl;
  1088. irow = f2cmin(i__5,i__6);
  1089. iltemp = jch + jkl < *m;
  1090. temp = 0.f;
  1091. i__5 = irow + 2 - ir;
  1092. slarot_(&c_false, &ilextr, &iltemp, &i__5, &c__, &
  1093. s, &a[ir - iskew * jch + ioffst + jch *
  1094. a_dim1], &ilda, &extra, &temp);
  1095. if (iltemp) {
  1096. slartg_(&a[irow - iskew * jch + ioffst + jch *
  1097. a_dim1], &temp, &c__, &s, &dummy);
  1098. /* Computing MIN */
  1099. i__5 = iendch, i__6 = jch + jkl + jku;
  1100. il = f2cmin(i__5,i__6) + 2 - jch;
  1101. extra = 0.f;
  1102. L__1 = jch + jkl + jku <= iendch;
  1103. slarot_(&c_true, &c_true, &L__1, &il, &c__, &
  1104. s, &a[irow - iskew * jch + ioffst +
  1105. jch * a_dim1], &ilda, &temp, &extra);
  1106. ir = irow;
  1107. }
  1108. /* L210: */
  1109. }
  1110. /* L220: */
  1111. }
  1112. /* L230: */
  1113. }
  1114. }
  1115. } else {
  1116. /* Symmetric -- A = U D U' */
  1117. ipackg = ipack;
  1118. ioffg = ioffst;
  1119. if (topdwn) {
  1120. /* Top-Down -- Generate Upper triangle only */
  1121. if (ipack >= 5) {
  1122. ipackg = 6;
  1123. ioffg = uub + 1;
  1124. } else {
  1125. ipackg = 1;
  1126. }
  1127. i__1 = ilda + 1;
  1128. scopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffg + a_dim1],
  1129. &i__1);
  1130. i__1 = uub;
  1131. for (k = 1; k <= i__1; ++k) {
  1132. i__4 = *n - 1;
  1133. for (jc = 1; jc <= i__4; ++jc) {
  1134. /* Computing MAX */
  1135. i__2 = 1, i__3 = jc - k;
  1136. irow = f2cmax(i__2,i__3);
  1137. /* Computing MIN */
  1138. i__2 = jc + 1, i__3 = k + 2;
  1139. il = f2cmin(i__2,i__3);
  1140. extra = 0.f;
  1141. temp = a[jc - iskew * (jc + 1) + ioffg + (jc + 1) *
  1142. a_dim1];
  1143. angle = slarnd_(&c__1, &iseed[1]) *
  1144. 6.2831853071795864769252867663f;
  1145. c__ = cos(angle);
  1146. s = sin(angle);
  1147. L__1 = jc > k;
  1148. slarot_(&c_false, &L__1, &c_true, &il, &c__, &s, &a[
  1149. irow - iskew * jc + ioffg + jc * a_dim1], &
  1150. ilda, &extra, &temp);
  1151. /* Computing MIN */
  1152. i__3 = k, i__5 = *n - jc;
  1153. i__2 = f2cmin(i__3,i__5) + 1;
  1154. slarot_(&c_true, &c_true, &c_false, &i__2, &c__, &s, &
  1155. a[(1 - iskew) * jc + ioffg + jc * a_dim1], &
  1156. ilda, &temp, &dummy);
  1157. /* Chase EXTRA back up the matrix */
  1158. icol = jc;
  1159. i__2 = -k;
  1160. for (jch = jc - k; i__2 < 0 ? jch >= 1 : jch <= 1;
  1161. jch += i__2) {
  1162. slartg_(&a[jch + 1 - iskew * (icol + 1) + ioffg +
  1163. (icol + 1) * a_dim1], &extra, &c__, &s, &
  1164. dummy);
  1165. temp = a[jch - iskew * (jch + 1) + ioffg + (jch +
  1166. 1) * a_dim1];
  1167. i__3 = k + 2;
  1168. r__1 = -s;
  1169. slarot_(&c_true, &c_true, &c_true, &i__3, &c__, &
  1170. r__1, &a[(1 - iskew) * jch + ioffg + jch *
  1171. a_dim1], &ilda, &temp, &extra);
  1172. /* Computing MAX */
  1173. i__3 = 1, i__5 = jch - k;
  1174. irow = f2cmax(i__3,i__5);
  1175. /* Computing MIN */
  1176. i__3 = jch + 1, i__5 = k + 2;
  1177. il = f2cmin(i__3,i__5);
  1178. extra = 0.f;
  1179. L__1 = jch > k;
  1180. r__1 = -s;
  1181. slarot_(&c_false, &L__1, &c_true, &il, &c__, &
  1182. r__1, &a[irow - iskew * jch + ioffg + jch
  1183. * a_dim1], &ilda, &extra, &temp);
  1184. icol = jch;
  1185. /* L240: */
  1186. }
  1187. /* L250: */
  1188. }
  1189. /* L260: */
  1190. }
  1191. /* If we need lower triangle, copy from upper. Note that */
  1192. /* the order of copying is chosen to work for 'q' -> 'b' */
  1193. if (ipack != ipackg && ipack != 3) {
  1194. i__1 = *n;
  1195. for (jc = 1; jc <= i__1; ++jc) {
  1196. irow = ioffst - iskew * jc;
  1197. /* Computing MIN */
  1198. i__2 = *n, i__3 = jc + uub;
  1199. i__4 = f2cmin(i__2,i__3);
  1200. for (jr = jc; jr <= i__4; ++jr) {
  1201. a[jr + irow + jc * a_dim1] = a[jc - iskew * jr +
  1202. ioffg + jr * a_dim1];
  1203. /* L270: */
  1204. }
  1205. /* L280: */
  1206. }
  1207. if (ipack == 5) {
  1208. i__1 = *n;
  1209. for (jc = *n - uub + 1; jc <= i__1; ++jc) {
  1210. i__4 = uub + 1;
  1211. for (jr = *n + 2 - jc; jr <= i__4; ++jr) {
  1212. a[jr + jc * a_dim1] = 0.f;
  1213. /* L290: */
  1214. }
  1215. /* L300: */
  1216. }
  1217. }
  1218. if (ipackg == 6) {
  1219. ipackg = ipack;
  1220. } else {
  1221. ipackg = 0;
  1222. }
  1223. }
  1224. } else {
  1225. /* Bottom-Up -- Generate Lower triangle only */
  1226. if (ipack >= 5) {
  1227. ipackg = 5;
  1228. if (ipack == 6) {
  1229. ioffg = 1;
  1230. }
  1231. } else {
  1232. ipackg = 2;
  1233. }
  1234. i__1 = ilda + 1;
  1235. scopy_(&mnmin, &d__[1], &c__1, &a[1 - iskew + ioffg + a_dim1],
  1236. &i__1);
  1237. i__1 = uub;
  1238. for (k = 1; k <= i__1; ++k) {
  1239. for (jc = *n - 1; jc >= 1; --jc) {
  1240. /* Computing MIN */
  1241. i__4 = *n + 1 - jc, i__2 = k + 2;
  1242. il = f2cmin(i__4,i__2);
  1243. extra = 0.f;
  1244. temp = a[(1 - iskew) * jc + 1 + ioffg + jc * a_dim1];
  1245. angle = slarnd_(&c__1, &iseed[1]) *
  1246. 6.2831853071795864769252867663f;
  1247. c__ = cos(angle);
  1248. s = -sin(angle);
  1249. L__1 = *n - jc > k;
  1250. slarot_(&c_false, &c_true, &L__1, &il, &c__, &s, &a[(
  1251. 1 - iskew) * jc + ioffg + jc * a_dim1], &ilda,
  1252. &temp, &extra);
  1253. /* Computing MAX */
  1254. i__4 = 1, i__2 = jc - k + 1;
  1255. icol = f2cmax(i__4,i__2);
  1256. i__4 = jc + 2 - icol;
  1257. slarot_(&c_true, &c_false, &c_true, &i__4, &c__, &s, &
  1258. a[jc - iskew * icol + ioffg + icol * a_dim1],
  1259. &ilda, &dummy, &temp);
  1260. /* Chase EXTRA back down the matrix */
  1261. icol = jc;
  1262. i__4 = *n - 1;
  1263. i__2 = k;
  1264. for (jch = jc + k; i__2 < 0 ? jch >= i__4 : jch <=
  1265. i__4; jch += i__2) {
  1266. slartg_(&a[jch - iskew * icol + ioffg + icol *
  1267. a_dim1], &extra, &c__, &s, &dummy);
  1268. temp = a[(1 - iskew) * jch + 1 + ioffg + jch *
  1269. a_dim1];
  1270. i__3 = k + 2;
  1271. slarot_(&c_true, &c_true, &c_true, &i__3, &c__, &
  1272. s, &a[jch - iskew * icol + ioffg + icol *
  1273. a_dim1], &ilda, &extra, &temp);
  1274. /* Computing MIN */
  1275. i__3 = *n + 1 - jch, i__5 = k + 2;
  1276. il = f2cmin(i__3,i__5);
  1277. extra = 0.f;
  1278. L__1 = *n - jch > k;
  1279. slarot_(&c_false, &c_true, &L__1, &il, &c__, &s, &
  1280. a[(1 - iskew) * jch + ioffg + jch *
  1281. a_dim1], &ilda, &temp, &extra);
  1282. icol = jch;
  1283. /* L310: */
  1284. }
  1285. /* L320: */
  1286. }
  1287. /* L330: */
  1288. }
  1289. /* If we need upper triangle, copy from lower. Note that */
  1290. /* the order of copying is chosen to work for 'b' -> 'q' */
  1291. if (ipack != ipackg && ipack != 4) {
  1292. for (jc = *n; jc >= 1; --jc) {
  1293. irow = ioffst - iskew * jc;
  1294. /* Computing MAX */
  1295. i__2 = 1, i__4 = jc - uub;
  1296. i__1 = f2cmax(i__2,i__4);
  1297. for (jr = jc; jr >= i__1; --jr) {
  1298. a[jr + irow + jc * a_dim1] = a[jc - iskew * jr +
  1299. ioffg + jr * a_dim1];
  1300. /* L340: */
  1301. }
  1302. /* L350: */
  1303. }
  1304. if (ipack == 6) {
  1305. i__1 = uub;
  1306. for (jc = 1; jc <= i__1; ++jc) {
  1307. i__2 = uub + 1 - jc;
  1308. for (jr = 1; jr <= i__2; ++jr) {
  1309. a[jr + jc * a_dim1] = 0.f;
  1310. /* L360: */
  1311. }
  1312. /* L370: */
  1313. }
  1314. }
  1315. if (ipackg == 5) {
  1316. ipackg = ipack;
  1317. } else {
  1318. ipackg = 0;
  1319. }
  1320. }
  1321. }
  1322. }
  1323. } else {
  1324. /* 4) Generate Banded Matrix by first */
  1325. /* Rotating by random Unitary matrices, */
  1326. /* then reducing the bandwidth using Householder */
  1327. /* transformations. */
  1328. /* Note: we should get here only if LDA .ge. N */
  1329. if (isym == 1) {
  1330. /* Non-symmetric -- A = U D V */
  1331. slagge_(&mr, &nc, &llb, &uub, &d__[1], &a[a_offset], lda, &iseed[
  1332. 1], &work[1], &iinfo);
  1333. } else {
  1334. /* Symmetric -- A = U D U' */
  1335. slagsy_(m, &llb, &d__[1], &a[a_offset], lda, &iseed[1], &work[1],
  1336. &iinfo);
  1337. }
  1338. if (iinfo != 0) {
  1339. *info = 3;
  1340. return;
  1341. }
  1342. }
  1343. /* 5) Pack the matrix */
  1344. if (ipack != ipackg) {
  1345. if (ipack == 1) {
  1346. /* 'U' -- Upper triangular, not packed */
  1347. i__1 = *m;
  1348. for (j = 1; j <= i__1; ++j) {
  1349. i__2 = *m;
  1350. for (i__ = j + 1; i__ <= i__2; ++i__) {
  1351. a[i__ + j * a_dim1] = 0.f;
  1352. /* L380: */
  1353. }
  1354. /* L390: */
  1355. }
  1356. } else if (ipack == 2) {
  1357. /* 'L' -- Lower triangular, not packed */
  1358. i__1 = *m;
  1359. for (j = 2; j <= i__1; ++j) {
  1360. i__2 = j - 1;
  1361. for (i__ = 1; i__ <= i__2; ++i__) {
  1362. a[i__ + j * a_dim1] = 0.f;
  1363. /* L400: */
  1364. }
  1365. /* L410: */
  1366. }
  1367. } else if (ipack == 3) {
  1368. /* 'C' -- Upper triangle packed Columnwise. */
  1369. icol = 1;
  1370. irow = 0;
  1371. i__1 = *m;
  1372. for (j = 1; j <= i__1; ++j) {
  1373. i__2 = j;
  1374. for (i__ = 1; i__ <= i__2; ++i__) {
  1375. ++irow;
  1376. if (irow > *lda) {
  1377. irow = 1;
  1378. ++icol;
  1379. }
  1380. a[irow + icol * a_dim1] = a[i__ + j * a_dim1];
  1381. /* L420: */
  1382. }
  1383. /* L430: */
  1384. }
  1385. } else if (ipack == 4) {
  1386. /* 'R' -- Lower triangle packed Columnwise. */
  1387. icol = 1;
  1388. irow = 0;
  1389. i__1 = *m;
  1390. for (j = 1; j <= i__1; ++j) {
  1391. i__2 = *m;
  1392. for (i__ = j; i__ <= i__2; ++i__) {
  1393. ++irow;
  1394. if (irow > *lda) {
  1395. irow = 1;
  1396. ++icol;
  1397. }
  1398. a[irow + icol * a_dim1] = a[i__ + j * a_dim1];
  1399. /* L440: */
  1400. }
  1401. /* L450: */
  1402. }
  1403. } else if (ipack >= 5) {
  1404. /* 'B' -- The lower triangle is packed as a band matrix. */
  1405. /* 'Q' -- The upper triangle is packed as a band matrix. */
  1406. /* 'Z' -- The whole matrix is packed as a band matrix. */
  1407. if (ipack == 5) {
  1408. uub = 0;
  1409. }
  1410. if (ipack == 6) {
  1411. llb = 0;
  1412. }
  1413. i__1 = uub;
  1414. for (j = 1; j <= i__1; ++j) {
  1415. /* Computing MIN */
  1416. i__2 = j + llb;
  1417. for (i__ = f2cmin(i__2,*m); i__ >= 1; --i__) {
  1418. a[i__ - j + uub + 1 + j * a_dim1] = a[i__ + j * a_dim1];
  1419. /* L460: */
  1420. }
  1421. /* L470: */
  1422. }
  1423. i__1 = *n;
  1424. for (j = uub + 2; j <= i__1; ++j) {
  1425. /* Computing MIN */
  1426. i__4 = j + llb;
  1427. i__2 = f2cmin(i__4,*m);
  1428. for (i__ = j - uub; i__ <= i__2; ++i__) {
  1429. a[i__ - j + uub + 1 + j * a_dim1] = a[i__ + j * a_dim1];
  1430. /* L480: */
  1431. }
  1432. /* L490: */
  1433. }
  1434. }
  1435. /* If packed, zero out extraneous elements. */
  1436. /* Symmetric/Triangular Packed -- */
  1437. /* zero out everything after A(IROW,ICOL) */
  1438. if (ipack == 3 || ipack == 4) {
  1439. i__1 = *m;
  1440. for (jc = icol; jc <= i__1; ++jc) {
  1441. i__2 = *lda;
  1442. for (jr = irow + 1; jr <= i__2; ++jr) {
  1443. a[jr + jc * a_dim1] = 0.f;
  1444. /* L500: */
  1445. }
  1446. irow = 0;
  1447. /* L510: */
  1448. }
  1449. } else if (ipack >= 5) {
  1450. /* Packed Band -- */
  1451. /* 1st row is now in A( UUB+2-j, j), zero above it */
  1452. /* m-th row is now in A( M+UUB-j,j), zero below it */
  1453. /* last non-zero diagonal is now in A( UUB+LLB+1,j ), */
  1454. /* zero below it, too. */
  1455. ir1 = uub + llb + 2;
  1456. ir2 = uub + *m + 2;
  1457. i__1 = *n;
  1458. for (jc = 1; jc <= i__1; ++jc) {
  1459. i__2 = uub + 1 - jc;
  1460. for (jr = 1; jr <= i__2; ++jr) {
  1461. a[jr + jc * a_dim1] = 0.f;
  1462. /* L520: */
  1463. }
  1464. /* Computing MAX */
  1465. /* Computing MIN */
  1466. i__3 = ir1, i__5 = ir2 - jc;
  1467. i__2 = 1, i__4 = f2cmin(i__3,i__5);
  1468. i__6 = *lda;
  1469. for (jr = f2cmax(i__2,i__4); jr <= i__6; ++jr) {
  1470. a[jr + jc * a_dim1] = 0.f;
  1471. /* L530: */
  1472. }
  1473. /* L540: */
  1474. }
  1475. }
  1476. }
  1477. return;
  1478. /* End of SLATMT */
  1479. } /* slatmt_ */