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)
514 /* Table of constant values */
516 static integer c__1 = 1;
518 /* > \brief \b ZHETF2 computes the factorization of a complex Hermitian matrix, using the diagonal pivoting me
519 thod (unblocked algorithm, calling Level 2 BLAS). */
521 /* =========== DOCUMENTATION =========== */
523 /* Online html documentation available at */
524 /* http://www.netlib.org/lapack/explore-html/ */
527 /* > Download ZHETF2 + dependencies */
528 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhetf2.
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhetf2.
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhetf2.
542 /* SUBROUTINE ZHETF2( UPLO, N, A, LDA, IPIV, INFO ) */
545 /* INTEGER INFO, LDA, N */
546 /* INTEGER IPIV( * ) */
547 /* COMPLEX*16 A( LDA, * ) */
550 /* > \par Purpose: */
555 /* > ZHETF2 computes the factorization of a complex Hermitian matrix A */
556 /* > using the Bunch-Kaufman diagonal pivoting method: */
558 /* > A = U*D*U**H or A = L*D*L**H */
560 /* > where U (or L) is a product of permutation and unit upper (lower) */
561 /* > triangular matrices, U**H is the conjugate transpose of U, and D is */
562 /* > Hermitian and block diagonal with 1-by-1 and 2-by-2 diagonal blocks. */
564 /* > This is the unblocked version of the algorithm, calling Level 2 BLAS. */
570 /* > \param[in] UPLO */
572 /* > UPLO is CHARACTER*1 */
573 /* > Specifies whether the upper or lower triangular part of the */
574 /* > Hermitian matrix A is stored: */
575 /* > = 'U': Upper triangular */
576 /* > = 'L': Lower triangular */
582 /* > The order of the matrix A. N >= 0. */
585 /* > \param[in,out] A */
587 /* > A is COMPLEX*16 array, dimension (LDA,N) */
588 /* > On entry, the Hermitian matrix A. If UPLO = 'U', the leading */
589 /* > n-by-n upper triangular part of A contains the upper */
590 /* > triangular part of the matrix A, and the strictly lower */
591 /* > triangular part of A is not referenced. If UPLO = 'L', the */
592 /* > leading n-by-n lower triangular part of A contains the lower */
593 /* > triangular part of the matrix A, and the strictly upper */
594 /* > triangular part of A is not referenced. */
596 /* > On exit, the block diagonal matrix D and the multipliers used */
597 /* > to obtain the factor U or L (see below for further details). */
600 /* > \param[in] LDA */
602 /* > LDA is INTEGER */
603 /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
606 /* > \param[out] IPIV */
608 /* > IPIV is INTEGER array, dimension (N) */
609 /* > Details of the interchanges and the block structure of D. */
611 /* > If UPLO = 'U': */
612 /* > If IPIV(k) > 0, then rows and columns k and IPIV(k) were */
613 /* > interchanged and D(k,k) is a 1-by-1 diagonal block. */
615 /* > If IPIV(k) = IPIV(k-1) < 0, then rows and columns */
616 /* > k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) */
617 /* > is a 2-by-2 diagonal block. */
619 /* > If UPLO = 'L': */
620 /* > If IPIV(k) > 0, then rows and columns k and IPIV(k) were */
621 /* > interchanged and D(k,k) is a 1-by-1 diagonal block. */
623 /* > If IPIV(k) = IPIV(k+1) < 0, then rows and columns */
624 /* > k+1 and -IPIV(k) were interchanged and D(k:k+1,k:k+1) */
625 /* > is a 2-by-2 diagonal block. */
628 /* > \param[out] INFO */
630 /* > INFO is INTEGER */
631 /* > = 0: successful exit */
632 /* > < 0: if INFO = -k, the k-th argument had an illegal value */
633 /* > > 0: if INFO = k, D(k,k) is exactly zero. The factorization */
634 /* > has been completed, but the block diagonal matrix D is */
635 /* > exactly singular, and division by zero will occur if it */
636 /* > is used to solve a system of equations. */
642 /* > \author Univ. of Tennessee */
643 /* > \author Univ. of California Berkeley */
644 /* > \author Univ. of Colorado Denver */
645 /* > \author NAG Ltd. */
647 /* > \date November 2013 */
649 /* > \ingroup complex16HEcomputational */
651 /* > \par Further Details: */
652 /* ===================== */
656 /* > If UPLO = 'U', then A = U*D*U**H, where */
657 /* > U = P(n)*U(n)* ... *P(k)U(k)* ..., */
658 /* > i.e., U is a product of terms P(k)*U(k), where k decreases from n to */
659 /* > 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */
660 /* > and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */
661 /* > defined by IPIV(k), and U(k) is a unit upper triangular matrix, such */
662 /* > that if the diagonal block D(k) is of order s (s = 1 or 2), then */
664 /* > ( I v 0 ) k-s */
665 /* > U(k) = ( 0 I 0 ) s */
666 /* > ( 0 0 I ) n-k */
669 /* > If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k). */
670 /* > If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k), */
671 /* > and A(k,k), and v overwrites A(1:k-2,k-1:k). */
673 /* > If UPLO = 'L', then A = L*D*L**H, where */
674 /* > L = P(1)*L(1)* ... *P(k)*L(k)* ..., */
675 /* > i.e., L is a product of terms P(k)*L(k), where k increases from 1 to */
676 /* > n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */
677 /* > and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */
678 /* > defined by IPIV(k), and L(k) is a unit lower triangular matrix, such */
679 /* > that if the diagonal block D(k) is of order s (s = 1 or 2), then */
681 /* > ( I 0 0 ) k-1 */
682 /* > L(k) = ( 0 I 0 ) s */
683 /* > ( 0 v I ) n-k-s+1 */
684 /* > k-1 s n-k-s+1 */
686 /* > If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k). */
687 /* > If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k), */
688 /* > and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1). */
691 /* > \par Contributors: */
692 /* ================== */
695 /* > 09-29-06 - patch from */
696 /* > Bobby Cheng, MathWorks */
698 /* > Replace l.210 and l.393 */
699 /* > IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN */
701 /* > IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. DISNAN(ABSAKK) ) THEN */
703 /* > 01-01-96 - Based on modifications by */
704 /* > J. Lewis, Boeing Computer Services Company */
705 /* > A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA */
708 /* ===================================================================== */
709 /* Subroutine */ int zhetf2_(char *uplo, integer *n, doublecomplex *a,
710 integer *lda, integer *ipiv, integer *info)
712 /* System generated locals */
713 integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5, i__6;
714 doublereal d__1, d__2, d__3, d__4;
715 doublecomplex z__1, z__2, z__3, z__4, z__5, z__6;
717 /* Local variables */
719 extern /* Subroutine */ int zher_(char *, integer *, doublereal *,
720 doublecomplex *, integer *, doublecomplex *, integer *);
725 extern logical lsame_(char *, char *);
729 extern /* Subroutine */ int zswap_(integer *, doublecomplex *, integer *,
730 doublecomplex *, integer *);
731 extern doublereal dlapy2_(doublereal *, doublereal *);
740 extern logical disnan_(doublereal *);
741 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen), zdscal_(
742 integer *, doublereal *, doublecomplex *, integer *);
744 extern integer izamax_(integer *, doublecomplex *, integer *);
746 doublecomplex wkm1, wkp1;
749 /* -- LAPACK computational routine (version 3.5.0) -- */
750 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
751 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
755 /* ===================================================================== */
758 /* Test the input parameters. */
760 /* Parameter adjustments */
762 a_offset = 1 + a_dim1 * 1;
768 upper = lsame_(uplo, "U");
769 if (! upper && ! lsame_(uplo, "L")) {
773 } else if (*lda < f2cmax(1,*n)) {
778 xerbla_("ZHETF2", &i__1, (ftnlen)6);
782 /* Initialize ALPHA for use in choosing pivot block size. */
784 alpha = (sqrt(17.) + 1.) / 8.;
788 /* Factorize A as U*D*U**H using the upper triangle of A */
790 /* K is the main loop index, decreasing from N to 1 in steps of */
796 /* If K < 1, exit from loop */
803 /* Determine rows and columns to be interchanged and whether */
804 /* a 1-by-1 or 2-by-2 pivot block will be used */
806 i__1 = k + k * a_dim1;
807 absakk = (d__1 = a[i__1].r, abs(d__1));
809 /* IMAX is the row-index of the largest off-diagonal element in */
810 /* column K, and COLMAX is its absolute value. */
811 /* Determine both COLMAX and IMAX. */
815 imax = izamax_(&i__1, &a[k * a_dim1 + 1], &c__1);
816 i__1 = imax + k * a_dim1;
817 colmax = (d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&a[imax +
818 k * a_dim1]), abs(d__2));
823 if (f2cmax(absakk,colmax) == 0. || disnan_(&absakk)) {
825 /* Column K is zero or underflow, or contains a NaN: */
826 /* set INFO and continue */
832 i__1 = k + k * a_dim1;
833 i__2 = k + k * a_dim1;
835 a[i__1].r = d__1, a[i__1].i = 0.;
838 /* ============================================================ */
840 /* Test for interchange */
842 if (absakk >= alpha * colmax) {
844 /* no interchange, use 1-by-1 pivot block */
849 /* JMAX is the column-index of the largest off-diagonal */
850 /* element in row IMAX, and ROWMAX is its absolute value. */
851 /* Determine only ROWMAX. */
854 jmax = imax + izamax_(&i__1, &a[imax + (imax + 1) * a_dim1],
856 i__1 = imax + jmax * a_dim1;
857 rowmax = (d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&a[
858 imax + jmax * a_dim1]), abs(d__2));
861 jmax = izamax_(&i__1, &a[imax * a_dim1 + 1], &c__1);
863 i__1 = jmax + imax * a_dim1;
864 d__3 = rowmax, d__4 = (d__1 = a[i__1].r, abs(d__1)) + (
865 d__2 = d_imag(&a[jmax + imax * a_dim1]), abs(d__2)
867 rowmax = f2cmax(d__3,d__4);
870 if (absakk >= alpha * colmax * (colmax / rowmax)) {
872 /* no interchange, use 1-by-1 pivot block */
876 } else /* if(complicated condition) */ {
877 i__1 = imax + imax * a_dim1;
878 if ((d__1 = a[i__1].r, abs(d__1)) >= alpha * rowmax) {
880 /* interchange rows and columns K and IMAX, use 1-by-1 */
886 /* interchange rows and columns K-1 and IMAX, use 2-by-2 */
896 /* ============================================================ */
901 /* Interchange rows and columns KK and KP in the leading */
902 /* submatrix A(1:k,1:k) */
905 zswap_(&i__1, &a[kk * a_dim1 + 1], &c__1, &a[kp * a_dim1 + 1],
908 for (j = kp + 1; j <= i__1; ++j) {
909 d_cnjg(&z__1, &a[j + kk * a_dim1]);
910 t.r = z__1.r, t.i = z__1.i;
911 i__2 = j + kk * a_dim1;
912 d_cnjg(&z__1, &a[kp + j * a_dim1]);
913 a[i__2].r = z__1.r, a[i__2].i = z__1.i;
914 i__2 = kp + j * a_dim1;
915 a[i__2].r = t.r, a[i__2].i = t.i;
918 i__1 = kp + kk * a_dim1;
919 d_cnjg(&z__1, &a[kp + kk * a_dim1]);
920 a[i__1].r = z__1.r, a[i__1].i = z__1.i;
921 i__1 = kk + kk * a_dim1;
923 i__1 = kk + kk * a_dim1;
924 i__2 = kp + kp * a_dim1;
926 a[i__1].r = d__1, a[i__1].i = 0.;
927 i__1 = kp + kp * a_dim1;
928 a[i__1].r = r1, a[i__1].i = 0.;
930 i__1 = k + k * a_dim1;
931 i__2 = k + k * a_dim1;
933 a[i__1].r = d__1, a[i__1].i = 0.;
934 i__1 = k - 1 + k * a_dim1;
935 t.r = a[i__1].r, t.i = a[i__1].i;
936 i__1 = k - 1 + k * a_dim1;
937 i__2 = kp + k * a_dim1;
938 a[i__1].r = a[i__2].r, a[i__1].i = a[i__2].i;
939 i__1 = kp + k * a_dim1;
940 a[i__1].r = t.r, a[i__1].i = t.i;
943 i__1 = k + k * a_dim1;
944 i__2 = k + k * a_dim1;
946 a[i__1].r = d__1, a[i__1].i = 0.;
948 i__1 = k - 1 + (k - 1) * a_dim1;
949 i__2 = k - 1 + (k - 1) * a_dim1;
951 a[i__1].r = d__1, a[i__1].i = 0.;
955 /* Update the leading submatrix */
959 /* 1-by-1 pivot block D(k): column k now holds */
961 /* W(k) = U(k)*D(k) */
963 /* where U(k) is the k-th column of U */
965 /* Perform a rank-1 update of A(1:k-1,1:k-1) as */
967 /* A := A - U(k)*D(k)*U(k)**H = A - W(k)*1/D(k)*W(k)**H */
969 i__1 = k + k * a_dim1;
973 zher_(uplo, &i__1, &d__1, &a[k * a_dim1 + 1], &c__1, &a[
976 /* Store U(k) in column k */
979 zdscal_(&i__1, &r1, &a[k * a_dim1 + 1], &c__1);
982 /* 2-by-2 pivot block D(k): columns k and k-1 now hold */
984 /* ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k) */
986 /* where U(k) and U(k-1) are the k-th and (k-1)-th columns */
989 /* Perform a rank-2 update of A(1:k-2,1:k-2) as */
991 /* A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**H */
992 /* = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**H */
996 i__1 = k - 1 + k * a_dim1;
998 d__2 = d_imag(&a[k - 1 + k * a_dim1]);
999 d__ = dlapy2_(&d__1, &d__2);
1000 i__1 = k - 1 + (k - 1) * a_dim1;
1001 d22 = a[i__1].r / d__;
1002 i__1 = k + k * a_dim1;
1003 d11 = a[i__1].r / d__;
1004 tt = 1. / (d11 * d22 - 1.);
1005 i__1 = k - 1 + k * a_dim1;
1006 z__1.r = a[i__1].r / d__, z__1.i = a[i__1].i / d__;
1007 d12.r = z__1.r, d12.i = z__1.i;
1010 for (j = k - 2; j >= 1; --j) {
1011 i__1 = j + (k - 1) * a_dim1;
1012 z__3.r = d11 * a[i__1].r, z__3.i = d11 * a[i__1].i;
1013 d_cnjg(&z__5, &d12);
1014 i__2 = j + k * a_dim1;
1015 z__4.r = z__5.r * a[i__2].r - z__5.i * a[i__2].i,
1016 z__4.i = z__5.r * a[i__2].i + z__5.i * a[i__2]
1018 z__2.r = z__3.r - z__4.r, z__2.i = z__3.i - z__4.i;
1019 z__1.r = d__ * z__2.r, z__1.i = d__ * z__2.i;
1020 wkm1.r = z__1.r, wkm1.i = z__1.i;
1021 i__1 = j + k * a_dim1;
1022 z__3.r = d22 * a[i__1].r, z__3.i = d22 * a[i__1].i;
1023 i__2 = j + (k - 1) * a_dim1;
1024 z__4.r = d12.r * a[i__2].r - d12.i * a[i__2].i,
1025 z__4.i = d12.r * a[i__2].i + d12.i * a[i__2]
1027 z__2.r = z__3.r - z__4.r, z__2.i = z__3.i - z__4.i;
1028 z__1.r = d__ * z__2.r, z__1.i = d__ * z__2.i;
1029 wk.r = z__1.r, wk.i = z__1.i;
1030 for (i__ = j; i__ >= 1; --i__) {
1031 i__1 = i__ + j * a_dim1;
1032 i__2 = i__ + j * a_dim1;
1033 i__3 = i__ + k * a_dim1;
1035 z__3.r = a[i__3].r * z__4.r - a[i__3].i * z__4.i,
1036 z__3.i = a[i__3].r * z__4.i + a[i__3].i *
1038 z__2.r = a[i__2].r - z__3.r, z__2.i = a[i__2].i -
1040 i__4 = i__ + (k - 1) * a_dim1;
1041 d_cnjg(&z__6, &wkm1);
1042 z__5.r = a[i__4].r * z__6.r - a[i__4].i * z__6.i,
1043 z__5.i = a[i__4].r * z__6.i + a[i__4].i *
1045 z__1.r = z__2.r - z__5.r, z__1.i = z__2.i -
1047 a[i__1].r = z__1.r, a[i__1].i = z__1.i;
1050 i__1 = j + k * a_dim1;
1051 a[i__1].r = wk.r, a[i__1].i = wk.i;
1052 i__1 = j + (k - 1) * a_dim1;
1053 a[i__1].r = wkm1.r, a[i__1].i = wkm1.i;
1054 i__1 = j + j * a_dim1;
1055 i__2 = j + j * a_dim1;
1057 z__1.r = d__1, z__1.i = 0.;
1058 a[i__1].r = z__1.r, a[i__1].i = z__1.i;
1067 /* Store details of the interchanges in IPIV */
1076 /* Decrease K and return to the start of the main loop */
1083 /* Factorize A as L*D*L**H using the lower triangle of A */
1085 /* K is the main loop index, increasing from 1 to N in steps of */
1091 /* If K > N, exit from loop */
1098 /* Determine rows and columns to be interchanged and whether */
1099 /* a 1-by-1 or 2-by-2 pivot block will be used */
1101 i__1 = k + k * a_dim1;
1102 absakk = (d__1 = a[i__1].r, abs(d__1));
1104 /* IMAX is the row-index of the largest off-diagonal element in */
1105 /* column K, and COLMAX is its absolute value. */
1106 /* Determine both COLMAX and IMAX. */
1110 imax = k + izamax_(&i__1, &a[k + 1 + k * a_dim1], &c__1);
1111 i__1 = imax + k * a_dim1;
1112 colmax = (d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&a[imax +
1113 k * a_dim1]), abs(d__2));
1118 if (f2cmax(absakk,colmax) == 0. || disnan_(&absakk)) {
1120 /* Column K is zero or underflow, or contains a NaN: */
1121 /* set INFO and continue */
1127 i__1 = k + k * a_dim1;
1128 i__2 = k + k * a_dim1;
1130 a[i__1].r = d__1, a[i__1].i = 0.;
1133 /* ============================================================ */
1135 /* Test for interchange */
1137 if (absakk >= alpha * colmax) {
1139 /* no interchange, use 1-by-1 pivot block */
1144 /* JMAX is the column-index of the largest off-diagonal */
1145 /* element in row IMAX, and ROWMAX is its absolute value. */
1146 /* Determine only ROWMAX. */
1149 jmax = k - 1 + izamax_(&i__1, &a[imax + k * a_dim1], lda);
1150 i__1 = imax + jmax * a_dim1;
1151 rowmax = (d__1 = a[i__1].r, abs(d__1)) + (d__2 = d_imag(&a[
1152 imax + jmax * a_dim1]), abs(d__2));
1155 jmax = imax + izamax_(&i__1, &a[imax + 1 + imax * a_dim1],
1158 i__1 = jmax + imax * a_dim1;
1159 d__3 = rowmax, d__4 = (d__1 = a[i__1].r, abs(d__1)) + (
1160 d__2 = d_imag(&a[jmax + imax * a_dim1]), abs(d__2)
1162 rowmax = f2cmax(d__3,d__4);
1165 if (absakk >= alpha * colmax * (colmax / rowmax)) {
1167 /* no interchange, use 1-by-1 pivot block */
1171 } else /* if(complicated condition) */ {
1172 i__1 = imax + imax * a_dim1;
1173 if ((d__1 = a[i__1].r, abs(d__1)) >= alpha * rowmax) {
1175 /* interchange rows and columns K and IMAX, use 1-by-1 */
1181 /* interchange rows and columns K+1 and IMAX, use 2-by-2 */
1191 /* ============================================================ */
1196 /* Interchange rows and columns KK and KP in the trailing */
1197 /* submatrix A(k:n,k:n) */
1201 zswap_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + 1
1202 + kp * a_dim1], &c__1);
1205 for (j = kk + 1; j <= i__1; ++j) {
1206 d_cnjg(&z__1, &a[j + kk * a_dim1]);
1207 t.r = z__1.r, t.i = z__1.i;
1208 i__2 = j + kk * a_dim1;
1209 d_cnjg(&z__1, &a[kp + j * a_dim1]);
1210 a[i__2].r = z__1.r, a[i__2].i = z__1.i;
1211 i__2 = kp + j * a_dim1;
1212 a[i__2].r = t.r, a[i__2].i = t.i;
1215 i__1 = kp + kk * a_dim1;
1216 d_cnjg(&z__1, &a[kp + kk * a_dim1]);
1217 a[i__1].r = z__1.r, a[i__1].i = z__1.i;
1218 i__1 = kk + kk * a_dim1;
1220 i__1 = kk + kk * a_dim1;
1221 i__2 = kp + kp * a_dim1;
1223 a[i__1].r = d__1, a[i__1].i = 0.;
1224 i__1 = kp + kp * a_dim1;
1225 a[i__1].r = r1, a[i__1].i = 0.;
1227 i__1 = k + k * a_dim1;
1228 i__2 = k + k * a_dim1;
1230 a[i__1].r = d__1, a[i__1].i = 0.;
1231 i__1 = k + 1 + k * a_dim1;
1232 t.r = a[i__1].r, t.i = a[i__1].i;
1233 i__1 = k + 1 + k * a_dim1;
1234 i__2 = kp + k * a_dim1;
1235 a[i__1].r = a[i__2].r, a[i__1].i = a[i__2].i;
1236 i__1 = kp + k * a_dim1;
1237 a[i__1].r = t.r, a[i__1].i = t.i;
1240 i__1 = k + k * a_dim1;
1241 i__2 = k + k * a_dim1;
1243 a[i__1].r = d__1, a[i__1].i = 0.;
1245 i__1 = k + 1 + (k + 1) * a_dim1;
1246 i__2 = k + 1 + (k + 1) * a_dim1;
1248 a[i__1].r = d__1, a[i__1].i = 0.;
1252 /* Update the trailing submatrix */
1256 /* 1-by-1 pivot block D(k): column k now holds */
1258 /* W(k) = L(k)*D(k) */
1260 /* where L(k) is the k-th column of L */
1264 /* Perform a rank-1 update of A(k+1:n,k+1:n) as */
1266 /* A := A - L(k)*D(k)*L(k)**H = A - W(k)*(1/D(k))*W(k)**H */
1268 i__1 = k + k * a_dim1;
1269 r1 = 1. / a[i__1].r;
1272 zher_(uplo, &i__1, &d__1, &a[k + 1 + k * a_dim1], &c__1, &
1273 a[k + 1 + (k + 1) * a_dim1], lda);
1275 /* Store L(k) in column K */
1278 zdscal_(&i__1, &r1, &a[k + 1 + k * a_dim1], &c__1);
1282 /* 2-by-2 pivot block D(k) */
1286 /* Perform a rank-2 update of A(k+2:n,k+2:n) as */
1288 /* A := A - ( L(k) L(k+1) )*D(k)*( L(k) L(k+1) )**H */
1289 /* = A - ( W(k) W(k+1) )*inv(D(k))*( W(k) W(k+1) )**H */
1291 /* where L(k) and L(k+1) are the k-th and (k+1)-th */
1294 i__1 = k + 1 + k * a_dim1;
1296 d__2 = d_imag(&a[k + 1 + k * a_dim1]);
1297 d__ = dlapy2_(&d__1, &d__2);
1298 i__1 = k + 1 + (k + 1) * a_dim1;
1299 d11 = a[i__1].r / d__;
1300 i__1 = k + k * a_dim1;
1301 d22 = a[i__1].r / d__;
1302 tt = 1. / (d11 * d22 - 1.);
1303 i__1 = k + 1 + k * a_dim1;
1304 z__1.r = a[i__1].r / d__, z__1.i = a[i__1].i / d__;
1305 d21.r = z__1.r, d21.i = z__1.i;
1309 for (j = k + 2; j <= i__1; ++j) {
1310 i__2 = j + k * a_dim1;
1311 z__3.r = d11 * a[i__2].r, z__3.i = d11 * a[i__2].i;
1312 i__3 = j + (k + 1) * a_dim1;
1313 z__4.r = d21.r * a[i__3].r - d21.i * a[i__3].i,
1314 z__4.i = d21.r * a[i__3].i + d21.i * a[i__3]
1316 z__2.r = z__3.r - z__4.r, z__2.i = z__3.i - z__4.i;
1317 z__1.r = d__ * z__2.r, z__1.i = d__ * z__2.i;
1318 wk.r = z__1.r, wk.i = z__1.i;
1319 i__2 = j + (k + 1) * a_dim1;
1320 z__3.r = d22 * a[i__2].r, z__3.i = d22 * a[i__2].i;
1321 d_cnjg(&z__5, &d21);
1322 i__3 = j + k * a_dim1;
1323 z__4.r = z__5.r * a[i__3].r - z__5.i * a[i__3].i,
1324 z__4.i = z__5.r * a[i__3].i + z__5.i * a[i__3]
1326 z__2.r = z__3.r - z__4.r, z__2.i = z__3.i - z__4.i;
1327 z__1.r = d__ * z__2.r, z__1.i = d__ * z__2.i;
1328 wkp1.r = z__1.r, wkp1.i = z__1.i;
1330 for (i__ = j; i__ <= i__2; ++i__) {
1331 i__3 = i__ + j * a_dim1;
1332 i__4 = i__ + j * a_dim1;
1333 i__5 = i__ + k * a_dim1;
1335 z__3.r = a[i__5].r * z__4.r - a[i__5].i * z__4.i,
1336 z__3.i = a[i__5].r * z__4.i + a[i__5].i *
1338 z__2.r = a[i__4].r - z__3.r, z__2.i = a[i__4].i -
1340 i__6 = i__ + (k + 1) * a_dim1;
1341 d_cnjg(&z__6, &wkp1);
1342 z__5.r = a[i__6].r * z__6.r - a[i__6].i * z__6.i,
1343 z__5.i = a[i__6].r * z__6.i + a[i__6].i *
1345 z__1.r = z__2.r - z__5.r, z__1.i = z__2.i -
1347 a[i__3].r = z__1.r, a[i__3].i = z__1.i;
1350 i__2 = j + k * a_dim1;
1351 a[i__2].r = wk.r, a[i__2].i = wk.i;
1352 i__2 = j + (k + 1) * a_dim1;
1353 a[i__2].r = wkp1.r, a[i__2].i = wkp1.i;
1354 i__2 = j + j * a_dim1;
1355 i__3 = j + j * a_dim1;
1357 z__1.r = d__1, z__1.i = 0.;
1358 a[i__2].r = z__1.r, a[i__2].i = z__1.i;
1365 /* Store details of the interchanges in IPIV */
1374 /* Increase K and return to the start of the main loop */