~ubuntu-branches/ubuntu/trusty/igraph/trusty-proposed

« back to all changes in this revision

Viewing changes to src/lapack/dlahqr.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Malaterre
  • Date: 2013-05-27 14:01:54 UTC
  • mfrom: (4.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130527140154-oxwwmr0gj3kdy4ol
Tags: 0.6.5-2
Upload to sid

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  -- translated by f2c (version 20050501).
 
1
/*  -- translated by f2c (version 20100827).
2
2
   You must link the resulting object file with libf2c:
3
3
        on Microsoft Windows system, link with libf2c.lib;
4
4
        on Linux or Unix systems, link with .../path/to/libf2c.a -lm
10
10
                http://www.netlib.org/f2c/libf2c.zip
11
11
*/
12
12
 
13
 
#include "config.h"
14
 
#include "arpack_internal.h"
15
13
#include "f2c.h"
16
14
 
17
15
/* Table of constant values */
24
22
        integer *ldz, integer *info)
25
23
{
26
24
    /* System generated locals */
27
 
    integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4;
28
 
    doublereal d__1, d__2;
 
25
    integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3;
 
26
    doublereal d__1, d__2, d__3, d__4;
29
27
 
30
28
    /* Builtin functions */
31
 
    double sqrt(doublereal), igraphd_sign(doublereal *, doublereal *);
 
29
    double sqrt(doublereal);
32
30
 
33
31
    /* Local variables */
34
 
    static integer i__, j, k, l, m;
35
 
    static doublereal s, v[3];
36
 
    static integer i1, i2;
37
 
    static doublereal t1, t2, t3, v1, v2, v3, h00, h10, h11, h12, h21, h22, 
38
 
            h33, h44;
39
 
    static integer nh;
40
 
    static doublereal cs;
41
 
    static integer nr;
42
 
    static doublereal sn;
43
 
    static integer nz;
44
 
    static doublereal ave, h33s, h44s;
45
 
    static integer itn, its;
46
 
    static doublereal ulp, sum, tst1, h43h34, disc, unfl, ovfl;
 
32
    integer i__, j, k, l, m;
 
33
    doublereal s, v[3];
 
34
    integer i1, i2;
 
35
    doublereal t1, t2, t3, v2, v3, aa, ab, ba, bb, h11, h12, h21, h22, cs;
 
36
    integer nh;
 
37
    doublereal sn;
 
38
    integer nr;
 
39
    doublereal tr;
 
40
    integer nz;
 
41
    doublereal det, h21s;
 
42
    integer its;
 
43
    doublereal ulp, sum, tst, rt1i, rt2i, rt1r, rt2r;
47
44
    extern /* Subroutine */ int igraphdrot_(integer *, doublereal *, integer *, 
48
 
            doublereal *, integer *, doublereal *, doublereal *);
49
 
    static doublereal work[1];
50
 
    extern /* Subroutine */ int igraphdcopy_(integer *, doublereal *, integer *, 
51
 
            doublereal *, integer *), igraphdlanv2_(doublereal *, doublereal *, 
 
45
            doublereal *, integer *, doublereal *, doublereal *), igraphdcopy_(
 
46
            integer *, doublereal *, integer *, doublereal *, integer *), 
 
47
            igraphdlanv2_(doublereal *, doublereal *, doublereal *, doublereal *, 
52
48
            doublereal *, doublereal *, doublereal *, doublereal *, 
53
 
            doublereal *, doublereal *, doublereal *, doublereal *), igraphdlabad_(
54
 
            doublereal *, doublereal *);
 
49
            doublereal *, doublereal *), igraphdlabad_(doublereal *, doublereal *);
55
50
    extern doublereal igraphdlamch_(char *);
56
51
    extern /* Subroutine */ int igraphdlarfg_(integer *, doublereal *, doublereal *,
57
52
             integer *, doublereal *);
58
 
    extern doublereal igraphdlanhs_(char *, integer *, doublereal *, integer *, 
59
 
            doublereal *);
60
 
    static doublereal smlnum;
61
 
 
62
 
 
63
 
/*  -- LAPACK auxiliary routine (version 3.0) -- */
64
 
/*     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */
65
 
/*     Courant Institute, Argonne National Lab, and Rice University */
66
 
/*     June 30, 1999 */
67
 
 
68
 
/*     .. Scalar Arguments .. */
69
 
/*     .. */
70
 
/*     .. Array Arguments .. */
71
 
/*     .. */
72
 
 
73
 
/*  Purpose */
74
 
/*  ======= */
75
 
 
76
 
/*  DLAHQR is an auxiliary routine called by DHSEQR to update the */
77
 
/*  eigenvalues and Schur decomposition already computed by DHSEQR, by */
78
 
/*  dealing with the Hessenberg submatrix in rows and columns ILO to IHI. */
79
 
 
80
 
/*  Arguments */
81
 
/*  ========= */
82
 
 
83
 
/*  WANTT   (input) LOGICAL */
84
 
/*          = .TRUE. : the full Schur form T is required; */
85
 
/*          = .FALSE.: only eigenvalues are required. */
86
 
 
87
 
/*  WANTZ   (input) LOGICAL */
88
 
/*          = .TRUE. : the matrix of Schur vectors Z is required; */
89
 
/*          = .FALSE.: Schur vectors are not required. */
90
 
 
91
 
/*  N       (input) INTEGER */
92
 
/*          The order of the matrix H.  N >= 0. */
93
 
 
94
 
