Mercurial > octave
comparison libcruft/lapack/slag2.f @ 7789:82be108cc558
First attempt at single precision tyeps
* * *
corrections to qrupdate single precision routines
* * *
prefer demotion to single over promotion to double
* * *
Add single precision support to log2 function
* * *
Trivial PROJECT file update
* * *
Cache optimized hermitian/transpose methods
* * *
Add tests for tranpose/hermitian and ChangeLog entry for new transpose code
author | David Bateman <dbateman@free.fr> |
---|---|
date | Sun, 27 Apr 2008 22:34:17 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7788:45f5faba05a2 | 7789:82be108cc558 |
---|---|
1 SUBROUTINE SLAG2( A, LDA, B, LDB, SAFMIN, SCALE1, SCALE2, WR1, | |
2 $ WR2, WI ) | |
3 * | |
4 * -- LAPACK auxiliary routine (version 3.1) -- | |
5 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. | |
6 * November 2006 | |
7 * | |
8 * .. Scalar Arguments .. | |
9 INTEGER LDA, LDB | |
10 REAL SAFMIN, SCALE1, SCALE2, WI, WR1, WR2 | |
11 * .. | |
12 * .. Array Arguments .. | |
13 REAL A( LDA, * ), B( LDB, * ) | |
14 * .. | |
15 * | |
16 * Purpose | |
17 * ======= | |
18 * | |
19 * SLAG2 computes the eigenvalues of a 2 x 2 generalized eigenvalue | |
20 * problem A - w B, with scaling as necessary to avoid over-/underflow. | |
21 * | |
22 * The scaling factor "s" results in a modified eigenvalue equation | |
23 * | |
24 * s A - w B | |
25 * | |
26 * where s is a non-negative scaling factor chosen so that w, w B, | |
27 * and s A do not overflow and, if possible, do not underflow, either. | |
28 * | |
29 * Arguments | |
30 * ========= | |
31 * | |
32 * A (input) REAL array, dimension (LDA, 2) | |
33 * On entry, the 2 x 2 matrix A. It is assumed that its 1-norm | |
34 * is less than 1/SAFMIN. Entries less than | |
35 * sqrt(SAFMIN)*norm(A) are subject to being treated as zero. | |
36 * | |
37 * LDA (input) INTEGER | |
38 * The leading dimension of the array A. LDA >= 2. | |
39 * | |
40 * B (input) REAL array, dimension (LDB, 2) | |
41 * On entry, the 2 x 2 upper triangular matrix B. It is | |
42 * assumed that the one-norm of B is less than 1/SAFMIN. The | |
43 * diagonals should be at least sqrt(SAFMIN) times the largest | |
44 * element of B (in absolute value); if a diagonal is smaller | |
45 * than that, then +/- sqrt(SAFMIN) will be used instead of | |
46 * that diagonal. | |
47 * | |
48 * LDB (input) INTEGER | |
49 * The leading dimension of the array B. LDB >= 2. | |
50 * | |
51 * SAFMIN (input) REAL | |
52 * The smallest positive number s.t. 1/SAFMIN does not | |
53 * overflow. (This should always be SLAMCH('S') -- it is an | |
54 * argument in order to avoid having to call SLAMCH frequently.) | |
55 * | |
56 * SCALE1 (output) REAL | |
57 * A scaling factor used to avoid over-/underflow in the | |
58 * eigenvalue equation which defines the first eigenvalue. If | |
59 * the eigenvalues are complex, then the eigenvalues are | |
60 * ( WR1 +/- WI i ) / SCALE1 (which may lie outside the | |
61 * exponent range of the machine), SCALE1=SCALE2, and SCALE1 | |
62 * will always be positive. If the eigenvalues are real, then | |
63 * the first (real) eigenvalue is WR1 / SCALE1 , but this may | |
64 * overflow or underflow, and in fact, SCALE1 may be zero or | |
65 * less than the underflow threshhold if the exact eigenvalue | |
66 * is sufficiently large. | |
67 * | |
68 * SCALE2 (output) REAL | |
69 * A scaling factor used to avoid over-/underflow in the | |
70 * eigenvalue equation which defines the second eigenvalue. If | |
71 * the eigenvalues are complex, then SCALE2=SCALE1. If the | |
72 * eigenvalues are real, then the second (real) eigenvalue is | |
73 * WR2 / SCALE2 , but this may overflow or underflow, and in | |
74 * fact, SCALE2 may be zero or less than the underflow | |
75 * threshhold if the exact eigenvalue is sufficiently large. | |
76 * | |
77 * WR1 (output) REAL | |
78 * If the eigenvalue is real, then WR1 is SCALE1 times the | |
79 * eigenvalue closest to the (2,2) element of A B**(-1). If the | |
80 * eigenvalue is complex, then WR1=WR2 is SCALE1 times the real | |
81 * part of the eigenvalues. | |
82 * | |
83 * WR2 (output) REAL | |
84 * If the eigenvalue is real, then WR2 is SCALE2 times the | |
85 * other eigenvalue. If the eigenvalue is complex, then | |
86 * WR1=WR2 is SCALE1 times the real part of the eigenvalues. | |
87 * | |
88 * WI (output) REAL | |
89 * If the eigenvalue is real, then WI is zero. If the | |
90 * eigenvalue is complex, then WI is SCALE1 times the imaginary | |
91 * part of the eigenvalues. WI will always be non-negative. | |
92 * | |
93 * ===================================================================== | |
94 * | |
95 * .. Parameters .. | |
96 REAL ZERO, ONE, TWO | |
97 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0, TWO = 2.0E+0 ) | |
98 REAL HALF | |
99 PARAMETER ( HALF = ONE / TWO ) | |
100 REAL FUZZY1 | |
101 PARAMETER ( FUZZY1 = ONE+1.0E-5 ) | |
102 * .. | |
103 * .. Local Scalars .. | |
104 REAL A11, A12, A21, A22, ABI22, ANORM, AS11, AS12, | |
105 $ AS22, ASCALE, B11, B12, B22, BINV11, BINV22, | |
106 $ BMIN, BNORM, BSCALE, BSIZE, C1, C2, C3, C4, C5, | |
107 $ DIFF, DISCR, PP, QQ, R, RTMAX, RTMIN, S1, S2, | |
108 $ SAFMAX, SHIFT, SS, SUM, WABS, WBIG, WDET, | |
109 $ WSCALE, WSIZE, WSMALL | |
110 * .. | |
111 * .. Intrinsic Functions .. | |
112 INTRINSIC ABS, MAX, MIN, SIGN, SQRT | |
113 * .. | |
114 * .. Executable Statements .. | |
115 * | |
116 RTMIN = SQRT( SAFMIN ) | |
117 RTMAX = ONE / RTMIN | |
118 SAFMAX = ONE / SAFMIN | |
119 * | |
120 * Scale A | |
121 * | |
122 ANORM = MAX( ABS( A( 1, 1 ) )+ABS( A( 2, 1 ) ), | |
123 $ ABS( A( 1, 2 ) )+ABS( A( 2, 2 ) ), SAFMIN ) | |
124 ASCALE = ONE / ANORM | |
125 A11 = ASCALE*A( 1, 1 ) | |
126 A21 = ASCALE*A( 2, 1 ) | |
127 A12 = ASCALE*A( 1, 2 ) | |
128 A22 = ASCALE*A( 2, 2 ) | |
129 * | |
130 * Perturb B if necessary to insure non-singularity | |
131 * | |
132 B11 = B( 1, 1 ) | |
133 B12 = B( 1, 2 ) | |
134 B22 = B( 2, 2 ) | |
135 BMIN = RTMIN*MAX( ABS( B11 ), ABS( B12 ), ABS( B22 ), RTMIN ) | |
136 IF( ABS( B11 ).LT.BMIN ) | |
137 $ B11 = SIGN( BMIN, B11 ) | |
138 IF( ABS( B22 ).LT.BMIN ) | |
139 $ B22 = SIGN( BMIN, B22 ) | |
140 * | |
141 * Scale B | |
142 * | |
143 BNORM = MAX( ABS( B11 ), ABS( B12 )+ABS( B22 ), SAFMIN ) | |
144 BSIZE = MAX( ABS( B11 ), ABS( B22 ) ) | |
145 BSCALE = ONE / BSIZE | |
146 B11 = B11*BSCALE | |
147 B12 = B12*BSCALE | |
148 B22 = B22*BSCALE | |
149 * | |
150 * Compute larger eigenvalue by method described by C. van Loan | |
151 * | |
152 * ( AS is A shifted by -SHIFT*B ) | |
153 * | |
154 BINV11 = ONE / B11 | |
155 BINV22 = ONE / B22 | |
156 S1 = A11*BINV11 | |
157 S2 = A22*BINV22 | |
158 IF( ABS( S1 ).LE.ABS( S2 ) ) THEN | |
159 AS12 = A12 - S1*B12 | |
160 AS22 = A22 - S1*B22 | |
161 SS = A21*( BINV11*BINV22 ) | |
162 ABI22 = AS22*BINV22 - SS*B12 | |
163 PP = HALF*ABI22 | |
164 SHIFT = S1 | |
165 ELSE | |
166 AS12 = A12 - S2*B12 | |
167 AS11 = A11 - S2*B11 | |
168 SS = A21*( BINV11*BINV22 ) | |
169 ABI22 = -SS*B12 | |
170 PP = HALF*( AS11*BINV11+ABI22 ) | |
171 SHIFT = S2 | |
172 END IF | |
173 QQ = SS*AS12 | |
174 IF( ABS( PP*RTMIN ).GE.ONE ) THEN | |
175 DISCR = ( RTMIN*PP )**2 + QQ*SAFMIN | |
176 R = SQRT( ABS( DISCR ) )*RTMAX | |
177 ELSE | |
178 IF( PP**2+ABS( QQ ).LE.SAFMIN ) THEN | |
179 DISCR = ( RTMAX*PP )**2 + QQ*SAFMAX | |
180 R = SQRT( ABS( DISCR ) )*RTMIN | |
181 ELSE | |
182 DISCR = PP**2 + QQ | |
183 R = SQRT( ABS( DISCR ) ) | |
184 END IF | |
185 END IF | |
186 * | |
187 * Note: the test of R in the following IF is to cover the case when | |
188 * DISCR is small and negative and is flushed to zero during | |
189 * the calculation of R. On machines which have a consistent | |
190 * flush-to-zero threshhold and handle numbers above that | |
191 * threshhold correctly, it would not be necessary. | |
192 * | |
193 IF( DISCR.GE.ZERO .OR. R.EQ.ZERO ) THEN | |
194 SUM = PP + SIGN( R, PP ) | |
195 DIFF = PP - SIGN( R, PP ) | |
196 WBIG = SHIFT + SUM | |
197 * | |
198 * Compute smaller eigenvalue | |
199 * | |
200 WSMALL = SHIFT + DIFF | |
201 IF( HALF*ABS( WBIG ).GT.MAX( ABS( WSMALL ), SAFMIN ) ) THEN | |
202 WDET = ( A11*A22-A12*A21 )*( BINV11*BINV22 ) | |
203 WSMALL = WDET / WBIG | |
204 END IF | |
205 * | |
206 * Choose (real) eigenvalue closest to 2,2 element of A*B**(-1) | |
207 * for WR1. | |
208 * | |
209 IF( PP.GT.ABI22 ) THEN | |
210 WR1 = MIN( WBIG, WSMALL ) | |
211 WR2 = MAX( WBIG, WSMALL ) | |
212 ELSE | |
213 WR1 = MAX( WBIG, WSMALL ) | |
214 WR2 = MIN( WBIG, WSMALL ) | |
215 END IF | |
216 WI = ZERO | |
217 ELSE | |
218 * | |
219 * Complex eigenvalues | |
220 * | |
221 WR1 = SHIFT + PP | |
222 WR2 = WR1 | |
223 WI = R | |
224 END IF | |
225 * | |
226 * Further scaling to avoid underflow and overflow in computing | |
227 * SCALE1 and overflow in computing w*B. | |
228 * | |
229 * This scale factor (WSCALE) is bounded from above using C1 and C2, | |
230 * and from below using C3 and C4. | |
231 * C1 implements the condition s A must never overflow. | |
232 * C2 implements the condition w B must never overflow. | |
233 * C3, with C2, | |
234 * implement the condition that s A - w B must never overflow. | |
235 * C4 implements the condition s should not underflow. | |
236 * C5 implements the condition max(s,|w|) should be at least 2. | |
237 * | |
238 C1 = BSIZE*( SAFMIN*MAX( ONE, ASCALE ) ) | |
239 C2 = SAFMIN*MAX( ONE, BNORM ) | |
240 C3 = BSIZE*SAFMIN | |
241 IF( ASCALE.LE.ONE .AND. BSIZE.LE.ONE ) THEN | |
242 C4 = MIN( ONE, ( ASCALE / SAFMIN )*BSIZE ) | |
243 ELSE | |
244 C4 = ONE | |
245 END IF | |
246 IF( ASCALE.LE.ONE .OR. BSIZE.LE.ONE ) THEN | |
247 C5 = MIN( ONE, ASCALE*BSIZE ) | |
248 ELSE | |
249 C5 = ONE | |
250 END IF | |
251 * | |
252 * Scale first eigenvalue | |
253 * | |
254 WABS = ABS( WR1 ) + ABS( WI ) | |
255 WSIZE = MAX( SAFMIN, C1, FUZZY1*( WABS*C2+C3 ), | |
256 $ MIN( C4, HALF*MAX( WABS, C5 ) ) ) | |
257 IF( WSIZE.NE.ONE ) THEN | |
258 WSCALE = ONE / WSIZE | |
259 IF( WSIZE.GT.ONE ) THEN | |
260 SCALE1 = ( MAX( ASCALE, BSIZE )*WSCALE )* | |
261 $ MIN( ASCALE, BSIZE ) | |
262 ELSE | |
263 SCALE1 = ( MIN( ASCALE, BSIZE )*WSCALE )* | |
264 $ MAX( ASCALE, BSIZE ) | |
265 END IF | |
266 WR1 = WR1*WSCALE | |
267 IF( WI.NE.ZERO ) THEN | |
268 WI = WI*WSCALE | |
269 WR2 = WR1 | |
270 SCALE2 = SCALE1 | |
271 END IF | |
272 ELSE | |
273 SCALE1 = ASCALE*BSIZE | |
274 SCALE2 = SCALE1 | |
275 END IF | |
276 * | |
277 * Scale second eigenvalue (if real) | |
278 * | |
279 IF( WI.EQ.ZERO ) THEN | |
280 WSIZE = MAX( SAFMIN, C1, FUZZY1*( ABS( WR2 )*C2+C3 ), | |
281 $ MIN( C4, HALF*MAX( ABS( WR2 ), C5 ) ) ) | |
282 IF( WSIZE.NE.ONE ) THEN | |
283 WSCALE = ONE / WSIZE | |
284 IF( WSIZE.GT.ONE ) THEN | |
285 SCALE2 = ( MAX( ASCALE, BSIZE )*WSCALE )* | |
286 $ MIN( ASCALE, BSIZE ) | |
287 ELSE | |
288 SCALE2 = ( MIN( ASCALE, BSIZE )*WSCALE )* | |
289 $ MAX( ASCALE, BSIZE ) | |
290 END IF | |
291 WR2 = WR2*WSCALE | |
292 ELSE | |
293 SCALE2 = ASCALE*BSIZE | |
294 END IF | |
295 END IF | |
296 * | |
297 * End of SLAG2 | |
298 * | |
299 RETURN | |
300 END |