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.

dlatps.c 34 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  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 DLATPS 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 DLATPS + dependencies */
  388. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlatps.
  389. f"> */
  390. /* > [TGZ]</a> */
  391. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlatps.
  392. f"> */
  393. /* > [ZIP]</a> */
  394. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlatps.
  395. f"> */
  396. /* > [TXT]</a> */
  397. /* > \endhtmlonly */
  398. /* Definition: */
  399. /* =========== */
  400. /* SUBROUTINE DLATPS( UPLO, TRANS, DIAG, NORMIN, N, AP, X, SCALE, */
  401. /* CNORM, INFO ) */
  402. /* CHARACTER DIAG, NORMIN, TRANS, UPLO */
  403. /* INTEGER INFO, N */
  404. /* DOUBLE PRECISION SCALE */
  405. /* DOUBLE PRECISION AP( * ), CNORM( * ), X( * ) */
  406. /* > \par Purpose: */
  407. /* ============= */
  408. /* > */
  409. /* > \verbatim */
  410. /* > */
  411. /* > DLATPS 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. /* > DTPSV 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION */
  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 DOUBLE PRECISION 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 doubleOTHERauxiliary */
  521. /* > \par Further Details: */
  522. /* ===================== */
  523. /* > */
  524. /* > \verbatim */
  525. /* > */
  526. /* > A rough bound on x is computed; if that is less than overflow, DTPSV */
  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 DTPSV 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 DTPSV if 1/M(n) and 1/G(n) are both greater */
  590. /* > than f2cmax(underflow, 1/overflow). */
  591. /* > \endverbatim */
  592. /* > */
  593. /* ===================================================================== */
  594. /* Subroutine */ int dlatps_(char *uplo, char *trans, char *diag, char *
  595. normin, integer *n, doublereal *ap, doublereal *x, doublereal *scale,
  596. doublereal *cnorm, integer *info)
  597. {
  598. /* System generated locals */
  599. integer i__1, i__2, i__3;
  600. doublereal d__1, d__2, d__3;
  601. /* Local variables */
  602. integer jinc, jlen;
  603. extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
  604. integer *);
  605. doublereal xbnd;
  606. integer imax;
  607. doublereal tmax, tjjs, xmax, grow, sumj;
  608. integer i__, j;
  609. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  610. integer *);
  611. extern logical lsame_(char *, char *);
  612. doublereal tscal, uscal;
  613. extern doublereal dasum_(integer *, doublereal *, integer *);
  614. integer jlast;
  615. extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *,
  616. integer *, doublereal *, integer *);
  617. logical upper;
  618. extern /* Subroutine */ int dtpsv_(char *, char *, char *, integer *,
  619. doublereal *, doublereal *, integer *);
  620. extern doublereal dlamch_(char *);
  621. integer ip;
  622. doublereal xj;
  623. extern integer idamax_(integer *, doublereal *, integer *);
  624. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  625. doublereal bignum;
  626. logical notran;
  627. integer jfirst;
  628. doublereal smlnum;
  629. logical nounit;
  630. doublereal rec, tjj;
  631. /* -- LAPACK auxiliary routine (version 3.7.0) -- */
  632. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  633. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  634. /* December 2016 */
  635. /* ===================================================================== */
  636. /* Parameter adjustments */
  637. --cnorm;
  638. --x;
  639. --ap;
  640. /* Function Body */
  641. *info = 0;
  642. upper = lsame_(uplo, "U");
  643. notran = lsame_(trans, "N");
  644. nounit = lsame_(diag, "N");
  645. /* Test the input parameters. */
  646. if (! upper && ! lsame_(uplo, "L")) {
  647. *info = -1;
  648. } else if (! notran && ! lsame_(trans, "T") && !
  649. lsame_(trans, "C")) {
  650. *info = -2;
  651. } else if (! nounit && ! lsame_(diag, "U")) {
  652. *info = -3;
  653. } else if (! lsame_(normin, "Y") && ! lsame_(normin,
  654. "N")) {
  655. *info = -4;
  656. } else if (*n < 0) {
  657. *info = -5;
  658. }
  659. if (*info != 0) {
  660. i__1 = -(*info);
  661. xerbla_("DLATPS", &i__1, (ftnlen)6);
  662. return 0;
  663. }
  664. /* Quick return if possible */
  665. if (*n == 0) {
  666. return 0;
  667. }
  668. /* Determine machine dependent parameters to control overflow. */
  669. smlnum = dlamch_("Safe minimum") / dlamch_("Precision");
  670. bignum = 1. / smlnum;
  671. *scale = 1.;
  672. if (lsame_(normin, "N")) {
  673. /* Compute the 1-norm of each column, not including the diagonal. */
  674. if (upper) {
  675. /* A is upper triangular. */
  676. ip = 1;
  677. i__1 = *n;
  678. for (j = 1; j <= i__1; ++j) {
  679. i__2 = j - 1;
  680. cnorm[j] = dasum_(&i__2, &ap[ip], &c__1);
  681. ip += j;
  682. /* L10: */
  683. }
  684. } else {
  685. /* A is lower triangular. */
  686. ip = 1;
  687. i__1 = *n - 1;
  688. for (j = 1; j <= i__1; ++j) {
  689. i__2 = *n - j;
  690. cnorm[j] = dasum_(&i__2, &ap[ip + 1], &c__1);
  691. ip = ip + *n - j + 1;
  692. /* L20: */
  693. }
  694. cnorm[*n] = 0.;
  695. }
  696. }
  697. /* Scale the column norms by TSCAL if the maximum element in CNORM is */
  698. /* greater than BIGNUM. */
  699. imax = idamax_(n, &cnorm[1], &c__1);
  700. tmax = cnorm[imax];
  701. if (tmax <= bignum) {
  702. tscal = 1.;
  703. } else {
  704. tscal = 1. / (smlnum * tmax);
  705. dscal_(n, &tscal, &cnorm[1], &c__1);
  706. }
  707. /* Compute a bound on the computed solution vector to see if the */
  708. /* Level 2 BLAS routine DTPSV can be used. */
  709. j = idamax_(n, &x[1], &c__1);
  710. xmax = (d__1 = x[j], abs(d__1));
  711. xbnd = xmax;
  712. if (notran) {
  713. /* Compute the growth in A * x = b. */
  714. if (upper) {
  715. jfirst = *n;
  716. jlast = 1;
  717. jinc = -1;
  718. } else {
  719. jfirst = 1;
  720. jlast = *n;
  721. jinc = 1;
  722. }
  723. if (tscal != 1.) {
  724. grow = 0.;
  725. goto L50;
  726. }
  727. if (nounit) {
  728. /* A is non-unit triangular. */
  729. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  730. /* Initially, G(0) = f2cmax{x(i), i=1,...,n}. */
  731. grow = 1. / f2cmax(xbnd,smlnum);
  732. xbnd = grow;
  733. ip = jfirst * (jfirst + 1) / 2;
  734. jlen = *n;
  735. i__1 = jlast;
  736. i__2 = jinc;
  737. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  738. /* Exit the loop if the growth factor is too small. */
  739. if (grow <= smlnum) {
  740. goto L50;
  741. }
  742. /* M(j) = G(j-1) / abs(A(j,j)) */
  743. tjj = (d__1 = ap[ip], abs(d__1));
  744. /* Computing MIN */
  745. d__1 = xbnd, d__2 = f2cmin(1.,tjj) * grow;
  746. xbnd = f2cmin(d__1,d__2);
  747. if (tjj + cnorm[j] >= smlnum) {
  748. /* G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */
  749. grow *= tjj / (tjj + cnorm[j]);
  750. } else {
  751. /* G(j) could overflow, set GROW to 0. */
  752. grow = 0.;
  753. }
  754. ip += jinc * jlen;
  755. --jlen;
  756. /* L30: */
  757. }
  758. grow = xbnd;
  759. } else {
  760. /* A is unit triangular. */
  761. /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
  762. /* Computing MIN */
  763. d__1 = 1., d__2 = 1. / f2cmax(xbnd,smlnum);
  764. grow = f2cmin(d__1,d__2);
  765. i__2 = jlast;
  766. i__1 = jinc;
  767. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  768. /* Exit the loop if the growth factor is too small. */
  769. if (grow <= smlnum) {
  770. goto L50;
  771. }
  772. /* G(j) = G(j-1)*( 1 + CNORM(j) ) */
  773. grow *= 1. / (cnorm[j] + 1.);
  774. /* L40: */
  775. }
  776. }
  777. L50:
  778. ;
  779. } else {
  780. /* Compute the growth in A**T * x = b. */
  781. if (upper) {
  782. jfirst = 1;
  783. jlast = *n;
  784. jinc = 1;
  785. } else {
  786. jfirst = *n;
  787. jlast = 1;
  788. jinc = -1;
  789. }
  790. if (tscal != 1.) {
  791. grow = 0.;
  792. goto L80;
  793. }
  794. if (nounit) {
  795. /* A is non-unit triangular. */
  796. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  797. /* Initially, M(0) = f2cmax{x(i), i=1,...,n}. */
  798. grow = 1. / f2cmax(xbnd,smlnum);
  799. xbnd = grow;
  800. ip = jfirst * (jfirst + 1) / 2;
  801. jlen = 1;
  802. i__1 = jlast;
  803. i__2 = jinc;
  804. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  805. /* Exit the loop if the growth factor is too small. */
  806. if (grow <= smlnum) {
  807. goto L80;
  808. }
  809. /* G(j) = f2cmax( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */
  810. xj = cnorm[j] + 1.;
  811. /* Computing MIN */
  812. d__1 = grow, d__2 = xbnd / xj;
  813. grow = f2cmin(d__1,d__2);
  814. /* M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */
  815. tjj = (d__1 = ap[ip], abs(d__1));
  816. if (xj > tjj) {
  817. xbnd *= tjj / xj;
  818. }
  819. ++jlen;
  820. ip += jinc * jlen;
  821. /* L60: */
  822. }
  823. grow = f2cmin(grow,xbnd);
  824. } else {
  825. /* A is unit triangular. */
  826. /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
  827. /* Computing MIN */
  828. d__1 = 1., d__2 = 1. / f2cmax(xbnd,smlnum);
  829. grow = f2cmin(d__1,d__2);
  830. i__2 = jlast;
  831. i__1 = jinc;
  832. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  833. /* Exit the loop if the growth factor is too small. */
  834. if (grow <= smlnum) {
  835. goto L80;
  836. }
  837. /* G(j) = ( 1 + CNORM(j) )*G(j-1) */
  838. xj = cnorm[j] + 1.;
  839. grow /= xj;
  840. /* L70: */
  841. }
  842. }
  843. L80:
  844. ;
  845. }
  846. if (grow * tscal > smlnum) {
  847. /* Use the Level 2 BLAS solve if the reciprocal of the bound on */
  848. /* elements of X is not too small. */
  849. dtpsv_(uplo, trans, diag, n, &ap[1], &x[1], &c__1);
  850. } else {
  851. /* Use a Level 1 BLAS solve, scaling intermediate results. */
  852. if (xmax > bignum) {
  853. /* Scale X so that its components are less than or equal to */
  854. /* BIGNUM in absolute value. */
  855. *scale = bignum / xmax;
  856. dscal_(n, scale, &x[1], &c__1);
  857. xmax = bignum;
  858. }
  859. if (notran) {
  860. /* Solve A * x = b */
  861. ip = jfirst * (jfirst + 1) / 2;
  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 = ap[ip] * 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, &ap[ip - j + 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. ip -= j;
  948. } else {
  949. if (j < *n) {
  950. /* Compute the update */
  951. /* x(j+1:n) := x(j+1:n) - x(j) * A(j+1:n,j) */
  952. i__3 = *n - j;
  953. d__1 = -x[j] * tscal;
  954. daxpy_(&i__3, &d__1, &ap[ip + 1], &c__1, &x[j + 1], &
  955. c__1);
  956. i__3 = *n - j;
  957. i__ = j + idamax_(&i__3, &x[j + 1], &c__1);
  958. xmax = (d__1 = x[i__], abs(d__1));
  959. }
  960. ip = ip + *n - j + 1;
  961. }
  962. /* L110: */
  963. }
  964. } else {
  965. /* Solve A**T * x = b */
  966. ip = jfirst * (jfirst + 1) / 2;
  967. jlen = 1;
  968. i__2 = jlast;
  969. i__1 = jinc;
  970. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  971. /* Compute x(j) = b(j) - sum A(k,j)*x(k). */
  972. /* k<>j */
  973. xj = (d__1 = x[j], abs(d__1));
  974. uscal = tscal;
  975. rec = 1. / f2cmax(xmax,1.);
  976. if (cnorm[j] > (bignum - xj) * rec) {
  977. /* If x(j) could overflow, scale x by 1/(2*XMAX). */
  978. rec *= .5;
  979. if (nounit) {
  980. tjjs = ap[ip] * tscal;
  981. } else {
  982. tjjs = tscal;
  983. }
  984. tjj = abs(tjjs);
  985. if (tjj > 1.) {
  986. /* Divide by A(j,j) when scaling x if A(j,j) > 1. */
  987. /* Computing MIN */
  988. d__1 = 1., d__2 = rec * tjj;
  989. rec = f2cmin(d__1,d__2);
  990. uscal /= tjjs;
  991. }
  992. if (rec < 1.) {
  993. dscal_(n, &rec, &x[1], &c__1);
  994. *scale *= rec;
  995. xmax *= rec;
  996. }
  997. }
  998. sumj = 0.;
  999. if (uscal == 1.) {
  1000. /* If the scaling needed for A in the dot product is 1, */
  1001. /* call DDOT to perform the dot product. */
  1002. if (upper) {
  1003. i__3 = j - 1;
  1004. sumj = ddot_(&i__3, &ap[ip - j + 1], &c__1, &x[1], &
  1005. c__1);
  1006. } else if (j < *n) {
  1007. i__3 = *n - j;
  1008. sumj = ddot_(&i__3, &ap[ip + 1], &c__1, &x[j + 1], &
  1009. c__1);
  1010. }
  1011. } else {
  1012. /* Otherwise, use in-line code for the dot product. */
  1013. if (upper) {
  1014. i__3 = j - 1;
  1015. for (i__ = 1; i__ <= i__3; ++i__) {
  1016. sumj += ap[ip - j + i__] * uscal * x[i__];
  1017. /* L120: */
  1018. }
  1019. } else if (j < *n) {
  1020. i__3 = *n - j;
  1021. for (i__ = 1; i__ <= i__3; ++i__) {
  1022. sumj += ap[ip + i__] * uscal * x[j + i__];
  1023. /* L130: */
  1024. }
  1025. }
  1026. }
  1027. if (uscal == tscal) {
  1028. /* Compute x(j) := ( x(j) - sumj ) / A(j,j) if 1/A(j,j) */
  1029. /* was not used to scale the dotproduct. */
  1030. x[j] -= sumj;
  1031. xj = (d__1 = x[j], abs(d__1));
  1032. if (nounit) {
  1033. /* Compute x(j) = x(j) / A(j,j), scaling if necessary. */
  1034. tjjs = ap[ip] * tscal;
  1035. } else {
  1036. tjjs = tscal;
  1037. if (tscal == 1.) {
  1038. goto L150;
  1039. }
  1040. }
  1041. tjj = abs(tjjs);
  1042. if (tjj > smlnum) {
  1043. /* abs(A(j,j)) > SMLNUM: */
  1044. if (tjj < 1.) {
  1045. if (xj > tjj * bignum) {
  1046. /* Scale X by 1/abs(x(j)). */
  1047. rec = 1. / xj;
  1048. dscal_(n, &rec, &x[1], &c__1);
  1049. *scale *= rec;
  1050. xmax *= rec;
  1051. }
  1052. }
  1053. x[j] /= tjjs;
  1054. } else if (tjj > 0.) {
  1055. /* 0 < abs(A(j,j)) <= SMLNUM: */
  1056. if (xj > tjj * bignum) {
  1057. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
  1058. rec = tjj * bignum / xj;
  1059. dscal_(n, &rec, &x[1], &c__1);
  1060. *scale *= rec;
  1061. xmax *= rec;
  1062. }
  1063. x[j] /= tjjs;
  1064. } else {
  1065. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  1066. /* scale = 0, and compute a solution to A**T*x = 0. */
  1067. i__3 = *n;
  1068. for (i__ = 1; i__ <= i__3; ++i__) {
  1069. x[i__] = 0.;
  1070. /* L140: */
  1071. }
  1072. x[j] = 1.;
  1073. *scale = 0.;
  1074. xmax = 0.;
  1075. }
  1076. L150:
  1077. ;
  1078. } else {
  1079. /* Compute x(j) := x(j) / A(j,j) - sumj if the dot */
  1080. /* product has already been divided by 1/A(j,j). */
  1081. x[j] = x[j] / tjjs - sumj;
  1082. }
  1083. /* Computing MAX */
  1084. d__2 = xmax, d__3 = (d__1 = x[j], abs(d__1));
  1085. xmax = f2cmax(d__2,d__3);
  1086. ++jlen;
  1087. ip += jinc * jlen;
  1088. /* L160: */
  1089. }
  1090. }
  1091. *scale /= tscal;
  1092. }
  1093. /* Scale the column norms by 1/TSCAL for return. */
  1094. if (tscal != 1.) {
  1095. d__1 = 1. / tscal;
  1096. dscal_(n, &d__1, &cnorm[1], &c__1);
  1097. }
  1098. return 0;
  1099. /* End of DLATPS */
  1100. } /* dlatps_ */