/*  ILO     (input) INTEGER */
95
 
/*  IHI     (input) INTEGER */
96
 
/*          It is assumed that H is already upper quasi-triangular in */
97
 
/*          rows and columns IHI+1:N, and that H(ILO,ILO-1) = 0 (unless */
98
 
/*          ILO = 1). DLAHQR works primarily with the Hessenberg */
99
 
/*          submatrix in rows and columns ILO to IHI, but applies */
100
 
/*          transformations to all of H if WANTT is .TRUE.. */
101
 
/*          1 <= ILO <= max(1,IHI); IHI <= N. */
102
 
 
103
 
/*  H       (input/output) DOUBLE PRECISION array, dimension (LDH,N) */
104
 
/*          On entry, the upper Hessenberg matrix H. */
105
 
/*          On exit, if WANTT is .TRUE., H is upper quasi-triangular in */
106
 
/*          rows and columns ILO:IHI, with any 2-by-2 diagonal blocks in */
107
 
/*          standard form. If WANTT is .FALSE., the contents of H are */
108
 
/*          unspecified on exit. */
109
 
 
110
 
/*  LDH     (input) INTEGER */
111
 
/*          The leading dimension of the array H. LDH >= max(1,N). */
112
 
 
113
 
/*  WR      (output) DOUBLE PRECISION array, dimension (N) */
114
 
/*  WI      (output) DOUBLE PRECISION array, dimension (N) */
115
 
/*          The real and imaginary parts, respectively, of the computed */
116
 
/*          eigenvalues ILO to IHI are stored in the corresponding */
117
 
/*          elements of WR and WI. If two eigenvalues are computed as a */
118
 
/*          complex conjugate pair, they are stored in consecutive */
119
 
/*          elements of WR and WI, say the i-th and (i+1)th, with */
120
 
/*          WI(i) > 0 and WI(i+1) < 0. If WANTT is .TRUE., the */
121
 
/*          eigenvalues are stored in the same order as on the diagonal */
122
 
/*          of the Schur form returned in H, with WR(i) = H(i,i), and, if */
123
 
/*          H(i:i+1,i:i+1) is a 2-by-2 diagonal block, */
124
 
/*          WI(i) = sqrt(H(i+1,i)*H(i,i+1)) and WI(i+1) = -WI(i). */
125
 
 
126
 
/*  ILOZ    (input) INTEGER */
127
 
/*  IHIZ    (input) INTEGER */
128
 
/*          Specify the rows of Z to which transformations must be */
129
 
/*          applied if WANTZ is .TRUE.. */
130
 
/*          1 <= ILOZ <= ILO; IHI <= IHIZ <= N. */
131
 
 
132
 
/*  Z       (input/output) DOUBLE PRECISION array, dimension (LDZ,N) */
133
 
/*          If WANTZ is .TRUE., on entry Z must contain the current */
134
 
/*          matrix Z of transformations accumulated by DHSEQR, and on */
135
 
/*          exit Z has been updated; transformations are applied only to */
136
 
/*          the submatrix Z(ILOZ:IHIZ,ILO:IHI). */
137
 
/*          If WANTZ is .FALSE., Z is not referenced. */
138
 
 
139
 
/*  LDZ     (input) INTEGER */
140
 
/*          The leading dimension of the array Z. LDZ >= max(1,N). */
141
 
 
142
 
/*  INFO    (output) INTEGER */
143
 
/*          = 0: successful exit */
144
 
/*          > 0: DLAHQR failed to compute all the eigenvalues ILO to IHI */
145
 
/*               in a total of 30*(IHI-ILO+1) iterations; if INFO = i, */
146
 
/*               elements i+1:ihi of WR and WI contain those eigenvalues */
147
 
/*               which have been successfully computed. */
148
 
 
149
 
/*  Further Details */
150
 
/*  =============== */
151
 
 
152
 
/*  2-96 Based on modifications by */
153
 
/*     David Day, Sandia National Laboratory, USA */
154
 
 
155
 
/*  ===================================================================== */
156
 
 
157
 
/*     .. Parameters .. */
158
 
/*     .. */
159
 
/*     .. Local Scalars .. */
160
 
/*     .. */
161
 
/*     .. Local Arrays .. */
162
 
/*     .. */
163
 
/*     .. External Functions .. */
164
 
/*     .. */
165
 
/*     .. External Subroutines .. */
166
 
/*     .. */
167
 
/*     .. Intrinsic Functions .. */
168
 
/*     .. */
169
 
/*     .. Executable Statements .. */
170
 
 
171
 
    /* Parameter adjustments */
 
53
    doublereal safmin, safmax, rtdisc, smlnum;
 
