1
/* -- translated by f2c (version 20050501).
2
You must link the resulting object file with libf2c:
3
on Microsoft Windows system, link with libf2c.lib;
4
on Linux or Unix systems, link with .../path/to/libf2c.a -lm
5
or, if you install libf2c.a in a standard place, with -lf2c -lm
6
-- in that order, at the end of the command line, as in
8
Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
10
http://www.netlib.org/f2c/libf2c.zip
14
#include "arpack_internal.h"
17
/* Table of constant values */
19
static integer c__4 = 4;
20
static integer c__1 = 1;
21
static integer c__16 = 16;
22
static integer c__0 = 0;
24
/* Subroutine */ int igraphdlasy2_(logical *ltranl, logical *ltranr, integer *isgn,
25
integer *n1, integer *n2, doublereal *tl, integer *ldtl, doublereal *
26
tr, integer *ldtr, doublereal *b, integer *ldb, doublereal *scale,
27
doublereal *x, integer *ldx, doublereal *xnorm, integer *info)
29
/* Initialized data */
31
static integer locu12[4] = { 3,4,1,2 };
32
static integer locl21[4] = { 2,1,4,3 };
33
static integer locu22[4] = { 4,3,2,1 };
34
static logical xswpiv[4] = { FALSE_,FALSE_,TRUE_,TRUE_ };
35
static logical bswpiv[4] = { FALSE_,TRUE_,FALSE_,TRUE_ };
37
/* System generated locals */
38
integer b_dim1, b_offset, tl_dim1, tl_offset, tr_dim1, tr_offset, x_dim1,
40
doublereal d__1, d__2, d__3, d__4, d__5, d__6, d__7, d__8;
43
static integer i__, j, k;
44
static doublereal x2[2], l21, u11, u12;
45
static integer ip, jp;
46
static doublereal u22, t16[16] /* was [4][4] */, gam, bet, eps, sgn,
47
tmp[4], tau1, btmp[4], smin;
49
static doublereal temp;
50
static integer jpiv[4];
51
static doublereal xmax;
52
static integer ipsv, jpsv;
54
extern /* Subroutine */ int igraphdcopy_(integer *, doublereal *, integer *,
55
doublereal *, integer *), igraphdswap_(integer *, doublereal *, integer
56
*, doublereal *, integer *);
58
extern doublereal igraphdlamch_(char *);
59
extern integer igraphidamax_(integer *, doublereal *, integer *);
60
static doublereal smlnum;
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
/* October 31, 1992 */
68
/* .. Scalar Arguments .. */
70
/* .. Array Arguments .. */
76
/* DLASY2 solves for the N1 by N2 matrix X, 1 <= N1,N2 <= 2, in */
78
/* op(TL)*X + ISGN*X*op(TR) = SCALE*B, */
80
/* where TL is N1 by N1, TR is N2 by N2, B is N1 by N2, and ISGN = 1 or */
81
/* -1. op(T) = T or T', where T' denotes the transpose of T. */
86
/* LTRANL (input) LOGICAL */
87
/* On entry, LTRANL specifies the op(TL): */
88
/* = .FALSE., op(TL) = TL, */
89
/* = .TRUE., op(TL) = TL'. */
91
/* LTRANR (input) LOGICAL */
92
/* On entry, LTRANR specifies the op(TR): */
93
/* = .FALSE., op(TR) = TR, */
94
/* = .TRUE., op(TR) = TR'. */
96
/* ISGN (input) INTEGER */
97
/* On entry, ISGN specifies the sign of the equation */
98
/* as described before. ISGN may only be 1 or -1. */
100
/* N1 (input) INTEGER */
101
/* On entry, N1 specifies the order of matrix TL. */
102
/* N1 may only be 0, 1 or 2. */
104
/* N2 (input) INTEGER */
105
/* On entry, N2 specifies the order of matrix TR. */
106
/* N2 may only be 0, 1 or 2. */
108
/* TL (input) DOUBLE PRECISION array, dimension (LDTL,2) */
109
/* On entry, TL contains an N1 by N1 matrix. */
111
/* LDTL (input) INTEGER */
112
/* The leading dimension of the matrix TL. LDTL >= max(1,N1). */
114
/* TR (input) DOUBLE PRECISION array, dimension (LDTR,2) */
115
/* On entry, TR contains an N2 by N2 matrix. */
117
/* LDTR (input) INTEGER */
118
/* The leading dimension of the matrix TR. LDTR >= max(1,N2). */
120
/* B (input) DOUBLE PRECISION array, dimension (LDB,2) */
121
/* On entry, the N1 by N2 matrix B contains the right-hand */
122
/* side of the equation. */
124
/* LDB (input) INTEGER */
125
/* The leading dimension of the matrix B. LDB >= max(1,N1). */
127
/* SCALE (output) DOUBLE PRECISION */
128
/* On exit, SCALE contains the scale factor. SCALE is chosen */
129
/* less than or equal to 1 to prevent the solution overflowing. */
131
/* X (output) DOUBLE PRECISION array, dimension (LDX,2) */
132
/* On exit, X contains the N1 by N2 solution. */
134
/* LDX (input) INTEGER */
135
/* The leading dimension of the matrix X. LDX >= max(1,N1). */
137
/* XNORM (output) DOUBLE PRECISION */
138
/* On exit, XNORM is the infinity-norm of the solution. */
140
/* INFO (output) INTEGER */
141
/* On exit, INFO is set to */
142
/* 0: successful exit. */
143
/* 1: TL and TR have too close eigenvalues, so TL or */
144
/* TR is perturbed to get a nonsingular equation. */
145
/* NOTE: In the interests of speed, this routine does not */
146
/* check the inputs for errors. */
148
/* ===================================================================== */
150
/* .. Parameters .. */
152
/* .. Local Scalars .. */
154
/* .. Local Arrays .. */
156
/* .. External Functions .. */
158
/* .. External Subroutines .. */
160
/* .. Intrinsic Functions .. */
162
/* .. Data statements .. */
163
/* Parameter adjustments */
165
tl_offset = 1 + tl_dim1;
168
tr_offset = 1 + tr_dim1;
171
b_offset = 1 + b_dim1;
174
x_offset = 1 + x_dim1;
179
/* .. Executable Statements .. */
181
/* Do not check the input parameters for errors */
185
/* Quick return if possible */
187
if (*n1 == 0 || *n2 == 0) {
191
/* Set constants to control overflow */
193
eps = igraphdlamch_("P");
194
smlnum = igraphdlamch_("S") / eps;
195
sgn = (doublereal) (*isgn);
197
k = *n1 + *n1 + *n2 - 2;
205
/* 1 by 1: TL11*X + SGN*X*TR11 = B11 */
208
tau1 = tl[tl_dim1 + 1] + sgn * tr[tr_dim1 + 1];
217
gam = (d__1 = b[b_dim1 + 1], abs(d__1));
218
if (smlnum * gam > bet) {
222
x[x_dim1 + 1] = b[b_dim1 + 1] * *scale / tau1;
223
*xnorm = (d__1 = x[x_dim1 + 1], abs(d__1));
227
/* TL11*[X11 X12] + ISGN*[X11 X12]*op[TR11 TR12] = [B11 B12] */
234
d__7 = (d__1 = tl[tl_dim1 + 1], abs(d__1)), d__8 = (d__2 = tr[tr_dim1 + 1]
235
, abs(d__2)), d__7 = max(d__7,d__8), d__8 = (d__3 = tr[(tr_dim1 <<
236
1) + 1], abs(d__3)), d__7 = max(d__7,d__8), d__8 = (d__4 = tr[
237
tr_dim1 + 2], abs(d__4)), d__7 = max(d__7,d__8), d__8 = (d__5 =
238
tr[(tr_dim1 << 1) + 2], abs(d__5));
239
d__6 = eps * max(d__7,d__8);
240
smin = max(d__6,smlnum);
241
tmp[0] = tl[tl_dim1 + 1] + sgn * tr[tr_dim1 + 1];
242
tmp[3] = tl[tl_dim1 + 1] + sgn * tr[(tr_dim1 << 1) + 2];
244
tmp[1] = sgn * tr[tr_dim1 + 2];
245
tmp[2] = sgn * tr[(tr_dim1 << 1) + 1];
247
tmp[1] = sgn * tr[(tr_dim1 << 1) + 1];
248
tmp[2] = sgn * tr[tr_dim1 + 2];
250
btmp[0] = b[b_dim1 + 1];
251
btmp[1] = b[(b_dim1 << 1) + 1];
255
/* op[TL11 TL12]*[X11] + ISGN* [X11]*TR11 = [B11] */
256
/* [TL21 TL22] [X21] [X21] [B21] */
261
d__7 = (d__1 = tr[tr_dim1 + 1], abs(d__1)), d__8 = (d__2 = tl[tl_dim1 + 1]
262
, abs(d__2)), d__7 = max(d__7,d__8), d__8 = (d__3 = tl[(tl_dim1 <<
263
1) + 1], abs(d__3)), d__7 = max(d__7,d__8), d__8 = (d__4 = tl[
264
tl_dim1 + 2], abs(d__4)), d__7 = max(d__7,d__8), d__8 = (d__5 =
265
tl[(tl_dim1 << 1) + 2], abs(d__5));
266
d__6 = eps * max(d__7,d__8);
267
smin = max(d__6,smlnum);
268
tmp[0] = tl[tl_dim1 + 1] + sgn * tr[tr_dim1 + 1];
269
tmp[3] = tl[(tl_dim1 << 1) + 2] + sgn * tr[tr_dim1 + 1];
271
tmp[1] = tl[(tl_dim1 << 1) + 1];
272
tmp[2] = tl[tl_dim1 + 2];
274
tmp[1] = tl[tl_dim1 + 2];
275
tmp[2] = tl[(tl_dim1 << 1) + 1];
277
btmp[0] = b[b_dim1 + 1];
278
btmp[1] = b[b_dim1 + 2];
281
/* Solve 2 by 2 system using complete pivoting. */
282
/* Set pivots less than SMIN to SMIN. */
284
ipiv = igraphidamax_(&c__4, tmp, &c__1);
286
if (abs(u11) <= smin) {
290
u12 = tmp[locu12[ipiv - 1] - 1];
291
l21 = tmp[locl21[ipiv - 1] - 1] / u11;
292
u22 = tmp[locu22[ipiv - 1] - 1] - u12 * l21;
293
xswap = xswpiv[ipiv - 1];
294
bswap = bswpiv[ipiv - 1];
295
if (abs(u22) <= smin) {
301
btmp[1] = btmp[0] - l21 * temp;
304
btmp[1] -= l21 * btmp[0];
307
if (smlnum * 2. * abs(btmp[1]) > abs(u22) || smlnum * 2. * abs(btmp[0]) >
310
d__1 = abs(btmp[0]), d__2 = abs(btmp[1]);
311
*scale = .5 / max(d__1,d__2);
315
x2[1] = btmp[1] / u22;
316
x2[0] = btmp[0] / u11 - u12 / u11 * x2[1];
322
x[x_dim1 + 1] = x2[0];
324
x[(x_dim1 << 1) + 1] = x2[1];
325
*xnorm = (d__1 = x[x_dim1 + 1], abs(d__1)) + (d__2 = x[(x_dim1 << 1)
328
x[x_dim1 + 2] = x2[1];
330
d__3 = (d__1 = x[x_dim1 + 1], abs(d__1)), d__4 = (d__2 = x[x_dim1 + 2]
332
*xnorm = max(d__3,d__4);
337
/* op[TL11 TL12]*[X11 X12] +ISGN* [X11 X12]*op[TR11 TR12] = [B11 B12] */
338
/* [TL21 TL22] [X21 X22] [X21 X22] [TR21 TR22] [B21 B22] */
340
/* Solve equivalent 4 by 4 system using complete pivoting. */
341
/* Set pivots less than SMIN to SMIN. */
345
d__5 = (d__1 = tr[tr_dim1 + 1], abs(d__1)), d__6 = (d__2 = tr[(tr_dim1 <<
346
1) + 1], abs(d__2)), d__5 = max(d__5,d__6), d__6 = (d__3 = tr[
347
tr_dim1 + 2], abs(d__3)), d__5 = max(d__5,d__6), d__6 = (d__4 =
348
tr[(tr_dim1 << 1) + 2], abs(d__4));
349
smin = max(d__5,d__6);
351
d__5 = smin, d__6 = (d__1 = tl[tl_dim1 + 1], abs(d__1)), d__5 = max(d__5,
352
d__6), d__6 = (d__2 = tl[(tl_dim1 << 1) + 1], abs(d__2)), d__5 =
353
max(d__5,d__6), d__6 = (d__3 = tl[tl_dim1 + 2], abs(d__3)), d__5 =
354
max(d__5,d__6), d__6 = (d__4 = tl[(tl_dim1 << 1) + 2], abs(d__4))
356
smin = max(d__5,d__6);
359
smin = max(d__1,smlnum);
361
igraphdcopy_(&c__16, btmp, &c__0, t16, &c__1);
362
t16[0] = tl[tl_dim1 + 1] + sgn * tr[tr_dim1 + 1];
363
t16[5] = tl[(tl_dim1 << 1) + 2] + sgn * tr[tr_dim1 + 1];
364
t16[10] = tl[tl_dim1 + 1] + sgn * tr[(tr_dim1 << 1) + 2];
365
t16[15] = tl[(tl_dim1 << 1) + 2] + sgn * tr[(tr_dim1 << 1) + 2];
367
t16[4] = tl[tl_dim1 + 2];
368
t16[1] = tl[(tl_dim1 << 1) + 1];
369
t16[14] = tl[tl_dim1 + 2];
370
t16[11] = tl[(tl_dim1 << 1) + 1];
372
t16[4] = tl[(tl_dim1 << 1) + 1];
373
t16[1] = tl[tl_dim1 + 2];
374
t16[14] = tl[(tl_dim1 << 1) + 1];
375
t16[11] = tl[tl_dim1 + 2];
378
t16[8] = sgn * tr[(tr_dim1 << 1) + 1];
379
t16[13] = sgn * tr[(tr_dim1 << 1) + 1];
380
t16[2] = sgn * tr[tr_dim1 + 2];
381
t16[7] = sgn * tr[tr_dim1 + 2];
383
t16[8] = sgn * tr[tr_dim1 + 2];
384
t16[13] = sgn * tr[tr_dim1 + 2];
385
t16[2] = sgn * tr[(tr_dim1 << 1) + 1];
386
t16[7] = sgn * tr[(tr_dim1 << 1) + 1];
388
btmp[0] = b[b_dim1 + 1];
389
btmp[1] = b[b_dim1 + 2];
390
btmp[2] = b[(b_dim1 << 1) + 1];
391
btmp[3] = b[(b_dim1 << 1) + 2];
393
/* Perform elimination */
395
for (i__ = 1; i__ <= 3; ++i__) {
397
for (ip = i__; ip <= 4; ++ip) {
398
for (jp = i__; jp <= 4; ++jp) {
399
if ((d__1 = t16[ip + (jp << 2) - 5], abs(d__1)) >= xmax) {
400
xmax = (d__1 = t16[ip + (jp << 2) - 5], abs(d__1));
409
igraphdswap_(&c__4, &t16[ipsv - 1], &c__4, &t16[i__ - 1], &c__4);
410
temp = btmp[i__ - 1];
411
btmp[i__ - 1] = btmp[ipsv - 1];
412
btmp[ipsv - 1] = temp;
415
igraphdswap_(&c__4, &t16[(jpsv << 2) - 4], &c__1, &t16[(i__ << 2) - 4],
418
jpiv[i__ - 1] = jpsv;
419
if ((d__1 = t16[i__ + (i__ << 2) - 5], abs(d__1)) < smin) {
421
t16[i__ + (i__ << 2) - 5] = smin;
423
for (j = i__ + 1; j <= 4; ++j) {
424
t16[j + (i__ << 2) - 5] /= t16[i__ + (i__ << 2) - 5];
425
btmp[j - 1] -= t16[j + (i__ << 2) - 5] * btmp[i__ - 1];
426
for (k = i__ + 1; k <= 4; ++k) {
427
t16[j + (k << 2) - 5] -= t16[j + (i__ << 2) - 5] * t16[i__ + (
435
if (abs(t16[15]) < smin) {
439
if (smlnum * 8. * abs(btmp[0]) > abs(t16[0]) || smlnum * 8. * abs(btmp[1])
440
> abs(t16[5]) || smlnum * 8. * abs(btmp[2]) > abs(t16[10]) ||
441
smlnum * 8. * abs(btmp[3]) > abs(t16[15])) {
443
d__1 = abs(btmp[0]), d__2 = abs(btmp[1]), d__1 = max(d__1,d__2), d__2
444
= abs(btmp[2]), d__1 = max(d__1,d__2), d__2 = abs(btmp[3]);
445
*scale = .125 / max(d__1,d__2);
451
for (i__ = 1; i__ <= 4; ++i__) {
453
temp = 1. / t16[k + (k << 2) - 5];
454
tmp[k - 1] = btmp[k - 1] * temp;
455
for (j = k + 1; j <= 4; ++j) {
456
tmp[k - 1] -= temp * t16[k + (j << 2) - 5] * tmp[j - 1];
461
for (i__ = 1; i__ <= 3; ++i__) {
462
if (jpiv[4 - i__ - 1] != 4 - i__) {
463
temp = tmp[4 - i__ - 1];
464
tmp[4 - i__ - 1] = tmp[jpiv[4 - i__ - 1] - 1];
465
tmp[jpiv[4 - i__ - 1] - 1] = temp;
469
x[x_dim1 + 1] = tmp[0];
470
x[x_dim1 + 2] = tmp[1];
471
x[(x_dim1 << 1) + 1] = tmp[2];
472
x[(x_dim1 << 1) + 2] = tmp[3];
474
d__1 = abs(tmp[0]) + abs(tmp[2]), d__2 = abs(tmp[1]) + abs(tmp[3]);
475
*xnorm = max(d__1,d__2);
480
} /* igraphdlasy2_ */