14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
22 typedef BLASLONG blasint;
24 #define blasabs(x) llabs(x)
26 #define blasabs(x) labs(x)
30 #define blasabs(x) abs(x)
33 typedef blasint integer;
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
63 /* Extern is for use with -E */
74 /*external read, write*/
83 /*internal read, write*/
113 /*rewind, backspace, endfile*/
125 ftnint *inex; /*parameters in standard's order*/
151 union Multitype { /* for multiple entry points */
162 typedef union Multitype Multitype;
164 struct Vardesc { /* for Namelist */
170 typedef struct Vardesc Vardesc;
177 typedef struct Namelist Namelist;
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b) ((a) >> (b) & 1)
186 #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #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++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #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]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
261 /* procedure parameter types for -A and -C++ */
263 #define F2C_proc_par_types 1
265 typedef logical (*L_fp)(...);
267 typedef logical (*L_fp)();
270 static float spow_ui(float x, integer n) {
271 float pow=1.0; unsigned long int u;
273 if(n < 0) n = -n, x = 1/x;
282 static double dpow_ui(double x, integer n) {
283 double pow=1.0; unsigned long int u;
285 if(n < 0) n = -n, x = 1/x;
295 static _Fcomplex cpow_ui(complex x, integer n) {
296 complex pow={1.0,0.0}; unsigned long int u;
298 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
300 if(u & 01) pow.r *= x.r, pow.i *= x.i;
301 if(u >>= 1) x.r *= x.r, x.i *= x.i;
305 _Fcomplex p={pow.r, pow.i};
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310 _Complex float pow=1.0; unsigned long int u;
312 if(n < 0) n = -n, x = 1/x;
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324 _Dcomplex pow={1.0,0.0}; unsigned long int u;
326 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
328 if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329 if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
333 _Dcomplex p = {pow._Val[0], pow._Val[1]};
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338 _Complex double pow=1.0; unsigned long int u;
340 if(n < 0) n = -n, x = 1/x;
350 static integer pow_ii(integer x, integer n) {
351 integer pow; unsigned long int u;
353 if (n == 0 || x == 1) pow = 1;
354 else if (x != -1) pow = x == 0 ? 1/x : 0;
357 if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
369 double m; integer i, mi;
370 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371 if (w[i-1]>m) mi=i ,m=w[i-1];
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
376 float m; integer i, mi;
377 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378 if (w[i-1]>m) mi=i ,m=w[i-1];
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382 integer n = *n_, incx = *incx_, incy = *incy_, i;
384 _Fcomplex zdotc = {0.0, 0.0};
385 if (incx == 1 && incy == 1) {
386 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387 zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388 zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
391 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392 zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393 zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
399 _Complex float zdotc = 0.0;
400 if (incx == 1 && incy == 1) {
401 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402 zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
405 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406 zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413 integer n = *n_, incx = *incx_, incy = *incy_, i;
415 _Dcomplex zdotc = {0.0, 0.0};
416 if (incx == 1 && incy == 1) {
417 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418 zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419 zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
422 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423 zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424 zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
430 _Complex double zdotc = 0.0;
431 if (incx == 1 && incy == 1) {
432 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433 zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
436 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437 zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444 integer n = *n_, incx = *incx_, incy = *incy_, i;
446 _Fcomplex zdotc = {0.0, 0.0};
447 if (incx == 1 && incy == 1) {
448 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449 zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450 zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
453 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454 zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455 zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
461 _Complex float zdotc = 0.0;
462 if (incx == 1 && incy == 1) {
463 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464 zdotc += Cf(&x[i]) * Cf(&y[i]);
467 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468 zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475 integer n = *n_, incx = *incx_, incy = *incy_, i;
477 _Dcomplex zdotc = {0.0, 0.0};
478 if (incx == 1 && incy == 1) {
479 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480 zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481 zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
484 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485 zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486 zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
492 _Complex double zdotc = 0.0;
493 if (incx == 1 && incy == 1) {
494 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495 zdotc += Cd(&x[i]) * Cd(&y[i]);
498 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499 zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
505 /* -- translated by f2c (version 20000121).
506 You must link the resulting object file with the libraries:
507 -lf2c -lm (in that order)
513 /* Table of constant values */
515 static integer c__1 = 1;
516 static doublereal c_b36 = .5;
518 /* > \brief \b DLATPS solves a triangular system of equations with the matrix held in packed storage. */
520 /* =========== DOCUMENTATION =========== */
522 /* Online html documentation available at */
523 /* http://www.netlib.org/lapack/explore-html/ */
526 /* > Download DLATPS + dependencies */
527 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlatps.
530 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlatps.
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlatps.
541 /* SUBROUTINE DLATPS( UPLO, TRANS, DIAG, NORMIN, N, AP, X, SCALE, */
544 /* CHARACTER DIAG, NORMIN, TRANS, UPLO */
545 /* INTEGER INFO, N */
546 /* DOUBLE PRECISION SCALE */
547 /* DOUBLE PRECISION AP( * ), CNORM( * ), X( * ) */
550 /* > \par Purpose: */
555 /* > DLATPS solves one of the triangular systems */
557 /* > A *x = s*b or A**T*x = s*b */
559 /* > with scaling to prevent overflow, where A is an upper or lower */
560 /* > triangular matrix stored in packed form. Here A**T denotes the */
561 /* > transpose of A, x and b are n-element vectors, and s is a scaling */
562 /* > factor, usually less than or equal to 1, chosen so that the */
563 /* > components of x will be less than the overflow threshold. If the */
564 /* > unscaled problem will not cause overflow, the Level 2 BLAS routine */
565 /* > DTPSV is called. If the matrix A is singular (A(j,j) = 0 for some j), */
566 /* > then s is set to 0 and a non-trivial solution to A*x = 0 is returned. */
572 /* > \param[in] UPLO */
574 /* > UPLO is CHARACTER*1 */
575 /* > Specifies whether the matrix A is upper or lower triangular. */
576 /* > = 'U': Upper triangular */
577 /* > = 'L': Lower triangular */
580 /* > \param[in] TRANS */
582 /* > TRANS is CHARACTER*1 */
583 /* > Specifies the operation applied to A. */
584 /* > = 'N': Solve A * x = s*b (No transpose) */
585 /* > = 'T': Solve A**T* x = s*b (Transpose) */
586 /* > = 'C': Solve A**T* x = s*b (Conjugate transpose = Transpose) */
589 /* > \param[in] DIAG */
591 /* > DIAG is CHARACTER*1 */
592 /* > Specifies whether or not the matrix A is unit triangular. */
593 /* > = 'N': Non-unit triangular */
594 /* > = 'U': Unit triangular */
597 /* > \param[in] NORMIN */
599 /* > NORMIN is CHARACTER*1 */
600 /* > Specifies whether CNORM has been set or not. */
601 /* > = 'Y': CNORM contains the column norms on entry */
602 /* > = 'N': CNORM is not set on entry. On exit, the norms will */
603 /* > be computed and stored in CNORM. */
609 /* > The order of the matrix A. N >= 0. */
612 /* > \param[in] AP */
614 /* > AP is DOUBLE PRECISION array, dimension (N*(N+1)/2) */
615 /* > The upper or lower triangular matrix A, packed columnwise in */
616 /* > a linear array. The j-th column of A is stored in the array */
617 /* > AP as follows: */
618 /* > if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
619 /* > if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
622 /* > \param[in,out] X */
624 /* > X is DOUBLE PRECISION array, dimension (N) */
625 /* > On entry, the right hand side b of the triangular system. */
626 /* > On exit, X is overwritten by the solution vector x. */
629 /* > \param[out] SCALE */
631 /* > SCALE is DOUBLE PRECISION */
632 /* > The scaling factor s for the triangular system */
633 /* > A * x = s*b or A**T* x = s*b. */
634 /* > If SCALE = 0, the matrix A is singular or badly scaled, and */
635 /* > the vector x is an exact or approximate solution to A*x = 0. */
638 /* > \param[in,out] CNORM */
640 /* > CNORM is DOUBLE PRECISION array, dimension (N) */
642 /* > If NORMIN = 'Y', CNORM is an input argument and CNORM(j) */
643 /* > contains the norm of the off-diagonal part of the j-th column */
644 /* > of A. If TRANS = 'N', CNORM(j) must be greater than or equal */
645 /* > to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) */
646 /* > must be greater than or equal to the 1-norm. */
648 /* > If NORMIN = 'N', CNORM is an output argument and CNORM(j) */
649 /* > returns the 1-norm of the offdiagonal part of the j-th column */
653 /* > \param[out] INFO */
655 /* > INFO is INTEGER */
656 /* > = 0: successful exit */
657 /* > < 0: if INFO = -k, the k-th argument had an illegal value */
663 /* > \author Univ. of Tennessee */
664 /* > \author Univ. of California Berkeley */
665 /* > \author Univ. of Colorado Denver */
666 /* > \author NAG Ltd. */
668 /* > \date December 2016 */
670 /* > \ingroup doubleOTHERauxiliary */
672 /* > \par Further Details: */
673 /* ===================== */
677 /* > A rough bound on x is computed; if that is less than overflow, DTPSV */
678 /* > is called, otherwise, specific code is used which checks for possible */
679 /* > overflow or divide-by-zero at every operation. */
681 /* > A columnwise scheme is used for solving A*x = b. The basic algorithm */
682 /* > if A is lower triangular is */
684 /* > x[1:n] := b[1:n] */
685 /* > for j = 1, ..., n */
686 /* > x(j) := x(j) / A(j,j) */
687 /* > x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] */
690 /* > Define bounds on the components of x after j iterations of the loop: */
691 /* > M(j) = bound on x[1:j] */
692 /* > G(j) = bound on x[j+1:n] */
693 /* > Initially, let M(0) = 0 and G(0) = f2cmax{x(i), i=1,...,n}. */
695 /* > Then for iteration j+1 we have */
696 /* > M(j+1) <= G(j) / | A(j+1,j+1) | */
697 /* > G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | */
698 /* > <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | ) */
700 /* > where CNORM(j+1) is greater than or equal to the infinity-norm of */
701 /* > column j+1 of A, not counting the diagonal. Hence */
703 /* > G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | ) */
707 /* > |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| ) */
710 /* > Since |x(j)| <= M(j), we use the Level 2 BLAS routine DTPSV if the */
711 /* > reciprocal of the largest M(j), j=1,..,n, is larger than */
712 /* > f2cmax(underflow, 1/overflow). */
714 /* > The bound on x(j) is also used to determine when a step in the */
715 /* > columnwise method can be performed without fear of overflow. If */
716 /* > the computed bound is greater than a large constant, x is scaled to */
717 /* > prevent overflow, but if the bound overflows, x is set to 0, x(j) to */
718 /* > 1, and scale to 0, and a non-trivial solution to A*x = 0 is found. */
720 /* > Similarly, a row-wise scheme is used to solve A**T*x = b. The basic */
721 /* > algorithm for A upper triangular is */
723 /* > for j = 1, ..., n */
724 /* > x(j) := ( b(j) - A[1:j-1,j]**T * x[1:j-1] ) / A(j,j) */
727 /* > We simultaneously compute two bounds */
728 /* > G(j) = bound on ( b(i) - A[1:i-1,i]**T * x[1:i-1] ), 1<=i<=j */
729 /* > M(j) = bound on x(i), 1<=i<=j */
731 /* > The initial values are G(0) = 0, M(0) = f2cmax{b(i), i=1,..,n}, and we */
732 /* > add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. */
733 /* > Then the bound on x(j) is */
735 /* > M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) | */
737 /* > <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| ) */
740 /* > and we can safely call DTPSV if 1/M(n) and 1/G(n) are both greater */
741 /* > than f2cmax(underflow, 1/overflow). */
744 /* ===================================================================== */
745 /* Subroutine */ int dlatps_(char *uplo, char *trans, char *diag, char *
746 normin, integer *n, doublereal *ap, doublereal *x, doublereal *scale,
747 doublereal *cnorm, integer *info)
749 /* System generated locals */
750 integer i__1, i__2, i__3;
751 doublereal d__1, d__2, d__3;
753 /* Local variables */
755 extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
759 doublereal tmax, tjjs, xmax, grow, sumj;
761 extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
763 extern logical lsame_(char *, char *);
764 doublereal tscal, uscal;
765 extern doublereal dasum_(integer *, doublereal *, integer *);
767 extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *,
768 integer *, doublereal *, integer *);
770 extern /* Subroutine */ int dtpsv_(char *, char *, char *, integer *,
771 doublereal *, doublereal *, integer *);
772 extern doublereal dlamch_(char *);
775 extern integer idamax_(integer *, doublereal *, integer *);
776 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
785 /* -- LAPACK auxiliary routine (version 3.7.0) -- */
786 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
787 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
791 /* ===================================================================== */
794 /* Parameter adjustments */
801 upper = lsame_(uplo, "U");
802 notran = lsame_(trans, "N");
803 nounit = lsame_(diag, "N");
805 /* Test the input parameters. */
807 if (! upper && ! lsame_(uplo, "L")) {
809 } else if (! notran && ! lsame_(trans, "T") && !
810 lsame_(trans, "C")) {
812 } else if (! nounit && ! lsame_(diag, "U")) {
814 } else if (! lsame_(normin, "Y") && ! lsame_(normin,
822 xerbla_("DLATPS", &i__1, (ftnlen)6);
826 /* Quick return if possible */
832 /* Determine machine dependent parameters to control overflow. */
834 smlnum = dlamch_("Safe minimum") / dlamch_("Precision");
835 bignum = 1. / smlnum;
838 if (lsame_(normin, "N")) {
840 /* Compute the 1-norm of each column, not including the diagonal. */
844 /* A is upper triangular. */
848 for (j = 1; j <= i__1; ++j) {
850 cnorm[j] = dasum_(&i__2, &ap[ip], &c__1);
856 /* A is lower triangular. */
860 for (j = 1; j <= i__1; ++j) {
862 cnorm[j] = dasum_(&i__2, &ap[ip + 1], &c__1);
863 ip = ip + *n - j + 1;
870 /* Scale the column norms by TSCAL if the maximum element in CNORM is */
871 /* greater than BIGNUM. */
873 imax = idamax_(n, &cnorm[1], &c__1);
875 if (tmax <= bignum) {
878 tscal = 1. / (smlnum * tmax);
879 dscal_(n, &tscal, &cnorm[1], &c__1);
882 /* Compute a bound on the computed solution vector to see if the */
883 /* Level 2 BLAS routine DTPSV can be used. */
885 j = idamax_(n, &x[1], &c__1);
886 xmax = (d__1 = x[j], abs(d__1));
890 /* Compute the growth in A * x = b. */
909 /* A is non-unit triangular. */
911 /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
912 /* Initially, G(0) = f2cmax{x(i), i=1,...,n}. */
914 grow = 1. / f2cmax(xbnd,smlnum);
916 ip = jfirst * (jfirst + 1) / 2;
920 for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
922 /* Exit the loop if the growth factor is too small. */
924 if (grow <= smlnum) {
928 /* M(j) = G(j-1) / abs(A(j,j)) */
930 tjj = (d__1 = ap[ip], abs(d__1));
932 d__1 = xbnd, d__2 = f2cmin(1.,tjj) * grow;
933 xbnd = f2cmin(d__1,d__2);
934 if (tjj + cnorm[j] >= smlnum) {
936 /* G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */
938 grow *= tjj / (tjj + cnorm[j]);
941 /* G(j) could overflow, set GROW to 0. */
952 /* A is unit triangular. */
954 /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
957 d__1 = 1., d__2 = 1. / f2cmax(xbnd,smlnum);
958 grow = f2cmin(d__1,d__2);
961 for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
963 /* Exit the loop if the growth factor is too small. */
965 if (grow <= smlnum) {
969 /* G(j) = G(j-1)*( 1 + CNORM(j) ) */
971 grow *= 1. / (cnorm[j] + 1.);
980 /* Compute the growth in A**T * x = b. */
999 /* A is non-unit triangular. */
1001 /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
1002 /* Initially, M(0) = f2cmax{x(i), i=1,...,n}. */
1004 grow = 1. / f2cmax(xbnd,smlnum);
1006 ip = jfirst * (jfirst + 1) / 2;
1010 for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
1012 /* Exit the loop if the growth factor is too small. */
1014 if (grow <= smlnum) {
1018 /* G(j) = f2cmax( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */
1022 d__1 = grow, d__2 = xbnd / xj;
1023 grow = f2cmin(d__1,d__2);
1025 /* M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */
1027 tjj = (d__1 = ap[ip], abs(d__1));
1035 grow = f2cmin(grow,xbnd);
1038 /* A is unit triangular. */
1040 /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
1043 d__1 = 1., d__2 = 1. / f2cmax(xbnd,smlnum);
1044 grow = f2cmin(d__1,d__2);
1047 for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
1049 /* Exit the loop if the growth factor is too small. */
1051 if (grow <= smlnum) {
1055 /* G(j) = ( 1 + CNORM(j) )*G(j-1) */
1066 if (grow * tscal > smlnum) {
1068 /* Use the Level 2 BLAS solve if the reciprocal of the bound on */
1069 /* elements of X is not too small. */
1071 dtpsv_(uplo, trans, diag, n, &ap[1], &x[1], &c__1);
1074 /* Use a Level 1 BLAS solve, scaling intermediate results. */
1076 if (xmax > bignum) {
1078 /* Scale X so that its components are less than or equal to */
1079 /* BIGNUM in absolute value. */
1081 *scale = bignum / xmax;
1082 dscal_(n, scale, &x[1], &c__1);
1088 /* Solve A * x = b */
1090 ip = jfirst * (jfirst + 1) / 2;
1093 for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
1095 /* Compute x(j) = b(j) / A(j,j), scaling x if necessary. */
1097 xj = (d__1 = x[j], abs(d__1));
1099 tjjs = ap[ip] * tscal;
1109 /* abs(A(j,j)) > SMLNUM: */
1112 if (xj > tjj * bignum) {
1114 /* Scale x by 1/b(j). */
1117 dscal_(n, &rec, &x[1], &c__1);
1123 xj = (d__1 = x[j], abs(d__1));
1124 } else if (tjj > 0.) {
1126 /* 0 < abs(A(j,j)) <= SMLNUM: */
1128 if (xj > tjj * bignum) {
1130 /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM */
1131 /* to avoid overflow when dividing by A(j,j). */
1133 rec = tjj * bignum / xj;
1134 if (cnorm[j] > 1.) {
1136 /* Scale by 1/CNORM(j) to avoid overflow when */
1137 /* multiplying x(j) times column j. */
1141 dscal_(n, &rec, &x[1], &c__1);
1146 xj = (d__1 = x[j], abs(d__1));
1149 /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
1150 /* scale = 0, and compute a solution to A*x = 0. */
1153 for (i__ = 1; i__ <= i__3; ++i__) {
1164 /* Scale x if necessary to avoid overflow when adding a */
1165 /* multiple of column j of A. */
1169 if (cnorm[j] > (bignum - xmax) * rec) {
1171 /* Scale x by 1/(2*abs(x(j))). */
1174 dscal_(n, &rec, &x[1], &c__1);
1177 } else if (xj * cnorm[j] > bignum - xmax) {
1179 /* Scale x by 1/2. */
1181 dscal_(n, &c_b36, &x[1], &c__1);
1188 /* Compute the update */
1189 /* x(1:j-1) := x(1:j-1) - x(j) * A(1:j-1,j) */
1192 d__1 = -x[j] * tscal;
1193 daxpy_(&i__3, &d__1, &ap[ip - j + 1], &c__1, &x[1], &
1196 i__ = idamax_(&i__3, &x[1], &c__1);
1197 xmax = (d__1 = x[i__], abs(d__1));
1203 /* Compute the update */
1204 /* x(j+1:n) := x(j+1:n) - x(j) * A(j+1:n,j) */
1207 d__1 = -x[j] * tscal;
1208 daxpy_(&i__3, &d__1, &ap[ip + 1], &c__1, &x[j + 1], &
1211 i__ = j + idamax_(&i__3, &x[j + 1], &c__1);
1212 xmax = (d__1 = x[i__], abs(d__1));
1214 ip = ip + *n - j + 1;
1221 /* Solve A**T * x = b */
1223 ip = jfirst * (jfirst + 1) / 2;
1227 for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
1229 /* Compute x(j) = b(j) - sum A(k,j)*x(k). */
1232 xj = (d__1 = x[j], abs(d__1));
1234 rec = 1. / f2cmax(xmax,1.);
1235 if (cnorm[j] > (bignum - xj) * rec) {
1237 /* If x(j) could overflow, scale x by 1/(2*XMAX). */
1241 tjjs = ap[ip] * tscal;
1248 /* Divide by A(j,j) when scaling x if A(j,j) > 1. */
1251 d__1 = 1., d__2 = rec * tjj;
1252 rec = f2cmin(d__1,d__2);
1256 dscal_(n, &rec, &x[1], &c__1);
1265 /* If the scaling needed for A in the dot product is 1, */
1266 /* call DDOT to perform the dot product. */
1270 sumj = ddot_(&i__3, &ap[ip - j + 1], &c__1, &x[1], &
1272 } else if (j < *n) {
1274 sumj = ddot_(&i__3, &ap[ip + 1], &c__1, &x[j + 1], &
1279 /* Otherwise, use in-line code for the dot product. */
1283 for (i__ = 1; i__ <= i__3; ++i__) {
1284 sumj += ap[ip - j + i__] * uscal * x[i__];
1287 } else if (j < *n) {
1289 for (i__ = 1; i__ <= i__3; ++i__) {
1290 sumj += ap[ip + i__] * uscal * x[j + i__];
1296 if (uscal == tscal) {
1298 /* Compute x(j) := ( x(j) - sumj ) / A(j,j) if 1/A(j,j) */
1299 /* was not used to scale the dotproduct. */
1302 xj = (d__1 = x[j], abs(d__1));
1305 /* Compute x(j) = x(j) / A(j,j), scaling if necessary. */
1307 tjjs = ap[ip] * tscal;
1317 /* abs(A(j,j)) > SMLNUM: */
1320 if (xj > tjj * bignum) {
1322 /* Scale X by 1/abs(x(j)). */
1325 dscal_(n, &rec, &x[1], &c__1);
1331 } else if (tjj > 0.) {
1333 /* 0 < abs(A(j,j)) <= SMLNUM: */
1335 if (xj > tjj * bignum) {
1337 /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
1339 rec = tjj * bignum / xj;
1340 dscal_(n, &rec, &x[1], &c__1);
1347 /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
1348 /* scale = 0, and compute a solution to A**T*x = 0. */
1351 for (i__ = 1; i__ <= i__3; ++i__) {
1363 /* Compute x(j) := x(j) / A(j,j) - sumj if the dot */
1364 /* product has already been divided by 1/A(j,j). */
1366 x[j] = x[j] / tjjs - sumj;
1369 d__2 = xmax, d__3 = (d__1 = x[j], abs(d__1));
1370 xmax = f2cmax(d__2,d__3);
1379 /* Scale the column norms by 1/TSCAL for return. */
1383 dscal_(n, &d__1, &cnorm[1], &c__1);