54
 
 
55
 
 
56
/*  -- LAPACK auxiliary routine (version 3.2) --   
 
57
       Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..   
 
58
       November 2006   
 
59
 
 
60
 
 
61
       Purpose   
 
62
       =======   
 
63
 
 
64
       DLAHQR is an auxiliary routine called by DHSEQR to update the   
 
65
       eigenvalues and Schur decomposition already computed by DHSEQR, by   
 
66
       dealing with the Hessenberg submatrix in rows and columns ILO to   
 
67
       IHI.   
 
68
 
 
69
       Arguments   
 
70
       =========   
 
71
 
 
72
       WANTT   (input) LOGICAL   
 
73
            = .TRUE. : the full Schur form T is required;   
 
74
            = .FALSE.: only eigenvalues are required.   
 
75
 
 
76
       WANTZ   (input) LOGICAL   
 
77
            = .TRUE. : the matrix of Schur vectors Z is required;   
 
78
            = .FALSE.: Schur vectors are not required.   
 
79
 
 
80
       N       (input) INTEGER   
 
81
            The order of the matrix H.  N >= 0.   
 
82
 
 
83
       ILO     (input) INTEGER   
 
84
       IHI     (input) INTEGER   
 
85
            It is assumed that H is already upper quasi-triangular in   
 
86
            rows and columns IHI+1:N, and that H(ILO,ILO-1) = 0 (unless   
 
87
            ILO = 1). DLAHQR works primarily with the Hessenberg   
 
88
            submatrix in rows and columns ILO to IHI, but applies   
 
89
            transformations to all of H if WANTT is .TRUE..   
 
90
            1 <= ILO <= max(1,IHI); IHI <= N.   
 
91
 
 
92
       H       (input/output) DOUBLE PRECISION array, dimension (LDH,N)   
 
93
            On entry, the upper Hessenberg matrix H.   
 
94
            On exit, if INFO is zero and if WANTT is .TRUE., H is upper   
 
95
            quasi-triangular in rows and columns ILO:IHI, with any   
 
96
            2-by-2 diagonal blocks in standard form. If INFO is zero   
 
97
            and WANTT is .FALSE., the contents of H are unspecified on   
 
98
            exit.  The output state of H if INFO is nonzero is given   
 
99
            below under the description of INFO.   
 
100
 
 
101
       LDH     (input) INTEGER   
 
102
            The leading dimension of the array H. LDH >= max(1,N).   
 
103
 
 
104
       WR      (output) DOUBLE PRECISION array, dimension (N)   
 
105
       WI      (output) DOUBLE PRECISION array, dimension (N)   
 
106
            The real and imaginary parts, respectively, of the computed   
 
107
            eigenvalues ILO to IHI are stored in the corresponding   
 
108
            elements of WR and WI. If two eigenvalues are computed as a   
 
109
            complex conjugate pair, they are stored in consecutive   
 
110
            elements of WR and WI, say the i-th and (i+1)th, with   
 
111
            WI(i) > 0 and WI(i+1) < 0. If WANTT is .TRUE., the   
 
112
            eigenvalues are stored in the same order as on the diagonal   
 
113
            of the Schur form returned in H, with WR(i) = H(i,i), and, if   
 
114
            H(i:i+1,i:i+1) is a 2-by-2 diagonal block,   
 
115
            WI(i) = sqrt(H(i+1,i)*H(i,i+1)) and WI(i+1) = -WI(i).   
 
116
 
 
117
       ILOZ    (input) INTEGER   
 
118
       IHIZ    (input) INTEGER   
 
119
            Specify the rows of Z to which transformations must be   
 
120
            applied if WANTZ is .TRUE..   
 
121
            1 <= ILOZ <= ILO; IHI <= IHIZ <= N.   
 
122
 
 
123
       Z       (input/output) DOUBLE PRECISION array, dimension (LDZ,N)   
 
124
            If WANTZ is .TRUE., on entry Z must contain the current   
 
125
            matrix Z of transformations accumulated by DHSEQR, and on   
 
126
            exit Z has been updated; transformations are applied only to   
 
127
            the submatrix Z(ILOZ:IHIZ,ILO:IHI).   
 
128
            If WANTZ is .FALSE., Z is not referenced.   
 
129
 
 
130
       LDZ     (input) INTEGER   
 
131
            The leading dimension of the array Z. LDZ >= max(1,N).   
 
132
 
 
133
       INFO    (output) INTEGER   
 
134
             =   0: successful exit   
 
135
            .GT. 0: If INFO = i, DLAHQR failed to compute all the   
 
136
                    eigenvalues ILO to IHI in a total of 30 iterations   
 
137
                    per eigenvalue; elements i+1:ihi of WR and WI   
 
138
                    contain those eigenvalues which have been   
 
139
                    successfully computed.   
 
140
 
 
141
                    If INFO .GT. 0 and WANTT is .FALSE., then on exit,   
 
142
                    the remaining unconverged eigenvalues are the   
 
143
                    eigenvalues of the upper Hessenberg matrix rows   
 
144
                    and columns ILO thorugh INFO of the final, output   
 
145
                    value of H.   
 
146
 
 
147
                    If INFO .GT. 0 and WANTT is .TRUE., then on exit   
 
148
            (*)       (initial value of H)*U  = U*(final value of H)   
 
149
                    where U is an orthognal matrix.    The final   
 
150
                    value of H is upper Hessenberg and triangular in   
 
151
                    rows and columns INFO+1 through IHI.   
 
152
 
 
153
                    If INFO .GT. 0 and WANTZ is .TRUE., then on exit   
 
154
                        (final value of Z)  = (initial value of Z)*U   
 
155
                    where U is the orthogonal matrix in (*)   
 
156
                    (regardless of the value of WANTT.)   
 
157
 
 
158
       Further Details   
 
159
       ===============   
 
160
 
 
161
       02-96 Based on modifications by   
 
162
       David Day, Sandia National Laboratory, USA   
 
163
 
 
164
       12-04 Further modifications by   
 
165
       Ralph Byers, University of Kansas, USA   
 
166
       This is a modified version of DLAHQR from LAPACK version 3.0.   
 
167
       It is (1) more robust against overflow and underflow and   
 
168
       (2) adopts the more conservative Ahues & Tisseur stopping   
 
169
       criterion (LAWN 122, 1997).   
 
170
 
 
171
       =========================================================   
 
172
 
 
173
 
 
174
       Parameter adjustments */
