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.

slaln2.c 29 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  1. /* f2c.h -- Standard Fortran to C header file */
  2. /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
  3. - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
  4. #ifndef F2C_INCLUDE
  5. #define F2C_INCLUDE
  6. #include <math.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <complex.h>
  11. #ifdef complex
  12. #undef complex
  13. #endif
  14. #ifdef I
  15. #undef I
  16. #endif
  17. #if defined(_WIN64)
  18. typedef long long BLASLONG;
  19. typedef unsigned long long BLASULONG;
  20. #else
  21. typedef long BLASLONG;
  22. typedef unsigned long BLASULONG;
  23. #endif
  24. #ifdef LAPACK_ILP64
  25. typedef BLASLONG blasint;
  26. #if defined(_WIN64)
  27. #define blasabs(x) llabs(x)
  28. #else
  29. #define blasabs(x) labs(x)
  30. #endif
  31. #else
  32. typedef int blasint;
  33. #define blasabs(x) abs(x)
  34. #endif
  35. typedef blasint integer;
  36. typedef unsigned int uinteger;
  37. typedef char *address;
  38. typedef short int shortint;
  39. typedef float real;
  40. typedef double doublereal;
  41. typedef struct { real r, i; } complex;
  42. typedef struct { doublereal r, i; } doublecomplex;
  43. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  44. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  46. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  47. #define pCf(z) (*_pCf(z))
  48. #define pCd(z) (*_pCd(z))
  49. typedef int logical;
  50. typedef short int shortlogical;
  51. typedef char logical1;
  52. typedef char integer1;
  53. #define TRUE_ (1)
  54. #define FALSE_ (0)
  55. /* Extern is for use with -E */
  56. #ifndef Extern
  57. #define Extern extern
  58. #endif
  59. /* I/O stuff */
  60. typedef int flag;
  61. typedef int ftnlen;
  62. typedef int ftnint;
  63. /*external read, write*/
  64. typedef struct
  65. { flag cierr;
  66. ftnint ciunit;
  67. flag ciend;
  68. char *cifmt;
  69. ftnint cirec;
  70. } cilist;
  71. /*internal read, write*/
  72. typedef struct
  73. { flag icierr;
  74. char *iciunit;
  75. flag iciend;
  76. char *icifmt;
  77. ftnint icirlen;
  78. ftnint icirnum;
  79. } icilist;
  80. /*open*/
  81. typedef struct
  82. { flag oerr;
  83. ftnint ounit;
  84. char *ofnm;
  85. ftnlen ofnmlen;
  86. char *osta;
  87. char *oacc;
  88. char *ofm;
  89. ftnint orl;
  90. char *oblnk;
  91. } olist;
  92. /*close*/
  93. typedef struct
  94. { flag cerr;
  95. ftnint cunit;
  96. char *csta;
  97. } cllist;
  98. /*rewind, backspace, endfile*/
  99. typedef struct
  100. { flag aerr;
  101. ftnint aunit;
  102. } alist;
  103. /* inquire */
  104. typedef struct
  105. { flag inerr;
  106. ftnint inunit;
  107. char *infile;
  108. ftnlen infilen;
  109. ftnint *inex; /*parameters in standard's order*/
  110. ftnint *inopen;
  111. ftnint *innum;
  112. ftnint *innamed;
  113. char *inname;
  114. ftnlen innamlen;
  115. char *inacc;
  116. ftnlen inacclen;
  117. char *inseq;
  118. ftnlen inseqlen;
  119. char *indir;
  120. ftnlen indirlen;
  121. char *infmt;
  122. ftnlen infmtlen;
  123. char *inform;
  124. ftnint informlen;
  125. char *inunf;
  126. ftnlen inunflen;
  127. ftnint *inrecl;
  128. ftnint *innrec;
  129. char *inblank;
  130. ftnlen inblanklen;
  131. } inlist;
  132. #define VOID void
  133. union Multitype { /* for multiple entry points */
  134. integer1 g;
  135. shortint h;
  136. integer i;
  137. /* longint j; */
  138. real r;
  139. doublereal d;
  140. complex c;
  141. doublecomplex z;
  142. };
  143. typedef union Multitype Multitype;
  144. struct Vardesc { /* for Namelist */
  145. char *name;
  146. char *addr;
  147. ftnlen *dims;
  148. int type;
  149. };
  150. typedef struct Vardesc Vardesc;
  151. struct Namelist {
  152. char *name;
  153. Vardesc **vars;
  154. int nvars;
  155. };
  156. typedef struct Namelist Namelist;
  157. #define abs(x) ((x) >= 0 ? (x) : -(x))
  158. #define dabs(x) (fabs(x))
  159. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  160. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  161. #define dmin(a,b) (f2cmin(a,b))
  162. #define dmax(a,b) (f2cmax(a,b))
  163. #define bit_test(a,b) ((a) >> (b) & 1)
  164. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  165. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  166. #define abort_() { sig_die("Fortran abort routine called", 1); }
  167. #define c_abs(z) (cabsf(Cf(z)))
  168. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  169. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  170. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  171. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  172. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  173. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  174. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  175. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  176. #define d_abs(x) (fabs(*(x)))
  177. #define d_acos(x) (acos(*(x)))
  178. #define d_asin(x) (asin(*(x)))
  179. #define d_atan(x) (atan(*(x)))
  180. #define d_atn2(x, y) (atan2(*(x),*(y)))
  181. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  182. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  183. #define d_cos(x) (cos(*(x)))
  184. #define d_cosh(x) (cosh(*(x)))
  185. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  186. #define d_exp(x) (exp(*(x)))
  187. #define d_imag(z) (cimag(Cd(z)))
  188. #define r_imag(z) (cimag(Cf(z)))
  189. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  190. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  191. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  192. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  193. #define d_log(x) (log(*(x)))
  194. #define d_mod(x, y) (fmod(*(x), *(y)))
  195. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  196. #define d_nint(x) u_nint(*(x))
  197. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  198. #define d_sign(a,b) u_sign(*(a),*(b))
  199. #define r_sign(a,b) u_sign(*(a),*(b))
  200. #define d_sin(x) (sin(*(x)))
  201. #define d_sinh(x) (sinh(*(x)))
  202. #define d_sqrt(x) (sqrt(*(x)))
  203. #define d_tan(x) (tan(*(x)))
  204. #define d_tanh(x) (tanh(*(x)))
  205. #define i_abs(x) abs(*(x))
  206. #define i_dnnt(x) ((integer)u_nint(*(x)))
  207. #define i_len(s, n) (n)
  208. #define i_nint(x) ((integer)u_nint(*(x)))
  209. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  210. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  211. #define pow_si(B,E) spow_ui(*(B),*(E))
  212. #define pow_ri(B,E) spow_ui(*(B),*(E))
  213. #define pow_di(B,E) dpow_ui(*(B),*(E))
  214. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  215. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  216. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  217. #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++ = ' '; }
  218. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  219. #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]; }
  220. #define sig_die(s, kill) { exit(1); }
  221. #define s_stop(s, n) {exit(0);}
  222. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  223. #define z_abs(z) (cabs(Cd(z)))
  224. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  225. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  226. #define myexit_() break;
  227. #define mycycle() continue;
  228. #define myceiling(w) {ceil(w)}
  229. #define myhuge(w) {HUGE_VAL}
  230. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  231. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  232. /* procedure parameter types for -A and -C++ */
  233. #define F2C_proc_par_types 1
  234. #ifdef __cplusplus
  235. typedef logical (*L_fp)(...);
  236. #else
  237. typedef logical (*L_fp)();
  238. #endif
  239. static float spow_ui(float x, integer n) {
  240. float pow=1.0; unsigned long int u;
  241. if(n != 0) {
  242. if(n < 0) n = -n, x = 1/x;
  243. for(u = n; ; ) {
  244. if(u & 01) pow *= x;
  245. if(u >>= 1) x *= x;
  246. else break;
  247. }
  248. }
  249. return pow;
  250. }
  251. static double dpow_ui(double x, integer n) {
  252. double pow=1.0; unsigned long int u;
  253. if(n != 0) {
  254. if(n < 0) n = -n, x = 1/x;
  255. for(u = n; ; ) {
  256. if(u & 01) pow *= x;
  257. if(u >>= 1) x *= x;
  258. else break;
  259. }
  260. }
  261. return pow;
  262. }
  263. static _Complex float cpow_ui(_Complex float x, integer n) {
  264. _Complex float pow=1.0; unsigned long int u;
  265. if(n != 0) {
  266. if(n < 0) n = -n, x = 1/x;
  267. for(u = n; ; ) {
  268. if(u & 01) pow *= x;
  269. if(u >>= 1) x *= x;
  270. else break;
  271. }
  272. }
  273. return pow;
  274. }
  275. static _Complex double zpow_ui(_Complex double x, integer n) {
  276. _Complex double pow=1.0; unsigned long int u;
  277. if(n != 0) {
  278. if(n < 0) n = -n, x = 1/x;
  279. for(u = n; ; ) {
  280. if(u & 01) pow *= x;
  281. if(u >>= 1) x *= x;
  282. else break;
  283. }
  284. }
  285. return pow;
  286. }
  287. static integer pow_ii(integer x, integer n) {
  288. integer pow; unsigned long int u;
  289. if (n <= 0) {
  290. if (n == 0 || x == 1) pow = 1;
  291. else if (x != -1) pow = x == 0 ? 1/x : 0;
  292. else n = -n;
  293. }
  294. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  295. u = n;
  296. for(pow = 1; ; ) {
  297. if(u & 01) pow *= x;
  298. if(u >>= 1) x *= x;
  299. else break;
  300. }
  301. }
  302. return pow;
  303. }
  304. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  305. {
  306. double m; integer i, mi;
  307. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  308. if (w[i-1]>m) mi=i ,m=w[i-1];
  309. return mi-s+1;
  310. }
  311. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  312. {
  313. float m; integer i, mi;
  314. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  315. if (w[i-1]>m) mi=i ,m=w[i-1];
  316. return mi-s+1;
  317. }
  318. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  319. integer n = *n_, incx = *incx_, incy = *incy_, i;
  320. _Complex float zdotc = 0.0;
  321. if (incx == 1 && incy == 1) {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  324. }
  325. } else {
  326. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  327. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  328. }
  329. }
  330. pCf(z) = zdotc;
  331. }
  332. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  333. integer n = *n_, incx = *incx_, incy = *incy_, i;
  334. _Complex double zdotc = 0.0;
  335. if (incx == 1 && incy == 1) {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  338. }
  339. } else {
  340. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  341. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  342. }
  343. }
  344. pCd(z) = zdotc;
  345. }
  346. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  347. integer n = *n_, incx = *incx_, incy = *incy_, i;
  348. _Complex float zdotc = 0.0;
  349. if (incx == 1 && incy == 1) {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cf(&x[i]) * Cf(&y[i]);
  352. }
  353. } else {
  354. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  355. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  356. }
  357. }
  358. pCf(z) = zdotc;
  359. }
  360. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  361. integer n = *n_, incx = *incx_, incy = *incy_, i;
  362. _Complex double zdotc = 0.0;
  363. if (incx == 1 && incy == 1) {
  364. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  365. zdotc += Cd(&x[i]) * Cd(&y[i]);
  366. }
  367. } else {
  368. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  369. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  370. }
  371. }
  372. pCd(z) = zdotc;
  373. }
  374. #endif
  375. /* -- translated by f2c (version 20000121).
  376. You must link the resulting object file with the libraries:
  377. -lf2c -lm (in that order)
  378. */
  379. /* > \brief \b SLALN2 solves a 1-by-1 or 2-by-2 linear system of equations of the specified form. */
  380. /* =========== DOCUMENTATION =========== */
  381. /* Online html documentation available at */
  382. /* http://www.netlib.org/lapack/explore-html/ */
  383. /* > \htmlonly */
  384. /* > Download SLALN2 + dependencies */
  385. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slaln2.
  386. f"> */
  387. /* > [TGZ]</a> */
  388. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slaln2.
  389. f"> */
  390. /* > [ZIP]</a> */
  391. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slaln2.
  392. f"> */
  393. /* > [TXT]</a> */
  394. /* > \endhtmlonly */
  395. /* Definition: */
  396. /* =========== */
  397. /* SUBROUTINE SLALN2( LTRANS, NA, NW, SMIN, CA, A, LDA, D1, D2, B, */
  398. /* LDB, WR, WI, X, LDX, SCALE, XNORM, INFO ) */
  399. /* LOGICAL LTRANS */
  400. /* INTEGER INFO, LDA, LDB, LDX, NA, NW */
  401. /* REAL CA, D1, D2, SCALE, SMIN, WI, WR, XNORM */
  402. /* REAL A( LDA, * ), B( LDB, * ), X( LDX, * ) */
  403. /* > \par Purpose: */
  404. /* ============= */
  405. /* > */
  406. /* > \verbatim */
  407. /* > */
  408. /* > SLALN2 solves a system of the form (ca A - w D ) X = s B */
  409. /* > or (ca A**T - w D) X = s B with possible scaling ("s") and */
  410. /* > perturbation of A. (A**T means A-transpose.) */
  411. /* > */
  412. /* > A is an NA x NA real matrix, ca is a real scalar, D is an NA x NA */
  413. /* > real diagonal matrix, w is a real or complex value, and X and B are */
  414. /* > NA x 1 matrices -- real if w is real, complex if w is complex. NA */
  415. /* > may be 1 or 2. */
  416. /* > */
  417. /* > If w is complex, X and B are represented as NA x 2 matrices, */
  418. /* > the first column of each being the real part and the second */
  419. /* > being the imaginary part. */
  420. /* > */
  421. /* > "s" is a scaling factor (<= 1), computed by SLALN2, which is */
  422. /* > so chosen that X can be computed without overflow. X is further */
  423. /* > scaled if necessary to assure that norm(ca A - w D)*norm(X) is less */
  424. /* > than overflow. */
  425. /* > */
  426. /* > If both singular values of (ca A - w D) are less than SMIN, */
  427. /* > SMIN*identity will be used instead of (ca A - w D). If only one */
  428. /* > singular value is less than SMIN, one element of (ca A - w D) will be */
  429. /* > perturbed enough to make the smallest singular value roughly SMIN. */
  430. /* > If both singular values are at least SMIN, (ca A - w D) will not be */
  431. /* > perturbed. In any case, the perturbation will be at most some small */
  432. /* > multiple of f2cmax( SMIN, ulp*norm(ca A - w D) ). The singular values */
  433. /* > are computed by infinity-norm approximations, and thus will only be */
  434. /* > correct to a factor of 2 or so. */
  435. /* > */
  436. /* > Note: all input quantities are assumed to be smaller than overflow */
  437. /* > by a reasonable factor. (See BIGNUM.) */
  438. /* > \endverbatim */
  439. /* Arguments: */
  440. /* ========== */
  441. /* > \param[in] LTRANS */
  442. /* > \verbatim */
  443. /* > LTRANS is LOGICAL */
  444. /* > =.TRUE.: A-transpose will be used. */
  445. /* > =.FALSE.: A will be used (not transposed.) */
  446. /* > \endverbatim */
  447. /* > */
  448. /* > \param[in] NA */
  449. /* > \verbatim */
  450. /* > NA is INTEGER */
  451. /* > The size of the matrix A. It may (only) be 1 or 2. */
  452. /* > \endverbatim */
  453. /* > */
  454. /* > \param[in] NW */
  455. /* > \verbatim */
  456. /* > NW is INTEGER */
  457. /* > 1 if "w" is real, 2 if "w" is complex. It may only be 1 */
  458. /* > or 2. */
  459. /* > \endverbatim */
  460. /* > */
  461. /* > \param[in] SMIN */
  462. /* > \verbatim */
  463. /* > SMIN is REAL */
  464. /* > The desired lower bound on the singular values of A. This */
  465. /* > should be a safe distance away from underflow or overflow, */
  466. /* > say, between (underflow/machine precision) and (machine */
  467. /* > precision * overflow ). (See BIGNUM and ULP.) */
  468. /* > \endverbatim */
  469. /* > */
  470. /* > \param[in] CA */
  471. /* > \verbatim */
  472. /* > CA is REAL */
  473. /* > The coefficient c, which A is multiplied by. */
  474. /* > \endverbatim */
  475. /* > */
  476. /* > \param[in] A */
  477. /* > \verbatim */
  478. /* > A is REAL array, dimension (LDA,NA) */
  479. /* > The NA x NA matrix A. */
  480. /* > \endverbatim */
  481. /* > */
  482. /* > \param[in] LDA */
  483. /* > \verbatim */
  484. /* > LDA is INTEGER */
  485. /* > The leading dimension of A. It must be at least NA. */
  486. /* > \endverbatim */
  487. /* > */
  488. /* > \param[in] D1 */
  489. /* > \verbatim */
  490. /* > D1 is REAL */
  491. /* > The 1,1 element in the diagonal matrix D. */
  492. /* > \endverbatim */
  493. /* > */
  494. /* > \param[in] D2 */
  495. /* > \verbatim */
  496. /* > D2 is REAL */
  497. /* > The 2,2 element in the diagonal matrix D. Not used if NA=1. */
  498. /* > \endverbatim */
  499. /* > */
  500. /* > \param[in] B */
  501. /* > \verbatim */
  502. /* > B is REAL array, dimension (LDB,NW) */
  503. /* > The NA x NW matrix B (right-hand side). If NW=2 ("w" is */
  504. /* > complex), column 1 contains the real part of B and column 2 */
  505. /* > contains the imaginary part. */
  506. /* > \endverbatim */
  507. /* > */
  508. /* > \param[in] LDB */
  509. /* > \verbatim */
  510. /* > LDB is INTEGER */
  511. /* > The leading dimension of B. It must be at least NA. */
  512. /* > \endverbatim */
  513. /* > */
  514. /* > \param[in] WR */
  515. /* > \verbatim */
  516. /* > WR is REAL */
  517. /* > The real part of the scalar "w". */
  518. /* > \endverbatim */
  519. /* > */
  520. /* > \param[in] WI */
  521. /* > \verbatim */
  522. /* > WI is REAL */
  523. /* > The imaginary part of the scalar "w". Not used if NW=1. */
  524. /* > \endverbatim */
  525. /* > */
  526. /* > \param[out] X */
  527. /* > \verbatim */
  528. /* > X is REAL array, dimension (LDX,NW) */
  529. /* > The NA x NW matrix X (unknowns), as computed by SLALN2. */
  530. /* > If NW=2 ("w" is complex), on exit, column 1 will contain */
  531. /* > the real part of X and column 2 will contain the imaginary */
  532. /* > part. */
  533. /* > \endverbatim */
  534. /* > */
  535. /* > \param[in] LDX */
  536. /* > \verbatim */
  537. /* > LDX is INTEGER */
  538. /* > The leading dimension of X. It must be at least NA. */
  539. /* > \endverbatim */
  540. /* > */
  541. /* > \param[out] SCALE */
  542. /* > \verbatim */
  543. /* > SCALE is REAL */
  544. /* > The scale factor that B must be multiplied by to insure */
  545. /* > that overflow does not occur when computing X. Thus, */
  546. /* > (ca A - w D) X will be SCALE*B, not B (ignoring */
  547. /* > perturbations of A.) It will be at most 1. */
  548. /* > \endverbatim */
  549. /* > */
  550. /* > \param[out] XNORM */
  551. /* > \verbatim */
  552. /* > XNORM is REAL */
  553. /* > The infinity-norm of X, when X is regarded as an NA x NW */
  554. /* > real matrix. */
  555. /* > \endverbatim */
  556. /* > */
  557. /* > \param[out] INFO */
  558. /* > \verbatim */
  559. /* > INFO is INTEGER */
  560. /* > An error flag. It will be set to zero if no error occurs, */
  561. /* > a negative number if an argument is in error, or a positive */
  562. /* > number if ca A - w D had to be perturbed. */
  563. /* > The possible values are: */
  564. /* > = 0: No error occurred, and (ca A - w D) did not have to be */
  565. /* > perturbed. */
  566. /* > = 1: (ca A - w D) had to be perturbed to make its smallest */
  567. /* > (or only) singular value greater than SMIN. */
  568. /* > NOTE: In the interests of speed, this routine does not */
  569. /* > check the inputs for errors. */
  570. /* > \endverbatim */
  571. /* Authors: */
  572. /* ======== */
  573. /* > \author Univ. of Tennessee */
  574. /* > \author Univ. of California Berkeley */
  575. /* > \author Univ. of Colorado Denver */
  576. /* > \author NAG Ltd. */
  577. /* > \date December 2016 */
  578. /* > \ingroup realOTHERauxiliary */
  579. /* ===================================================================== */
  580. /* Subroutine */ int slaln2_(logical *ltrans, integer *na, integer *nw, real *
  581. smin, real *ca, real *a, integer *lda, real *d1, real *d2, real *b,
  582. integer *ldb, real *wr, real *wi, real *x, integer *ldx, real *scale,
  583. real *xnorm, integer *info)
  584. {
  585. /* Initialized data */
  586. static logical cswap[4] = { FALSE_,FALSE_,TRUE_,TRUE_ };
  587. static logical rswap[4] = { FALSE_,TRUE_,FALSE_,TRUE_ };
  588. static integer ipivot[16] /* was [4][4] */ = { 1,2,3,4,2,1,4,3,3,4,1,2,
  589. 4,3,2,1 };
  590. /* System generated locals */
  591. integer a_dim1, a_offset, b_dim1, b_offset, x_dim1, x_offset;
  592. real r__1, r__2, r__3, r__4, r__5, r__6;
  593. static real equiv_0[4], equiv_1[4];
  594. /* Local variables */
  595. real bbnd, cmax, ui11r, ui12s, temp, ur11r, ur12s;
  596. integer j;
  597. real u22abs;
  598. integer icmax;
  599. real bnorm, cnorm, smini;
  600. #define ci (equiv_0)
  601. #define cr (equiv_1)
  602. extern real slamch_(char *);
  603. real bignum;
  604. extern /* Subroutine */ int sladiv_(real *, real *, real *, real *, real *
  605. , real *);
  606. real bi1, bi2, br1, br2, smlnum, xi1, xi2, xr1, xr2, ci21, ci22, cr21,
  607. cr22, li21, csi, ui11, lr21, ui12, ui22;
  608. #define civ (equiv_0)
  609. real csr, ur11, ur12, ur22;
  610. #define crv (equiv_1)
  611. /* -- LAPACK auxiliary routine (version 3.7.0) -- */
  612. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  613. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  614. /* December 2016 */
  615. /* ===================================================================== */
  616. /* Parameter adjustments */
  617. a_dim1 = *lda;
  618. a_offset = 1 + a_dim1 * 1;
  619. a -= a_offset;
  620. b_dim1 = *ldb;
  621. b_offset = 1 + b_dim1 * 1;
  622. b -= b_offset;
  623. x_dim1 = *ldx;
  624. x_offset = 1 + x_dim1 * 1;
  625. x -= x_offset;
  626. /* Function Body */
  627. /* Compute BIGNUM */
  628. smlnum = 2.f * slamch_("Safe minimum");
  629. bignum = 1.f / smlnum;
  630. smini = f2cmax(*smin,smlnum);
  631. /* Don't check for input errors */
  632. *info = 0;
  633. /* Standard Initializations */
  634. *scale = 1.f;
  635. if (*na == 1) {
  636. /* 1 x 1 (i.e., scalar) system C X = B */
  637. if (*nw == 1) {
  638. /* Real 1x1 system. */
  639. /* C = ca A - w D */
  640. csr = *ca * a[a_dim1 + 1] - *wr * *d1;
  641. cnorm = abs(csr);
  642. /* If | C | < SMINI, use C = SMINI */
  643. if (cnorm < smini) {
  644. csr = smini;
  645. cnorm = smini;
  646. *info = 1;
  647. }
  648. /* Check scaling for X = B / C */
  649. bnorm = (r__1 = b[b_dim1 + 1], abs(r__1));
  650. if (cnorm < 1.f && bnorm > 1.f) {
  651. if (bnorm > bignum * cnorm) {
  652. *scale = 1.f / bnorm;
  653. }
  654. }
  655. /* Compute X */
  656. x[x_dim1 + 1] = b[b_dim1 + 1] * *scale / csr;
  657. *xnorm = (r__1 = x[x_dim1 + 1], abs(r__1));
  658. } else {
  659. /* Complex 1x1 system (w is complex) */
  660. /* C = ca A - w D */
  661. csr = *ca * a[a_dim1 + 1] - *wr * *d1;
  662. csi = -(*wi) * *d1;
  663. cnorm = abs(csr) + abs(csi);
  664. /* If | C | < SMINI, use C = SMINI */
  665. if (cnorm < smini) {
  666. csr = smini;
  667. csi = 0.f;
  668. cnorm = smini;
  669. *info = 1;
  670. }
  671. /* Check scaling for X = B / C */
  672. bnorm = (r__1 = b[b_dim1 + 1], abs(r__1)) + (r__2 = b[(b_dim1 <<
  673. 1) + 1], abs(r__2));
  674. if (cnorm < 1.f && bnorm > 1.f) {
  675. if (bnorm > bignum * cnorm) {
  676. *scale = 1.f / bnorm;
  677. }
  678. }
  679. /* Compute X */
  680. r__1 = *scale * b[b_dim1 + 1];
  681. r__2 = *scale * b[(b_dim1 << 1) + 1];
  682. sladiv_(&r__1, &r__2, &csr, &csi, &x[x_dim1 + 1], &x[(x_dim1 << 1)
  683. + 1]);
  684. *xnorm = (r__1 = x[x_dim1 + 1], abs(r__1)) + (r__2 = x[(x_dim1 <<
  685. 1) + 1], abs(r__2));
  686. }
  687. } else {
  688. /* 2x2 System */
  689. /* Compute the real part of C = ca A - w D (or ca A**T - w D ) */
  690. cr[0] = *ca * a[a_dim1 + 1] - *wr * *d1;
  691. cr[3] = *ca * a[(a_dim1 << 1) + 2] - *wr * *d2;
  692. if (*ltrans) {
  693. cr[2] = *ca * a[a_dim1 + 2];
  694. cr[1] = *ca * a[(a_dim1 << 1) + 1];
  695. } else {
  696. cr[1] = *ca * a[a_dim1 + 2];
  697. cr[2] = *ca * a[(a_dim1 << 1) + 1];
  698. }
  699. if (*nw == 1) {
  700. /* Real 2x2 system (w is real) */
  701. /* Find the largest element in C */
  702. cmax = 0.f;
  703. icmax = 0;
  704. for (j = 1; j <= 4; ++j) {
  705. if ((r__1 = crv[j - 1], abs(r__1)) > cmax) {
  706. cmax = (r__1 = crv[j - 1], abs(r__1));
  707. icmax = j;
  708. }
  709. /* L10: */
  710. }
  711. /* If norm(C) < SMINI, use SMINI*identity. */
  712. if (cmax < smini) {
  713. /* Computing MAX */
  714. r__3 = (r__1 = b[b_dim1 + 1], abs(r__1)), r__4 = (r__2 = b[
  715. b_dim1 + 2], abs(r__2));
  716. bnorm = f2cmax(r__3,r__4);
  717. if (smini < 1.f && bnorm > 1.f) {
  718. if (bnorm > bignum * smini) {
  719. *scale = 1.f / bnorm;
  720. }
  721. }
  722. temp = *scale / smini;
  723. x[x_dim1 + 1] = temp * b[b_dim1 + 1];
  724. x[x_dim1 + 2] = temp * b[b_dim1 + 2];
  725. *xnorm = temp * bnorm;
  726. *info = 1;
  727. return 0;
  728. }
  729. /* Gaussian elimination with complete pivoting. */
  730. ur11 = crv[icmax - 1];
  731. cr21 = crv[ipivot[(icmax << 2) - 3] - 1];
  732. ur12 = crv[ipivot[(icmax << 2) - 2] - 1];
  733. cr22 = crv[ipivot[(icmax << 2) - 1] - 1];
  734. ur11r = 1.f / ur11;
  735. lr21 = ur11r * cr21;
  736. ur22 = cr22 - ur12 * lr21;
  737. /* If smaller pivot < SMINI, use SMINI */
  738. if (abs(ur22) < smini) {
  739. ur22 = smini;
  740. *info = 1;
  741. }
  742. if (rswap[icmax - 1]) {
  743. br1 = b[b_dim1 + 2];
  744. br2 = b[b_dim1 + 1];
  745. } else {
  746. br1 = b[b_dim1 + 1];
  747. br2 = b[b_dim1 + 2];
  748. }
  749. br2 -= lr21 * br1;
  750. /* Computing MAX */
  751. r__2 = (r__1 = br1 * (ur22 * ur11r), abs(r__1)), r__3 = abs(br2);
  752. bbnd = f2cmax(r__2,r__3);
  753. if (bbnd > 1.f && abs(ur22) < 1.f) {
  754. if (bbnd >= bignum * abs(ur22)) {
  755. *scale = 1.f / bbnd;
  756. }
  757. }
  758. xr2 = br2 * *scale / ur22;
  759. xr1 = *scale * br1 * ur11r - xr2 * (ur11r * ur12);
  760. if (cswap[icmax - 1]) {
  761. x[x_dim1 + 1] = xr2;
  762. x[x_dim1 + 2] = xr1;
  763. } else {
  764. x[x_dim1 + 1] = xr1;
  765. x[x_dim1 + 2] = xr2;
  766. }
  767. /* Computing MAX */
  768. r__1 = abs(xr1), r__2 = abs(xr2);
  769. *xnorm = f2cmax(r__1,r__2);
  770. /* Further scaling if norm(A) norm(X) > overflow */
  771. if (*xnorm > 1.f && cmax > 1.f) {
  772. if (*xnorm > bignum / cmax) {
  773. temp = cmax / bignum;
  774. x[x_dim1 + 1] = temp * x[x_dim1 + 1];
  775. x[x_dim1 + 2] = temp * x[x_dim1 + 2];
  776. *xnorm = temp * *xnorm;
  777. *scale = temp * *scale;
  778. }
  779. }
  780. } else {
  781. /* Complex 2x2 system (w is complex) */
  782. /* Find the largest element in C */
  783. ci[0] = -(*wi) * *d1;
  784. ci[1] = 0.f;
  785. ci[2] = 0.f;
  786. ci[3] = -(*wi) * *d2;
  787. cmax = 0.f;
  788. icmax = 0;
  789. for (j = 1; j <= 4; ++j) {
  790. if ((r__1 = crv[j - 1], abs(r__1)) + (r__2 = civ[j - 1], abs(
  791. r__2)) > cmax) {
  792. cmax = (r__1 = crv[j - 1], abs(r__1)) + (r__2 = civ[j - 1]
  793. , abs(r__2));
  794. icmax = j;
  795. }
  796. /* L20: */
  797. }
  798. /* If norm(C) < SMINI, use SMINI*identity. */
  799. if (cmax < smini) {
  800. /* Computing MAX */
  801. r__5 = (r__1 = b[b_dim1 + 1], abs(r__1)) + (r__2 = b[(b_dim1
  802. << 1) + 1], abs(r__2)), r__6 = (r__3 = b[b_dim1 + 2],
  803. abs(r__3)) + (r__4 = b[(b_dim1 << 1) + 2], abs(r__4));
  804. bnorm = f2cmax(r__5,r__6);
  805. if (smini < 1.f && bnorm > 1.f) {
  806. if (bnorm > bignum * smini) {
  807. *scale = 1.f / bnorm;
  808. }
  809. }
  810. temp = *scale / smini;
  811. x[x_dim1 + 1] = temp * b[b_dim1 + 1];
  812. x[x_dim1 + 2] = temp * b[b_dim1 + 2];
  813. x[(x_dim1 << 1) + 1] = temp * b[(b_dim1 << 1) + 1];
  814. x[(x_dim1 << 1) + 2] = temp * b[(b_dim1 << 1) + 2];
  815. *xnorm = temp * bnorm;
  816. *info = 1;
  817. return 0;
  818. }
  819. /* Gaussian elimination with complete pivoting. */
  820. ur11 = crv[icmax - 1];
  821. ui11 = civ[icmax - 1];
  822. cr21 = crv[ipivot[(icmax << 2) - 3] - 1];
  823. ci21 = civ[ipivot[(icmax << 2) - 3] - 1];
  824. ur12 = crv[ipivot[(icmax << 2) - 2] - 1];
  825. ui12 = civ[ipivot[(icmax << 2) - 2] - 1];
  826. cr22 = crv[ipivot[(icmax << 2) - 1] - 1];
  827. ci22 = civ[ipivot[(icmax << 2) - 1] - 1];
  828. if (icmax == 1 || icmax == 4) {
  829. /* Code when off-diagonals of pivoted C are real */
  830. if (abs(ur11) > abs(ui11)) {
  831. temp = ui11 / ur11;
  832. /* Computing 2nd power */
  833. r__1 = temp;
  834. ur11r = 1.f / (ur11 * (r__1 * r__1 + 1.f));
  835. ui11r = -temp * ur11r;
  836. } else {
  837. temp = ur11 / ui11;
  838. /* Computing 2nd power */
  839. r__1 = temp;
  840. ui11r = -1.f / (ui11 * (r__1 * r__1 + 1.f));
  841. ur11r = -temp * ui11r;
  842. }
  843. lr21 = cr21 * ur11r;
  844. li21 = cr21 * ui11r;
  845. ur12s = ur12 * ur11r;
  846. ui12s = ur12 * ui11r;
  847. ur22 = cr22 - ur12 * lr21;
  848. ui22 = ci22 - ur12 * li21;
  849. } else {
  850. /* Code when diagonals of pivoted C are real */
  851. ur11r = 1.f / ur11;
  852. ui11r = 0.f;
  853. lr21 = cr21 * ur11r;
  854. li21 = ci21 * ur11r;
  855. ur12s = ur12 * ur11r;
  856. ui12s = ui12 * ur11r;
  857. ur22 = cr22 - ur12 * lr21 + ui12 * li21;
  858. ui22 = -ur12 * li21 - ui12 * lr21;
  859. }
  860. u22abs = abs(ur22) + abs(ui22);
  861. /* If smaller pivot < SMINI, use SMINI */
  862. if (u22abs < smini) {
  863. ur22 = smini;
  864. ui22 = 0.f;
  865. *info = 1;
  866. }
  867. if (rswap[icmax - 1]) {
  868. br2 = b[b_dim1 + 1];
  869. br1 = b[b_dim1 + 2];
  870. bi2 = b[(b_dim1 << 1) + 1];
  871. bi1 = b[(b_dim1 << 1) + 2];
  872. } else {
  873. br1 = b[b_dim1 + 1];
  874. br2 = b[b_dim1 + 2];
  875. bi1 = b[(b_dim1 << 1) + 1];
  876. bi2 = b[(b_dim1 << 1) + 2];
  877. }
  878. br2 = br2 - lr21 * br1 + li21 * bi1;
  879. bi2 = bi2 - li21 * br1 - lr21 * bi1;
  880. /* Computing MAX */
  881. r__1 = (abs(br1) + abs(bi1)) * (u22abs * (abs(ur11r) + abs(ui11r))
  882. ), r__2 = abs(br2) + abs(bi2);
  883. bbnd = f2cmax(r__1,r__2);
  884. if (bbnd > 1.f && u22abs < 1.f) {
  885. if (bbnd >= bignum * u22abs) {
  886. *scale = 1.f / bbnd;
  887. br1 = *scale * br1;
  888. bi1 = *scale * bi1;
  889. br2 = *scale * br2;
  890. bi2 = *scale * bi2;
  891. }
  892. }
  893. sladiv_(&br2, &bi2, &ur22, &ui22, &xr2, &xi2);
  894. xr1 = ur11r * br1 - ui11r * bi1 - ur12s * xr2 + ui12s * xi2;
  895. xi1 = ui11r * br1 + ur11r * bi1 - ui12s * xr2 - ur12s * xi2;
  896. if (cswap[icmax - 1]) {
  897. x[x_dim1 + 1] = xr2;
  898. x[x_dim1 + 2] = xr1;
  899. x[(x_dim1 << 1) + 1] = xi2;
  900. x[(x_dim1 << 1) + 2] = xi1;
  901. } else {
  902. x[x_dim1 + 1] = xr1;
  903. x[x_dim1 + 2] = xr2;
  904. x[(x_dim1 << 1) + 1] = xi1;
  905. x[(x_dim1 << 1) + 2] = xi2;
  906. }
  907. /* Computing MAX */
  908. r__1 = abs(xr1) + abs(xi1), r__2 = abs(xr2) + abs(xi2);
  909. *xnorm = f2cmax(r__1,r__2);
  910. /* Further scaling if norm(A) norm(X) > overflow */
  911. if (*xnorm > 1.f && cmax > 1.f) {
  912. if (*xnorm > bignum / cmax) {
  913. temp = cmax / bignum;
  914. x[x_dim1 + 1] = temp * x[x_dim1 + 1];
  915. x[x_dim1 + 2] = temp * x[x_dim1 + 2];
  916. x[(x_dim1 << 1) + 1] = temp * x[(x_dim1 << 1) + 1];
  917. x[(x_dim1 << 1) + 2] = temp * x[(x_dim1 << 1) + 2];
  918. *xnorm = temp * *xnorm;
  919. *scale = temp * *scale;
  920. }
  921. }
  922. }
  923. }
  924. return 0;
  925. /* End of SLALN2 */
  926. } /* slaln2_ */
  927. #undef crv
  928. #undef civ
  929. #undef cr
  930. #undef ci