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.

dlatrs.c 34 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282
  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. /* Table of constant values */
  380. static integer c__1 = 1;
  381. static doublereal c_b36 = .5;
  382. /* > \brief \b DLATRS solves a triangular system of equations with the scale factor set to prevent overflow.
  383. */
  384. /* =========== DOCUMENTATION =========== */
  385. /* Online html documentation available at */
  386. /* http://www.netlib.org/lapack/explore-html/ */
  387. /* > \htmlonly */
  388. /* > Download DLATRS + dependencies */
  389. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlatrs.
  390. f"> */
  391. /* > [TGZ]</a> */
  392. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlatrs.
  393. f"> */
  394. /* > [ZIP]</a> */
  395. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlatrs.
  396. f"> */
  397. /* > [TXT]</a> */
  398. /* > \endhtmlonly */
  399. /* Definition: */
  400. /* =========== */
  401. /* SUBROUTINE DLATRS( UPLO, TRANS, DIAG, NORMIN, N, A, LDA, X, SCALE, */
  402. /* CNORM, INFO ) */
  403. /* CHARACTER DIAG, NORMIN, TRANS, UPLO */
  404. /* INTEGER INFO, LDA, N */
  405. /* DOUBLE PRECISION SCALE */
  406. /* DOUBLE PRECISION A( LDA, * ), CNORM( * ), X( * ) */
  407. /* > \par Purpose: */
  408. /* ============= */
  409. /* > */
  410. /* > \verbatim */
  411. /* > */
  412. /* > DLATRS solves one of the triangular systems */
  413. /* > */
  414. /* > A *x = s*b or A**T *x = s*b */
  415. /* > */
  416. /* > with scaling to prevent overflow. Here A is an upper or lower */
  417. /* > triangular matrix, A**T denotes the transpose of A, x and b are */
  418. /* > n-element vectors, and s is a scaling factor, usually less than */
  419. /* > or equal to 1, chosen so that the components of x will be less than */
  420. /* > the overflow threshold. If the unscaled problem will not cause */
  421. /* > overflow, the Level 2 BLAS routine DTRSV is called. If the matrix A */
  422. /* > is singular (A(j,j) = 0 for some j), then s is set to 0 and a */
  423. /* > non-trivial solution to A*x = 0 is returned. */
  424. /* > \endverbatim */
  425. /* Arguments: */
  426. /* ========== */
  427. /* > \param[in] UPLO */
  428. /* > \verbatim */
  429. /* > UPLO is CHARACTER*1 */
  430. /* > Specifies whether the matrix A is upper or lower triangular. */
  431. /* > = 'U': Upper triangular */
  432. /* > = 'L': Lower triangular */
  433. /* > \endverbatim */
  434. /* > */
  435. /* > \param[in] TRANS */
  436. /* > \verbatim */
  437. /* > TRANS is CHARACTER*1 */
  438. /* > Specifies the operation applied to A. */
  439. /* > = 'N': Solve A * x = s*b (No transpose) */
  440. /* > = 'T': Solve A**T* x = s*b (Transpose) */
  441. /* > = 'C': Solve A**T* x = s*b (Conjugate transpose = Transpose) */
  442. /* > \endverbatim */
  443. /* > */
  444. /* > \param[in] DIAG */
  445. /* > \verbatim */
  446. /* > DIAG is CHARACTER*1 */
  447. /* > Specifies whether or not the matrix A is unit triangular. */
  448. /* > = 'N': Non-unit triangular */
  449. /* > = 'U': Unit triangular */
  450. /* > \endverbatim */
  451. /* > */
  452. /* > \param[in] NORMIN */
  453. /* > \verbatim */
  454. /* > NORMIN is CHARACTER*1 */
  455. /* > Specifies whether CNORM has been set or not. */
  456. /* > = 'Y': CNORM contains the column norms on entry */
  457. /* > = 'N': CNORM is not set on entry. On exit, the norms will */
  458. /* > be computed and stored in CNORM. */
  459. /* > \endverbatim */
  460. /* > */
  461. /* > \param[in] N */
  462. /* > \verbatim */
  463. /* > N is INTEGER */
  464. /* > The order of the matrix A. N >= 0. */
  465. /* > \endverbatim */
  466. /* > */
  467. /* > \param[in] A */
  468. /* > \verbatim */
  469. /* > A is DOUBLE PRECISION array, dimension (LDA,N) */
  470. /* > The triangular matrix A. If UPLO = 'U', the leading n by n */
  471. /* > upper triangular part of the array A contains the upper */
  472. /* > triangular matrix, and the strictly lower triangular part of */
  473. /* > A is not referenced. If UPLO = 'L', the leading n by n lower */
  474. /* > triangular part of the array A contains the lower triangular */
  475. /* > matrix, and the strictly upper triangular part of A is not */
  476. /* > referenced. If DIAG = 'U', the diagonal elements of A are */
  477. /* > also not referenced and are assumed to be 1. */
  478. /* > \endverbatim */
  479. /* > */
  480. /* > \param[in] LDA */
  481. /* > \verbatim */
  482. /* > LDA is INTEGER */
  483. /* > The leading dimension of the array A. LDA >= f2cmax (1,N). */
  484. /* > \endverbatim */
  485. /* > */
  486. /* > \param[in,out] X */
  487. /* > \verbatim */
  488. /* > X is DOUBLE PRECISION array, dimension (N) */
  489. /* > On entry, the right hand side b of the triangular system. */
  490. /* > On exit, X is overwritten by the solution vector x. */
  491. /* > \endverbatim */
  492. /* > */
  493. /* > \param[out] SCALE */
  494. /* > \verbatim */
  495. /* > SCALE is DOUBLE PRECISION */
  496. /* > The scaling factor s for the triangular system */
  497. /* > A * x = s*b or A**T* x = s*b. */
  498. /* > If SCALE = 0, the matrix A is singular or badly scaled, and */
  499. /* > the vector x is an exact or approximate solution to A*x = 0. */
  500. /* > \endverbatim */
  501. /* > */
  502. /* > \param[in,out] CNORM */
  503. /* > \verbatim */
  504. /* > CNORM is DOUBLE PRECISION array, dimension (N) */
  505. /* > */
  506. /* > If NORMIN = 'Y', CNORM is an input argument and CNORM(j) */
  507. /* > contains the norm of the off-diagonal part of the j-th column */
  508. /* > of A. If TRANS = 'N', CNORM(j) must be greater than or equal */
  509. /* > to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) */
  510. /* > must be greater than or equal to the 1-norm. */
  511. /* > */
  512. /* > If NORMIN = 'N', CNORM is an output argument and CNORM(j) */
  513. /* > returns the 1-norm of the offdiagonal part of the j-th column */
  514. /* > of A. */
  515. /* > \endverbatim */
  516. /* > */
  517. /* > \param[out] INFO */
  518. /* > \verbatim */
  519. /* > INFO is INTEGER */
  520. /* > = 0: successful exit */
  521. /* > < 0: if INFO = -k, the k-th argument had an illegal value */
  522. /* > \endverbatim */
  523. /* Authors: */
  524. /* ======== */
  525. /* > \author Univ. of Tennessee */
  526. /* > \author Univ. of California Berkeley */
  527. /* > \author Univ. of Colorado Denver */
  528. /* > \author NAG Ltd. */
  529. /* > \date December 2016 */
  530. /* > \ingroup doubleOTHERauxiliary */
  531. /* > \par Further Details: */
  532. /* ===================== */
  533. /* > */
  534. /* > \verbatim */
  535. /* > */
  536. /* > A rough bound on x is computed; if that is less than overflow, DTRSV */
  537. /* > is called, otherwise, specific code is used which checks for possible */
  538. /* > overflow or divide-by-zero at every operation. */
  539. /* > */
  540. /* > A columnwise scheme is used for solving A*x = b. The basic algorithm */
  541. /* > if A is lower triangular is */
  542. /* > */
  543. /* > x[1:n] := b[1:n] */
  544. /* > for j = 1, ..., n */
  545. /* > x(j) := x(j) / A(j,j) */
  546. /* > x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] */
  547. /* > end */
  548. /* > */
  549. /* > Define bounds on the components of x after j iterations of the loop: */
  550. /* > M(j) = bound on x[1:j] */
  551. /* > G(j) = bound on x[j+1:n] */
  552. /* > Initially, let M(0) = 0 and G(0) = f2cmax{x(i), i=1,...,n}. */
  553. /* > */
  554. /* > Then for iteration j+1 we have */
  555. /* > M(j+1) <= G(j) / | A(j+1,j+1) | */
  556. /* > G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | */
  557. /* > <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | ) */
  558. /* > */
  559. /* > where CNORM(j+1) is greater than or equal to the infinity-norm of */
  560. /* > column j+1 of A, not counting the diagonal. Hence */
  561. /* > */
  562. /* > G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | ) */
  563. /* > 1<=i<=j */
  564. /* > and */
  565. /* > */
  566. /* > |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| ) */
  567. /* > 1<=i< j */
  568. /* > */
  569. /* > Since |x(j)| <= M(j), we use the Level 2 BLAS routine DTRSV if the */
  570. /* > reciprocal of the largest M(j), j=1,..,n, is larger than */
  571. /* > f2cmax(underflow, 1/overflow). */
  572. /* > */
  573. /* > The bound on x(j) is also used to determine when a step in the */
  574. /* > columnwise method can be performed without fear of overflow. If */
  575. /* > the computed bound is greater than a large constant, x is scaled to */
  576. /* > prevent overflow, but if the bound overflows, x is set to 0, x(j) to */
  577. /* > 1, and scale to 0, and a non-trivial solution to A*x = 0 is found. */
  578. /* > */
  579. /* > Similarly, a row-wise scheme is used to solve A**T*x = b. The basic */
  580. /* > algorithm for A upper triangular is */
  581. /* > */
  582. /* > for j = 1, ..., n */
  583. /* > x(j) := ( b(j) - A[1:j-1,j]**T * x[1:j-1] ) / A(j,j) */
  584. /* > end */
  585. /* > */
  586. /* > We simultaneously compute two bounds */
  587. /* > G(j) = bound on ( b(i) - A[1:i-1,i]**T * x[1:i-1] ), 1<=i<=j */
  588. /* > M(j) = bound on x(i), 1<=i<=j */
  589. /* > */
  590. /* > The initial values are G(0) = 0, M(0) = f2cmax{b(i), i=1,..,n}, and we */
  591. /* > add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. */
  592. /* > Then the bound on x(j) is */
  593. /* > */
  594. /* > M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) | */
  595. /* > */
  596. /* > <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| ) */
  597. /* > 1<=i<=j */
  598. /* > */
  599. /* > and we can safely call DTRSV if 1/M(n) and 1/G(n) are both greater */
  600. /* > than f2cmax(underflow, 1/overflow). */
  601. /* > \endverbatim */
  602. /* > */
  603. /* ===================================================================== */
  604. /* Subroutine */ int dlatrs_(char *uplo, char *trans, char *diag, char *
  605. normin, integer *n, doublereal *a, integer *lda, doublereal *x,
  606. doublereal *scale, doublereal *cnorm, integer *info)
  607. {
  608. /* System generated locals */
  609. integer a_dim1, a_offset, i__1, i__2, i__3;
  610. doublereal d__1, d__2, d__3;
  611. /* Local variables */
  612. integer jinc;
  613. extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
  614. integer *);
  615. doublereal xbnd;
  616. integer imax;
  617. doublereal tmax, tjjs, xmax, grow, sumj;
  618. integer i__, j;
  619. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  620. integer *);
  621. extern logical lsame_(char *, char *);
  622. doublereal tscal, uscal;
  623. extern doublereal dasum_(integer *, doublereal *, integer *);
  624. integer jlast;
  625. extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *,
  626. integer *, doublereal *, integer *);
  627. logical upper;
  628. extern /* Subroutine */ int dtrsv_(char *, char *, char *, integer *,
  629. doublereal *, integer *, doublereal *, integer *);
  630. extern doublereal dlamch_(char *);
  631. doublereal xj;
  632. extern integer idamax_(integer *, doublereal *, integer *);
  633. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  634. doublereal bignum;
  635. logical notran;
  636. integer jfirst;
  637. doublereal smlnum;
  638. logical nounit;
  639. doublereal rec, tjj;
  640. /* -- LAPACK auxiliary routine (version 3.7.0) -- */
  641. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  642. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  643. /* December 2016 */
  644. /* ===================================================================== */
  645. /* Parameter adjustments */
  646. a_dim1 = *lda;
  647. a_offset = 1 + a_dim1 * 1;
  648. a -= a_offset;
  649. --x;
  650. --cnorm;
  651. /* Function Body */
  652. *info = 0;
  653. upper = lsame_(uplo, "U");
  654. notran = lsame_(trans, "N");
  655. nounit = lsame_(diag, "N");
  656. /* Test the input parameters. */
  657. if (! upper && ! lsame_(uplo, "L")) {
  658. *info = -1;
  659. } else if (! notran && ! lsame_(trans, "T") && !
  660. lsame_(trans, "C")) {
  661. *info = -2;
  662. } else if (! nounit && ! lsame_(diag, "U")) {
  663. *info = -3;
  664. } else if (! lsame_(normin, "Y") && ! lsame_(normin,
  665. "N")) {
  666. *info = -4;
  667. } else if (*n < 0) {
  668. *info = -5;
  669. } else if (*lda < f2cmax(1,*n)) {
  670. *info = -7;
  671. }
  672. if (*info != 0) {
  673. i__1 = -(*info);
  674. xerbla_("DLATRS", &i__1, (ftnlen)6);
  675. return 0;
  676. }
  677. /* Quick return if possible */
  678. if (*n == 0) {
  679. return 0;
  680. }
  681. /* Determine machine dependent parameters to control overflow. */
  682. smlnum = dlamch_("Safe minimum") / dlamch_("Precision");
  683. bignum = 1. / smlnum;
  684. *scale = 1.;
  685. if (lsame_(normin, "N")) {
  686. /* Compute the 1-norm of each column, not including the diagonal. */
  687. if (upper) {
  688. /* A is upper triangular. */
  689. i__1 = *n;
  690. for (j = 1; j <= i__1; ++j) {
  691. i__2 = j - 1;
  692. cnorm[j] = dasum_(&i__2, &a[j * a_dim1 + 1], &c__1);
  693. /* L10: */
  694. }
  695. } else {
  696. /* A is lower triangular. */
  697. i__1 = *n - 1;
  698. for (j = 1; j <= i__1; ++j) {
  699. i__2 = *n - j;
  700. cnorm[j] = dasum_(&i__2, &a[j + 1 + j * a_dim1], &c__1);
  701. /* L20: */
  702. }
  703. cnorm[*n] = 0.;
  704. }
  705. }
  706. /* Scale the column norms by TSCAL if the maximum element in CNORM is */
  707. /* greater than BIGNUM. */
  708. imax = idamax_(n, &cnorm[1], &c__1);
  709. tmax = cnorm[imax];
  710. if (tmax <= bignum) {
  711. tscal = 1.;
  712. } else {
  713. tscal = 1. / (smlnum * tmax);
  714. dscal_(n, &tscal, &cnorm[1], &c__1);
  715. }
  716. /* Compute a bound on the computed solution vector to see if the */
  717. /* Level 2 BLAS routine DTRSV can be used. */
  718. j = idamax_(n, &x[1], &c__1);
  719. xmax = (d__1 = x[j], abs(d__1));
  720. xbnd = xmax;
  721. if (notran) {
  722. /* Compute the growth in A * x = b. */
  723. if (upper) {
  724. jfirst = *n;
  725. jlast = 1;
  726. jinc = -1;
  727. } else {
  728. jfirst = 1;
  729. jlast = *n;
  730. jinc = 1;
  731. }
  732. if (tscal != 1.) {
  733. grow = 0.;
  734. goto L50;
  735. }
  736. if (nounit) {
  737. /* A is non-unit triangular. */
  738. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  739. /* Initially, G(0) = f2cmax{x(i), i=1,...,n}. */
  740. grow = 1. / f2cmax(xbnd,smlnum);
  741. xbnd = grow;
  742. i__1 = jlast;
  743. i__2 = jinc;
  744. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  745. /* Exit the loop if the growth factor is too small. */
  746. if (grow <= smlnum) {
  747. goto L50;
  748. }
  749. /* M(j) = G(j-1) / abs(A(j,j)) */
  750. tjj = (d__1 = a[j + j * a_dim1], abs(d__1));
  751. /* Computing MIN */
  752. d__1 = xbnd, d__2 = f2cmin(1.,tjj) * grow;
  753. xbnd = f2cmin(d__1,d__2);
  754. if (tjj + cnorm[j] >= smlnum) {
  755. /* G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */
  756. grow *= tjj / (tjj + cnorm[j]);
  757. } else {
  758. /* G(j) could overflow, set GROW to 0. */
  759. grow = 0.;
  760. }
  761. /* L30: */
  762. }
  763. grow = xbnd;
  764. } else {
  765. /* A is unit triangular. */
  766. /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
  767. /* Computing MIN */
  768. d__1 = 1., d__2 = 1. / f2cmax(xbnd,smlnum);
  769. grow = f2cmin(d__1,d__2);
  770. i__2 = jlast;
  771. i__1 = jinc;
  772. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  773. /* Exit the loop if the growth factor is too small. */
  774. if (grow <= smlnum) {
  775. goto L50;
  776. }
  777. /* G(j) = G(j-1)*( 1 + CNORM(j) ) */
  778. grow *= 1. / (cnorm[j] + 1.);
  779. /* L40: */
  780. }
  781. }
  782. L50:
  783. ;
  784. } else {
  785. /* Compute the growth in A**T * x = b. */
  786. if (upper) {
  787. jfirst = 1;
  788. jlast = *n;
  789. jinc = 1;
  790. } else {
  791. jfirst = *n;
  792. jlast = 1;
  793. jinc = -1;
  794. }
  795. if (tscal != 1.) {
  796. grow = 0.;
  797. goto L80;
  798. }
  799. if (nounit) {
  800. /* A is non-unit triangular. */
  801. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  802. /* Initially, M(0) = f2cmax{x(i), i=1,...,n}. */
  803. grow = 1. / f2cmax(xbnd,smlnum);
  804. xbnd = grow;
  805. i__1 = jlast;
  806. i__2 = jinc;
  807. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  808. /* Exit the loop if the growth factor is too small. */
  809. if (grow <= smlnum) {
  810. goto L80;
  811. }
  812. /* G(j) = f2cmax( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */
  813. xj = cnorm[j] + 1.;
  814. /* Computing MIN */
  815. d__1 = grow, d__2 = xbnd / xj;
  816. grow = f2cmin(d__1,d__2);
  817. /* M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */
  818. tjj = (d__1 = a[j + j * a_dim1], abs(d__1));
  819. if (xj > tjj) {
  820. xbnd *= tjj / xj;
  821. }
  822. /* L60: */
  823. }
  824. grow = f2cmin(grow,xbnd);
  825. } else {
  826. /* A is unit triangular. */
  827. /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
  828. /* Computing MIN */
  829. d__1 = 1., d__2 = 1. / f2cmax(xbnd,smlnum);
  830. grow = f2cmin(d__1,d__2);
  831. i__2 = jlast;
  832. i__1 = jinc;
  833. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  834. /* Exit the loop if the growth factor is too small. */
  835. if (grow <= smlnum) {
  836. goto L80;
  837. }
  838. /* G(j) = ( 1 + CNORM(j) )*G(j-1) */
  839. xj = cnorm[j] + 1.;
  840. grow /= xj;
  841. /* L70: */
  842. }
  843. }
  844. L80:
  845. ;
  846. }
  847. if (grow * tscal > smlnum) {
  848. /* Use the Level 2 BLAS solve if the reciprocal of the bound on */
  849. /* elements of X is not too small. */
  850. dtrsv_(uplo, trans, diag, n, &a[a_offset], lda, &x[1], &c__1);
  851. } else {
  852. /* Use a Level 1 BLAS solve, scaling intermediate results. */
  853. if (xmax > bignum) {
  854. /* Scale X so that its components are less than or equal to */
  855. /* BIGNUM in absolute value. */
  856. *scale = bignum / xmax;
  857. dscal_(n, scale, &x[1], &c__1);
  858. xmax = bignum;
  859. }
  860. if (notran) {
  861. /* Solve A * x = b */
  862. i__1 = jlast;
  863. i__2 = jinc;
  864. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  865. /* Compute x(j) = b(j) / A(j,j), scaling x if necessary. */
  866. xj = (d__1 = x[j], abs(d__1));
  867. if (nounit) {
  868. tjjs = a[j + j * a_dim1] * tscal;
  869. } else {
  870. tjjs = tscal;
  871. if (tscal == 1.) {
  872. goto L100;
  873. }
  874. }
  875. tjj = abs(tjjs);
  876. if (tjj > smlnum) {
  877. /* abs(A(j,j)) > SMLNUM: */
  878. if (tjj < 1.) {
  879. if (xj > tjj * bignum) {
  880. /* Scale x by 1/b(j). */
  881. rec = 1. / xj;
  882. dscal_(n, &rec, &x[1], &c__1);
  883. *scale *= rec;
  884. xmax *= rec;
  885. }
  886. }
  887. x[j] /= tjjs;
  888. xj = (d__1 = x[j], abs(d__1));
  889. } else if (tjj > 0.) {
  890. /* 0 < abs(A(j,j)) <= SMLNUM: */
  891. if (xj > tjj * bignum) {
  892. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM */
  893. /* to avoid overflow when dividing by A(j,j). */
  894. rec = tjj * bignum / xj;
  895. if (cnorm[j] > 1.) {
  896. /* Scale by 1/CNORM(j) to avoid overflow when */
  897. /* multiplying x(j) times column j. */
  898. rec /= cnorm[j];
  899. }
  900. dscal_(n, &rec, &x[1], &c__1);
  901. *scale *= rec;
  902. xmax *= rec;
  903. }
  904. x[j] /= tjjs;
  905. xj = (d__1 = x[j], abs(d__1));
  906. } else {
  907. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  908. /* scale = 0, and compute a solution to A*x = 0. */
  909. i__3 = *n;
  910. for (i__ = 1; i__ <= i__3; ++i__) {
  911. x[i__] = 0.;
  912. /* L90: */
  913. }
  914. x[j] = 1.;
  915. xj = 1.;
  916. *scale = 0.;
  917. xmax = 0.;
  918. }
  919. L100:
  920. /* Scale x if necessary to avoid overflow when adding a */
  921. /* multiple of column j of A. */
  922. if (xj > 1.) {
  923. rec = 1. / xj;
  924. if (cnorm[j] > (bignum - xmax) * rec) {
  925. /* Scale x by 1/(2*abs(x(j))). */
  926. rec *= .5;
  927. dscal_(n, &rec, &x[1], &c__1);
  928. *scale *= rec;
  929. }
  930. } else if (xj * cnorm[j] > bignum - xmax) {
  931. /* Scale x by 1/2. */
  932. dscal_(n, &c_b36, &x[1], &c__1);
  933. *scale *= .5;
  934. }
  935. if (upper) {
  936. if (j > 1) {
  937. /* Compute the update */
  938. /* x(1:j-1) := x(1:j-1) - x(j) * A(1:j-1,j) */
  939. i__3 = j - 1;
  940. d__1 = -x[j] * tscal;
  941. daxpy_(&i__3, &d__1, &a[j * a_dim1 + 1], &c__1, &x[1],
  942. &c__1);
  943. i__3 = j - 1;
  944. i__ = idamax_(&i__3, &x[1], &c__1);
  945. xmax = (d__1 = x[i__], abs(d__1));
  946. }
  947. } else {
  948. if (j < *n) {
  949. /* Compute the update */
  950. /* x(j+1:n) := x(j+1:n) - x(j) * A(j+1:n,j) */
  951. i__3 = *n - j;
  952. d__1 = -x[j] * tscal;
  953. daxpy_(&i__3, &d__1, &a[j + 1 + j * a_dim1], &c__1, &
  954. x[j + 1], &c__1);
  955. i__3 = *n - j;
  956. i__ = j + idamax_(&i__3, &x[j + 1], &c__1);
  957. xmax = (d__1 = x[i__], abs(d__1));
  958. }
  959. }
  960. /* L110: */
  961. }
  962. } else {
  963. /* Solve A**T * x = b */
  964. i__2 = jlast;
  965. i__1 = jinc;
  966. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  967. /* Compute x(j) = b(j) - sum A(k,j)*x(k). */
  968. /* k<>j */
  969. xj = (d__1 = x[j], abs(d__1));
  970. uscal = tscal;
  971. rec = 1. / f2cmax(xmax,1.);
  972. if (cnorm[j] > (bignum - xj) * rec) {
  973. /* If x(j) could overflow, scale x by 1/(2*XMAX). */
  974. rec *= .5;
  975. if (nounit) {
  976. tjjs = a[j + j * a_dim1] * tscal;
  977. } else {
  978. tjjs = tscal;
  979. }
  980. tjj = abs(tjjs);
  981. if (tjj > 1.) {
  982. /* Divide by A(j,j) when scaling x if A(j,j) > 1. */
  983. /* Computing MIN */
  984. d__1 = 1., d__2 = rec * tjj;
  985. rec = f2cmin(d__1,d__2);
  986. uscal /= tjjs;
  987. }
  988. if (rec < 1.) {
  989. dscal_(n, &rec, &x[1], &c__1);
  990. *scale *= rec;
  991. xmax *= rec;
  992. }
  993. }
  994. sumj = 0.;
  995. if (uscal == 1.) {
  996. /* If the scaling needed for A in the dot product is 1, */
  997. /* call DDOT to perform the dot product. */
  998. if (upper) {
  999. i__3 = j - 1;
  1000. sumj = ddot_(&i__3, &a[j * a_dim1 + 1], &c__1, &x[1],
  1001. &c__1);
  1002. } else if (j < *n) {
  1003. i__3 = *n - j;
  1004. sumj = ddot_(&i__3, &a[j + 1 + j * a_dim1], &c__1, &x[
  1005. j + 1], &c__1);
  1006. }
  1007. } else {
  1008. /* Otherwise, use in-line code for the dot product. */
  1009. if (upper) {
  1010. i__3 = j - 1;
  1011. for (i__ = 1; i__ <= i__3; ++i__) {
  1012. sumj += a[i__ + j * a_dim1] * uscal * x[i__];
  1013. /* L120: */
  1014. }
  1015. } else if (j < *n) {
  1016. i__3 = *n;
  1017. for (i__ = j + 1; i__ <= i__3; ++i__) {
  1018. sumj += a[i__ + j * a_dim1] * uscal * x[i__];
  1019. /* L130: */
  1020. }
  1021. }
  1022. }
  1023. if (uscal == tscal) {
  1024. /* Compute x(j) := ( x(j) - sumj ) / A(j,j) if 1/A(j,j) */
  1025. /* was not used to scale the dotproduct. */
  1026. x[j] -= sumj;
  1027. xj = (d__1 = x[j], abs(d__1));
  1028. if (nounit) {
  1029. tjjs = a[j + j * a_dim1] * tscal;
  1030. } else {
  1031. tjjs = tscal;
  1032. if (tscal == 1.) {
  1033. goto L150;
  1034. }
  1035. }
  1036. /* Compute x(j) = x(j) / A(j,j), scaling if necessary. */
  1037. tjj = abs(tjjs);
  1038. if (tjj > smlnum) {
  1039. /* abs(A(j,j)) > SMLNUM: */
  1040. if (tjj < 1.) {
  1041. if (xj > tjj * bignum) {
  1042. /* Scale X by 1/abs(x(j)). */
  1043. rec = 1. / xj;
  1044. dscal_(n, &rec, &x[1], &c__1);
  1045. *scale *= rec;
  1046. xmax *= rec;
  1047. }
  1048. }
  1049. x[j] /= tjjs;
  1050. } else if (tjj > 0.) {
  1051. /* 0 < abs(A(j,j)) <= SMLNUM: */
  1052. if (xj > tjj * bignum) {
  1053. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
  1054. rec = tjj * bignum / xj;
  1055. dscal_(n, &rec, &x[1], &c__1);
  1056. *scale *= rec;
  1057. xmax *= rec;
  1058. }
  1059. x[j] /= tjjs;
  1060. } else {
  1061. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  1062. /* scale = 0, and compute a solution to A**T*x = 0. */
  1063. i__3 = *n;
  1064. for (i__ = 1; i__ <= i__3; ++i__) {
  1065. x[i__] = 0.;
  1066. /* L140: */
  1067. }
  1068. x[j] = 1.;
  1069. *scale = 0.;
  1070. xmax = 0.;
  1071. }
  1072. L150:
  1073. ;
  1074. } else {
  1075. /* Compute x(j) := x(j) / A(j,j) - sumj if the dot */
  1076. /* product has already been divided by 1/A(j,j). */
  1077. x[j] = x[j] / tjjs - sumj;
  1078. }
  1079. /* Computing MAX */
  1080. d__2 = xmax, d__3 = (d__1 = x[j], abs(d__1));
  1081. xmax = f2cmax(d__2,d__3);
  1082. /* L160: */
  1083. }
  1084. }
  1085. *scale /= tscal;
  1086. }
  1087. /* Scale the column norms by 1/TSCAL for return. */
  1088. if (tscal != 1.) {
  1089. d__1 = 1. / tscal;
  1090. dscal_(n, &d__1, &cnorm[1], &c__1);
  1091. }
  1092. return 0;
  1093. /* End of DLATRS */
  1094. } /* dlatrs_ */