172
175
    h_dim1 = *ldh;
173
176
    h_offset = 1 + h_dim1;
174
177
    h__ -= h_offset;
192
195
        return 0;
193
196
    }
194
197
 
 
198
/*     ==== clear out the trash ==== */
 
199
    i__1 = *ihi - 3;
 
200
    for (j = *ilo; j <= i__1; ++j) {
 
201
        h__[j + 2 + j * h_dim1] = 0.;
 
202
        h__[j + 3 + j * h_dim1] = 0.;
 
203
/* L10: */
 
204
    }
 
205
    if (*ilo <= *ihi - 2) {
 
206
        h__[*ihi + (*ihi - 2) * h_dim1] = 0.;
 
207
    }
 
208
 
195
209
    nh = *ihi - *ilo + 1;
196
210
    nz = *ihiz - *iloz + 1;
197
211
 
198
212
/*     Set machine-dependent constants for the stopping criterion. */
199
 
/*     If norm(H) <= sqrt(OVFL), overflow should not occur. */
200
 
 
201
 
    unfl = igraphdlamch_("Safe minimum");
202
 
    ovfl = 1. / unfl;
203
 
    igraphdlabad_(&unfl, &ovfl);
204
 
    ulp = igraphdlamch_("Precision");
205
 
    smlnum = unfl * (nh / ulp);
206
 
 
207
 
/*     I1 and I2 are the indices of the first row and last column of H */
208
 
/*     to which transformations must be applied. If eigenvalues only are */
209
 
/*     being computed, I1 and I2 are set inside the main loop. */
 
213
 
 
214
    safmin = igraphdlamch_("SAFE MINIMUM");
 
215
    safmax = 1. / safmin;
 
216
    igraphdlabad_(&safmin, &safmax);
 
217
    ulp = igraphdlamch_("PRECISION");
 
218
    smlnum = safmin * ((doublereal) nh / ulp);
 
219
 
 
220
/*     I1 and I2 are the indices of the first row and last column of H   
 
221
       to which transformations must be applied. If eigenvalues only are   
 
222
       being computed, I1 and I2 are set inside the main loop. */
210
223
 
211
224
    if (*wantt) {
212
225
        i1 = 1;
213
226
        i2 = *n;
214
227
    }
215
228
 
216
 
/*     ITN is the total number of QR iterations allowed. */
217
 
 
218
 
    itn = nh * 30;
219
 
 
220
 
/*     The main loop begins here. I is the loop index and decreases from */
221
 
/*     IHI to ILO in steps of 1 or 2. Each iteration of the loop works */
222
 
/*     with the active submatrix in rows and columns L to I. */
223
 
/*     Eigenvalues I+1 to IHI have already converged. Either L = ILO or */
224
 
/*     H(L,L-1) is negligible so that the matrix splits. */
 
229
/*     The main loop begins here. I is the loop index and decreases from   
 
230
       IHI to ILO in steps of 1 or 2. Each iteration of the loop works   
 
231
       with the active submatrix in rows and columns L to I.   
 
232
       Eigenvalues I+1 to IHI have already converged. Either L = ILO or   
 
233
       H(L,L-1) is negligible so that the matrix splits. */
225
234
 
226
235
    i__ = *ihi;
227
 
L10:
 
236
L20:
228
237
    l = *ilo;
229
238
    if (i__ < *ilo) {
230
 
        goto L150;
 
239
        goto L160;
231
240
    }
232
241
 
233
 
/*     Perform QR iterations on rows and columns ILO to I until a */
234
 
/*     submatrix of order 1 or 2 splits off at the bottom because a */
235
 
/*     subdiagonal element has become negligible. */
 
242
/*     Perform QR iterations on rows and columns ILO to I until a   
 
243
       submatrix of order 1 or 2 splits off at the bottom because a   
 
244
       subdiagonal element has become negligible. */
236
245
 
237
 
    i__1 = itn;
