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.

slatps.c 34 kB

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