238
 
    for (its = 0; its <= i__1; ++its) {
 
246
    for (its = 0; its <= 30; ++its) {
239
247
 
240
248
/*        Look for a single small subdiagonal element. */
241
249
 
242
 
        i__2 = l + 1;
243
 
        for (k = i__; k >= i__2; --k) {
244
 
            tst1 = (d__1 = h__[k - 1 + (k - 1) * h_dim1], abs(d__1)) + (d__2 =
245
 
                     h__[k + k * h_dim1], abs(d__2));
246
 
            if (tst1 == 0.) {
247
 
                i__3 = i__ - l + 1;
248
 
                tst1 = igraphdlanhs_("1", &i__3, &h__[l + l * h_dim1], ldh, work);
249
 
            }
250
 
/* Computing MAX */
251
 
            d__2 = ulp * tst1;
252
 
            if ((d__1 = h__[k + (k - 1) * h_dim1], abs(d__1)) <= max(d__2,
253
 
                    smlnum)) {
254
 
                goto L30;
255
 
            }
256
 
/* L20: */
 
250
        i__1 = l + 1;
 
251
        for (k = i__; k >= i__1; --k) {
 
252
            if ((d__1 = h__[k + (k - 1) * h_dim1], abs(d__1)) <= smlnum) {
 
253
                goto L40;
 
254
            }
 
255
            tst = (d__1 = h__[k - 1 + (k - 1) * h_dim1], abs(d__1)) + (d__2 = 
 
256
                    h__[k + k * h_dim1], abs(d__2));
 
257
            if (tst == 0.) {
 
258
                if (k - 2 >= *ilo) {
 
259
                    tst += (d__1 = h__[k - 1 + (k - 2) * h_dim1], abs(d__1));
 
260
                }
 
261
                if (k + 1 <= *ihi) {
 
262
                    tst += (d__1 = h__[k + 1 + k * h_dim1], abs(d__1));
 
263
                }
 
264
            }
 
265
/*           ==== The following is a conservative small subdiagonal   
 
266
             .    deflation  criterion due to Ahues & Tisseur (LAWN 122,   
 
267
             .    1997). It has better mathematical foundation and   
 
268
             .    improves accuracy in some cases.  ==== */
 
269
            if ((d__1 = h__[k + (k - 1) * h_dim1], abs(d__1)) <= ulp * tst) {
 
270
/* Computing MAX */
 
271
                d__3 = (d__1 = h__[k + (k - 1) * h_dim1], abs(d__1)), d__4 = (
 
272
                        d__2 = h__[k - 1 + k * h_dim1], abs(d__2));
 
273
                ab = max(d__3,d__4);
 
274
/* Computing MIN */
 
275
                d__3 = (d__1 = h__[k + (k - 1) * h_dim1], abs(d__1)), d__4 = (
 
276
                        d__2 = h__[k - 1 + k * h_dim1], abs(d__2));
 
277
                ba = min(d__3,d__4);
 
278
/* Computing MAX */
 
279
                d__3 = (d__1 = h__[k + k * h_dim1], abs(d__1)), d__4 = (d__2 =
 
280
                         h__[k - 1 + (k - 1) * h_dim1] - h__[k + k * h_dim1], 
 
281
                        abs(d__2));
 
282
                aa = max(d__3,d__4);
 
283
/* Computing MIN */
 
284
                d__3 = (d__1 = h__[k + k * h_dim1], abs(d__1)), d__4 = (d__2 =
 
285
                         h__[k - 1 + (k - 1) * h_dim1] - h__[k + k * h_dim1], 
 
286
                        abs(d__2));
 
287
                bb = min(d__3,d__4);
 
288
                s = aa + ab;
 
289
/* Computing MAX */
 
290
                d__1 = smlnum, d__2 = ulp * (bb * (aa / s));
 
291
                if (ba * (ab / s) <= max(d__1,d__2)) {
 
292
                    goto L40;
 
293
                }
 
294
            }
 
295
/* L30: */
257
296
        }
258
 
L30:
 
297
L40:
259
298
        l = k;
260
299
        if (l > *ilo) {
261
300
 
267
306
/*        Exit from loop if a submatrix of order 1 or 2 has split off. */
268
307
 
269
308
        if (l >= i__ - 1) {
270
 
            goto L140;
 
309
            goto L150;
271
310
        }
272
311
 
273
 
/*        Now the active submatrix is in rows and columns L to I. If */
274
 
/*        eigenvalues only are being computed, only the active submatrix */
275
 
/*        need be transformed. */
 
312
/*        Now the active submatrix is in rows and columns L to I. If   
 
313
          eigenvalues only are being computed, only the active submatrix   
 
314
          need be transformed. */
276
315
 
277
316
        if (! (*wantt)) {
278
317
            i1 = l;
279
318
            i2 = i__;
280
319
        }
281
320
 
282
 
        if (its == 10 || its == 20) {
 
321
        if (its == 10) {
 
322
 
 
323
/*           Exceptional shift. */
 
324
 
 
325
            s = (d__1 = h__[l + 1 + l * h_dim1], abs(d__1)) + (d__2 = h__[l + 
 
326
                    2 + (l + 1) * h_dim1], abs(d__2));
 
327
            h11 = s * .75 + h__[l + l * h_dim1];
 
328
            h12 = s * -.4375;
 
329
            h21 = s;
 
330
            h22 = h11;
 
331
        } else if (its == 20) {
283
332
 
284
333
/*           Exceptional shift. */
285
334
 
286
335
            s = (d__1 = h__[i__ + (i__ - 1) * h_dim1], abs(d__1)) + (d__2 = 
287
336
                    h__[i__ - 1 + (i__ - 2) * h_dim1], abs(d__2));
288
 
            h44 = s * .75 + h__[i__ + i__ * h_dim1];
289
 
            h33 = h44;
290
 
            h43h34 = s * -.4375 * s;
291
 
        } else {
292
 
 
293
 
/*           Prepare to use Francis' double shift */
294
 
/*           (i.e. 2nd degree generalized Rayleigh quotient) */
295
 
 
296
 
            h44 = h__[i__ + i__ * h_dim1];
297
 
            h33 = h__[i__ - 1 + (i__ - 1) * h_dim1];
298
 
            h43h34 = h__[i__ + (i__ - 1) * h_dim1] * h__[i__ - 1 + i__ * 
299
 
                    h_dim1];
300
 
            s = h__[i__ - 1 + (i__ - 2) * h_dim1] * h__[i__ - 1 + (i__ - 2) * 
301
 
                    h_dim1];
302
 
            disc = (h33 - h44) * .5;
303
 
            disc = disc * disc + h43h34;
304
 
            if (disc > 0.) {
305
 
 
306
 
/*              Real roots: use Wilkinson's shift twice */
307
 
 
308
 
                disc = sqrt(disc);
309
 
                ave = (h33 + h44) * .5;
310
 
                if (abs(h33) - abs(h44) > 0.) {
311
 
                    h33 = h33 * h44 - h43h34;
312
 
                    h44 = h33 / (igraphd_sign(&disc, &ave) + ave);
 
337
            h11 = s * .75 + h__[i__ + i__ * h_dim1];
 
338
            h12 = s * -.4375;
 
339
            h21 = s;
 
340
            h22 = h11;
 
341
        } else {
 
342
 
 
343
/*           Prepare to use Francis' double shift   
 
344
             (i.e. 2nd degree generalized Rayleigh quotient) */
 
345
 
 
346
            h11 = h__[i__ - 1 + (i__ - 1) * h_dim1];
 
347
            h21 = h__[i__ + (i__ - 1) * h_dim1];
 
348
            h12 = h__[i__ - 1 + i__ * h_dim1];
 
349
            h22 = h__[i__ + i__ * h_dim1];
 
350
        }
 
351
        s = abs(h11) + abs(h12) + abs(h21) + abs(h22);
 
352
        if (s == 0.) {
 
353
            rt1r = 0.;
 
354
            rt1i = 0.;
 
355
            rt2r = 0.;
 
356
            rt2i = 0.;
 
357
        } else {
 
358
            h11 /= s;
 
359
            h21 /= s;
 
360
            h12 /= s;
 
361
            h22 /= s;
 
362
            tr = (h11 + h22) / 2.;
 
363
            det = (h11 - tr) * (h22 - tr) - h12 * h21;
 
364
            rtdisc = sqrt((abs(det)));
 
365
            if (det >= 0.) {
 
366
 
 
367
/*              ==== complex conjugate shifts ==== */
 
368
 
 
369
                rt1r = tr * s;
 
370
                rt2r = rt1r;
 
371
                rt1i = rtdisc * s;
 
372
                rt2i = -rt1i;
 
373
            } else {
 
374
 
 
375
/*              ==== real shifts (use only one of them)  ==== */
 
376
 
 
377
                rt1r = tr + rtdisc;
 
378
                rt2r = tr - rtdisc;
 
379
                if ((d__1 = rt1r - h22, abs(d__1)) <= (d__2 = rt2r - h22, abs(
 
380
                        d__2))) {
 
381
                    rt1r *= s;
 
382
                    rt2r = rt1r;
313
383
                } else {
314
 
                    h44 = igraphd_sign(&disc, &ave) + ave;
 
384
                    rt2r *= s;
 
385
                    rt1r = rt2r;
315
386
                }
316
 
                h33 = h44;
317
 
                h43h34 = 0.;
 
387
                rt1i = 0.;
 
388
                rt2i = 0.;
318
389
            }
319
390
        }
320
391
 
321
392
/*        Look for two consecutive small subdiagonal elements. */
322
393
 
323
 
        i__2 = l;
324
 
        for (m = i__ - 2; m >= i__2; --m) {
325
 
/*           Determine the effect of starting the double-shift QR */
326
 
/*           iteration at row M, and see if this would make H(M,M-1) */
327
 
/*           negligible. */
 
394
        i__1 = l;
 
395
        for (m = i__ - 2; m >= i__1; --m) {
 
396
/*           Determine the effect of starting the double-shift QR   
 
397
             iteration at row M, and see if this would make H(M,M-1)   
 
398
             negligible.  (The following uses scaling to avoid   
 
399
             overflows and most underflows.) */
328
400
 
329
 
            h11 = h__[m + m * h_dim1];
330
 
            h22 = h__[m + 1 + (m + 1) * h_dim1];
331
 
            h21 = h__[m + 1 + m * h_dim1];
332
 
            h12 = h__[m + (m + 1) * h_dim1];
333
 
            h44s = h44 - h11;
334
 
            h33s = h33 - h11;
335
 
            v1 = (h33s * h44s - h43h34) / h21 + h12;
336
 
            v2 = h22 - h11 - h33s - h44s;
337
 
            v3 = h__[m + 2 + (m + 1) * h_dim1];
338
 
            s = abs(v1) + abs(v2) + abs(v3);
339
 
            v1 /= s;
340
 
            v2 /= s;
341
 
            v3 /= s;
342
 
            v[0] = v1;
343
 
            v[1] = v2;
344
 
            v[2] = v3;
 
401
            h21s = h__[m + 1 + m * h_dim1];
 
402
            s = (d__1 = h__[m + m * h_dim1] - rt2r, abs(d__1)) + abs(rt2i) + 
 
403
                    abs(h21s);
 
404
            h21s = h__[m + 1 + m * h_dim1] / s;
 
405
            v[0] = h21s * h__[m + (m + 1) * h_dim1] + (h__[m + m * h_dim1] - 
 
406
                    rt1r) * ((h__[m + m * h_dim1] - rt2r) / s) - rt1i * (rt2i 
 
407
                    / s);
 
408
            v[1] = h21s * (h__[m + m * h_dim1] + h__[m + 1 + (m + 1) * h_dim1]
 
409
                     - rt1r - rt2r);
 
410
            v[2] = h21s * h__[m + 2 + (m + 1) * h_dim1];
 
411
            s = abs(v[0]) + abs(v[1]) + abs(v[2]);
 
412
            v[0] /= s;
 
413
            v[1] /= s;
 
414
            v[2] /= s;
345
415
            if (m == l) {
346
 
                goto L50;
347
 
            }
348
 
            h00 = h__[m - 1 + (m - 1) * h_dim1];
349
 
            h10 = h__[m + (m - 1) * h_dim1];
350
 
            tst1 = abs(v1) * (abs(h00) + abs(h11) + abs(h22));
351
 
            if (abs(h10) * (abs(v2) + abs(v3)) <= ulp * tst1) {
352
 
                goto L50;
353
 
            }
354
 
/* L40: */
 
416
                goto L60;
 
417
            }
 
418
            if ((d__1 = h__[m + (m - 1) * h_dim1], abs(d__1)) * (abs(v[1]) + 
 
419
                    abs(v[2])) <= ulp * abs(v[0]) * ((d__2 = h__[m - 1 + (m - 
 
420
                    1) * h_dim1], abs(d__2)) + (d__3 = h__[m + m * h_dim1], 
 
421
                    abs(d__3)) + (d__4 = h__[m + 1 + (m + 1) * h_dim1], abs(
 
422
                    d__4)))) {
 
423
                goto L60;
 
424
            }
 
425
/* L50: */
355
426
        }
356
 
L50:
 
427
L60:
357
428
 
358
429
/*        Double-shift QR step */
359
430
 
360
 
        i__2 = i__ - 1;
361
 
        for (k = m; k <= i__2; ++k) {
362
 
 
363
 
/*           The first iteration of this loop determines a reflection G */
364
 
/*           from the vector V and applies it from left and right to H, */
365
 
/*           thus creating a nonzero bulge below the subdiagonal. */
366
 
 
367
 
/*           Each subsequent iteration determines a reflection G to */
368
 
/*           restore the Hessenberg form in the (K-1)th column, and thus */
369
 
/*           chases the bulge one step toward the bottom of the active */
370
 
/*           submatrix. NR is the order of G. */
371
 
 
372
 
/* Computing MIN */
373
 
            i__3 = 3, i__4 = i__ - k + 1;
374
 
            nr = min(i__3,i__4);
 
431
        i__1 = i__ - 1;
 
432
        for (k = m; k <= i__1; ++k) {
 
433
 
 
434
/*           The first iteration of this loop determines a reflection G   
 
435
             from the vector V and applies it from left and right to H,   
 
436
             thus creating a nonzero bulge below the subdiagonal.   
 
437
 
 
438
             Each subsequent iteration determines a reflection G to   
 
439
             restore the Hessenberg form in the (K-1)th column, and thus   
 
440
             chases the bulge one step toward the bottom of the active   
 
441
             submatrix. NR is the order of G.   
 
442
 
 
443
   Computing MIN */
 
444
            i__2 = 3, i__3 = i__ - k + 1;
 
445
            nr = min(i__2,i__3);
375
446
            if (k > m) {
376
447
                igraphdcopy_(&nr, &h__[k + (k - 1) * h_dim1], &c__1, v, &c__1);
377
448
            }
383
454
                    h__[k + 2 + (k - 1) * h_dim1] = 0.;
384
455
                }
385
456
            } else if (m > l) {
386
 
                h__[k + (k - 1) * h_dim1] = -h__[k + (k - 1) * h_dim1];
 
457
/*               ==== Use the following instead of   
 
458
                 .    H( K, K-1 ) = -H( K, K-1 ) to   
 
459
                 .    avoid a bug when v(2) and v(3)   
 
460
                 .    underflow. ==== */
 
461
                h__[k + (k - 1) * h_dim1] *= 1. - t1;
387
462
            }
388
463
            v2 = v[1];
389
464
            t2 = t1 * v2;
391
466
                v3 = v[2];
392
467
                t3 = t1 * v3;
393
468
 
394
 
/*              Apply G from the left to transform the rows of the matrix */
395
 
/*              in columns K to I2. */
 
469
/*              Apply G from the left to transform the rows of the matrix   
 
470
                in columns K to I2. */
396
471
 
397
 
                i__3 = i2;
398
 
                for (j = k; j <= i__3; ++j) {
 
472
                i__2 = i2;
 
473
                for (j = k; j <= i__2; ++j) {
399
474
                    sum = h__[k + j * h_dim1] + v2 * h__[k + 1 + j * h_dim1] 
400
475
                            + v3 * h__[k + 2 + j * h_dim1];
401
476
                    h__[k + j * h_dim1] -= sum * t1;
402
477
                    h__[k + 1 + j * h_dim1] -= sum * t2;
403
478
                    h__[k + 2 + j * h_dim1] -= sum * t3;
404
 
/* L60: */
 
479
/* L70: */
405
480
                }
406
481
 
407
 
/*              Apply G from the right to transform the columns of the */
408
 
/*              matrix in rows I1 to min(K+3,I). */
 
482
/*              Apply G from the right to transform the columns of the   
 
483
                matrix in rows I1 to min(K+3,I).   
409
484
 
410
 
/* Computing MIN */
411
 
                i__4 = k + 3;
412
 
                i__3 = min(i__4,i__);
413
 
                for (j = i1; j <= i__3; ++j) {
 
485
   Computing MIN */
 
486
                i__3 = k + 3;
 
487
                i__2 = min(i__3,i__);
 
488
                for (j = i1; j <= i__2; ++j) {
414
489
                    sum = h__[j + k * h_dim1] + v2 * h__[j + (k + 1) * h_dim1]
415
490
                             + v3 * h__[j + (k + 2) * h_dim1];
416
491
                    h__[j + k * h_dim1] -= sum * t1;
417
492
                    h__[j + (k + 1) * h_dim1] -= sum * t2;
418
493
                    h__[j + (k + 2) * h_dim1] -= sum * t3;
419
 
/* L70: */
 
494
/* L80: */
420
495
                }
421
496
 
422
497
                if (*wantz) {
423
498
 
424
499
/*                 Accumulate transformations in the matrix Z */
425
500
 
426
 
                    i__3 = *ihiz;
427
 
                    for (j = *iloz; j <= i__3; ++j) {
 
501
                    i__2 = *ihiz;
 
502
                    for (j = *iloz; j <= i__2; ++j) {
428
503
                        sum = z__[j + k * z_dim1] + v2 * z__[j + (k + 1) * 
429
504
                                z_dim1] + v3 * z__[j + (k + 2) * z_dim1];
430
505
                        z__[j + k * z_dim1] -= sum * t1;
431
506
                        z__[j + (k + 1) * z_dim1] -= sum * t2;
432
507
                        z__[j + (k + 2) * z_dim1] -= sum * t3;
433
 
/* L80: */
 
508
/* L90: */
434
509
                    }
435
510
                }
436
511
            } else if (nr == 2) {
437
512
 
438
 
/*              Apply G from the left to transform the rows of the matrix */
439
 
/*              in columns K to I2. */
 
513
/*              Apply G from the left to transform the rows of the matrix   
 
514
                in columns K to I2. */
440
515
 
441
 
                i__3 = i2;
442
 
                for (j = k; j <= i__3; ++j) {
 
516
                i__2 = i2;
 
517
                for (j = k; j <= i__2; ++j) {
443
518
                    sum = h__[k + j * h_dim1] + v2 * h__[k + 1 + j * h_dim1];
444
519
                    h__[k + j * h_dim1] -= sum * t1;
445
520
                    h__[k + 1 + j * h_dim1] -= sum * t2;
446
 
/* L90: */
 
521
/* L100: */
447
522
                }
448
523
 
449
 
/*              Apply G from the right to transform the columns of the */
450
 
/*              matrix in rows I1 to min(K+3,I). */
 
524
/*              Apply G from the right to transform the columns of the   
 
525
                matrix in rows I1 to min(K+3,I). */
451
526
 
452
 
                i__3 = i__;
453
 
                for (j = i1; j <= i__3; ++j) {
 
527
                i__2 = i__;
 
528
                for (j = i1; j <= i__2; ++j) {
454
529
                    sum = h__[j + k * h_dim1] + v2 * h__[j + (k + 1) * h_dim1]
455
530
                            ;
456
531
                    h__[j + k * h_dim1] -= sum * t1;
457
532
                    h__[j + (k + 1) * h_dim1] -= sum * t2;
458
 
/* L100: */
 
533
/* L110: */
459
534
                }
460
535
 
461
536
                if (*wantz) {
462
537
 
463
538
/*                 Accumulate transformations in the matrix Z */
464
539
 
465
 
                    i__3 = *ihiz;
466
 
                    for (j = *iloz; j <= i__3; ++j) {
 
540
                    i__2 = *ihiz;
 
541
                    for (j = *iloz; j <= i__2; ++j) {
467
542
                        sum = z__[j + k * z_dim1] + v2 * z__[j + (k + 1) * 
468
543
                                z_dim1];
469
544
                        z__[j + k * z_dim1] -= sum * t1;
470
545
                        z__[j + (k + 1) * z_dim1] -= sum * t2;
471
 
/* L110: */
472
 
                    }
473
 
                }
474
 
            }
475
546
/* L120: */
476
 
        }
477
 
 
 
547
                    }
 
548
                }
 
549
            }
478
550
/* L130: */
 
551
        }
 
552
 
 
553
/* L140: */
479
554
    }
480
555
 
481
556
/*     Failure to converge in remaining number of iterations */
483
558
    *info = i__;
484
559
    return 0;
485
560
 
486
 
L140:
 
561
L150:
487
562
 
488
563
    if (l == i__) {
489
564
 
493
568
        wi[i__] = 0.;
494
569
    } else if (l == i__ - 1) {
495
570
 
496
 
/*        H(I-1,I-2) is negligible: a pair of eigenvalues have converged. */
 
571
/*        H(I-1,I-2) is negligible: a pair of eigenvalues have converged.   
497
572
 
498
 
/*        Transform the 2-by-2 submatrix to standard Schur form, */
499
 
/*        and compute and store the eigenvalues. */
 
573
          Transform the 2-by-2 submatrix to standard Schur form,   
 
574
          and compute and store the eigenvalues. */
500
575
 
501
576
        igraphdlanv2_(&h__[i__ - 1 + (i__ - 1) * h_dim1], &h__[i__ - 1 + i__ * 
502
577
                h_dim1], &h__[i__ + (i__ - 1) * h_dim1], &h__[i__ + i__ * 
525
600
        }
526
601
    }
527
602
 
528
 
/*     Decrement number of remaining iterations, and return to start of */
529
 
/*     the main loop with new value of I. */
 
603
/*     return to start of the main loop with new value of I. */
530
604
 
531
 
    itn -= its;
532
605
    i__ = l - 1;
533
 
    goto L10;
 
606
    goto L20;
534
607
 
535
 
L150:
 
608
L160:
536
609
    return 0;
537
610
 
538
611
/*     End of DLAHQR */