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
/* Subroutine */ int igraphdlaln2_(logical *ltrans, integer *na, integer *nw,
18
doublereal *smin, doublereal *ca, doublereal *a, integer *lda,
19
doublereal *d1, doublereal *d2, doublereal *b, integer *ldb,
20
doublereal *wr, doublereal *wi, doublereal *x, integer *ldx,
21
doublereal *scale, doublereal *xnorm, integer *info)
23
/* Initialized data */
25
static logical zswap[4] = { FALSE_,FALSE_,TRUE_,TRUE_ };
26
static logical rswap[4] = { FALSE_,TRUE_,FALSE_,TRUE_ };
27
static integer ipivot[16] /* was [4][4] */ = { 1,2,3,4,2,1,4,3,3,4,1,2,
30
/* System generated locals */
31
integer a_dim1, a_offset, b_dim1, b_offset, x_dim1, x_offset;
32
doublereal d__1, d__2, d__3, d__4, d__5, d__6;
33
static doublereal equiv_0[4], equiv_1[4];
39
static doublereal bi1, bi2, br1, br2, xi1, xi2, xr1, xr2, ci21, ci22,
40
cr21, cr22, li21, csi, ui11, lr21, ui12, ui22;
42
static doublereal csr, ur11, ur12, ur22;
44
static doublereal bbnd, cmax, ui11r, ui12s, temp, ur11r, ur12s, u22abs;
46
static doublereal bnorm, cnorm, smini;
47
extern doublereal igraphdlamch_(char *);
48
extern /* Subroutine */ int igraphdladiv_(doublereal *, doublereal *,
49
doublereal *, doublereal *, doublereal *, doublereal *);
50
static doublereal bignum, smlnum;
53
/* -- LAPACK auxiliary routine (version 3.0) -- */
54
/* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */
55
/* Courant Institute, Argonne National Lab, and Rice University */
56
/* October 31, 1992 */
58
/* .. Scalar Arguments .. */
60
/* .. Array Arguments .. */
66
/* DLALN2 solves a system of the form (ca A - w D ) X = s B */
67
/* or (ca A' - w D) X = s B with possible scaling ("s") and */
68
/* perturbation of A. (A' means A-transpose.) */
70
/* A is an NA x NA real matrix, ca is a real scalar, D is an NA x NA */
71
/* real diagonal matrix, w is a real or complex value, and X and B are */
72
/* NA x 1 matrices -- real if w is real, complex if w is complex. NA */
75
/* If w is complex, X and B are represented as NA x 2 matrices, */
76
/* the first column of each being the real part and the second */
77
/* being the imaginary part. */
79
/* "s" is a scaling factor (.LE. 1), computed by DLALN2, which is */
80
/* so chosen that X can be computed without overflow. X is further */
81
/* scaled if necessary to assure that norm(ca A - w D)*norm(X) is less */
84
/* If both singular values of (ca A - w D) are less than SMIN, */
85
/* SMIN*identity will be used instead of (ca A - w D). If only one */
86
/* singular value is less than SMIN, one element of (ca A - w D) will be */
87
/* perturbed enough to make the smallest singular value roughly SMIN. */
88
/* If both singular values are at least SMIN, (ca A - w D) will not be */
89
/* perturbed. In any case, the perturbation will be at most some small */
90
/* multiple of max( SMIN, ulp*norm(ca A - w D) ). The singular values */
91
/* are computed by infinity-norm approximations, and thus will only be */
92
/* correct to a factor of 2 or so. */
94
/* Note: all input quantities are assumed to be smaller than overflow */
95
/* by a reasonable factor. (See BIGNUM.) */
100
/* LTRANS (input) LOGICAL */
101
/* =.TRUE.: A-transpose will be used. */
102
/* =.FALSE.: A will be used (not transposed.) */
104
/* NA (input) INTEGER */
105
/* The size of the matrix A. It may (only) be 1 or 2. */
107
/* NW (input) INTEGER */
108
/* 1 if "w" is real, 2 if "w" is complex. It may only be 1 */
111
/* SMIN (input) DOUBLE PRECISION */
112
/* The desired lower bound on the singular values of A. This */
113
/* should be a safe distance away from underflow or overflow, */
114
/* say, between (underflow/machine precision) and (machine */
115
/* precision * overflow ). (See BIGNUM and ULP.) */
117
/* CA (input) DOUBLE PRECISION */
118
/* The coefficient c, which A is multiplied by. */
120
/* A (input) DOUBLE PRECISION array, dimension (LDA,NA) */
121
/* The NA x NA matrix A. */
123
/* LDA (input) INTEGER */
124
/* The leading dimension of A. It must be at least NA. */
126
/* D1 (input) DOUBLE PRECISION */
127
/* The 1,1 element in the diagonal matrix D. */
129
/* D2 (input) DOUBLE PRECISION */
130
/* The 2,2 element in the diagonal matrix D. Not used if NW=1. */
132
/* B (input) DOUBLE PRECISION array, dimension (LDB,NW) */
133
/* The NA x NW matrix B (right-hand side). If NW=2 ("w" is */
134
/* complex), column 1 contains the real part of B and column 2 */
135
/* contains the imaginary part. */
137
/* LDB (input) INTEGER */
138
/* The leading dimension of B. It must be at least NA. */
140
/* WR (input) DOUBLE PRECISION */
141
/* The real part of the scalar "w". */
143
/* WI (input) DOUBLE PRECISION */
144
/* The imaginary part of the scalar "w". Not used if NW=1. */
146
/* X (output) DOUBLE PRECISION array, dimension (LDX,NW) */
147
/* The NA x NW matrix X (unknowns), as computed by DLALN2. */
148
/* If NW=2 ("w" is complex), on exit, column 1 will contain */
149
/* the real part of X and column 2 will contain the imaginary */
152
/* LDX (input) INTEGER */
153
/* The leading dimension of X. It must be at least NA. */
155
/* SCALE (output) DOUBLE PRECISION */
156
/* The scale factor that B must be multiplied by to insure */
157
/* that overflow does not occur when computing X. Thus, */
158
/* (ca A - w D) X will be SCALE*B, not B (ignoring */
159
/* perturbations of A.) It will be at most 1. */
161
/* XNORM (output) DOUBLE PRECISION */
162
/* The infinity-norm of X, when X is regarded as an NA x NW */
165
/* INFO (output) INTEGER */
166
/* An error flag. It will be set to zero if no error occurs, */
167
/* a negative number if an argument is in error, or a positive */
168
/* number if ca A - w D had to be perturbed. */
169
/* The possible values are: */
170
/* = 0: No error occurred, and (ca A - w D) did not have to be */
172
/* = 1: (ca A - w D) had to be perturbed to make its smallest */
173
/* (or only) singular value greater than SMIN. */
174
/* NOTE: In the interests of speed, this routine does not */
175
/* check the inputs for errors. */
177
/* ===================================================================== */
179
/* .. Parameters .. */
181
/* .. Local Scalars .. */
183
/* .. Local Arrays .. */
185
/* .. External Functions .. */
187
/* .. External Subroutines .. */
189
/* .. Intrinsic Functions .. */
191
/* .. Equivalences .. */
193
/* .. Data statements .. */
194
/* Parameter adjustments */
196
a_offset = 1 + a_dim1;
199
b_offset = 1 + b_dim1;
202
x_offset = 1 + x_dim1;
207
/* .. Executable Statements .. */
211
smlnum = 2. * igraphdlamch_("Safe minimum");
212
bignum = 1. / smlnum;
213
smini = max(*smin,smlnum);
215
/* Don't check for input errors */
219
/* Standard Initializations */
225
/* 1 x 1 (i.e., scalar) system C X = B */
229
/* Real 1x1 system. */
233
csr = *ca * a[a_dim1 + 1] - *wr * *d1;
236
/* If | C | < SMINI, use C = SMINI */
244
/* Check scaling for X = B / C */
246
bnorm = (d__1 = b[b_dim1 + 1], abs(d__1));
247
if (cnorm < 1. && bnorm > 1.) {
248
if (bnorm > bignum * cnorm) {
255
x[x_dim1 + 1] = b[b_dim1 + 1] * *scale / csr;
256
*xnorm = (d__1 = x[x_dim1 + 1], abs(d__1));
259
/* Complex 1x1 system (w is complex) */
263
csr = *ca * a[a_dim1 + 1] - *wr * *d1;
265
cnorm = abs(csr) + abs(csi);
267
/* If | C | < SMINI, use C = SMINI */
276
/* Check scaling for X = B / C */
278
bnorm = (d__1 = b[b_dim1 + 1], abs(d__1)) + (d__2 = b[(b_dim1 <<
280
if (cnorm < 1. && bnorm > 1.) {
281
if (bnorm > bignum * cnorm) {
288
d__1 = *scale * b[b_dim1 + 1];
289
d__2 = *scale * b[(b_dim1 << 1) + 1];
290
igraphdladiv_(&d__1, &d__2, &csr, &csi, &x[x_dim1 + 1], &x[(x_dim1 << 1)
292
*xnorm = (d__1 = x[x_dim1 + 1], abs(d__1)) + (d__2 = x[(x_dim1 <<
300
/* Compute the real part of C = ca A - w D (or ca A' - w D ) */
302
cr[0] = *ca * a[a_dim1 + 1] - *wr * *d1;
303
cr[3] = *ca * a[(a_dim1 << 1) + 2] - *wr * *d2;
305
cr[2] = *ca * a[a_dim1 + 2];
306
cr[1] = *ca * a[(a_dim1 << 1) + 1];
308
cr[1] = *ca * a[a_dim1 + 2];
309
cr[2] = *ca * a[(a_dim1 << 1) + 1];
314
/* Real 2x2 system (w is real) */
316
/* Find the largest element in C */
321
for (j = 1; j <= 4; ++j) {
322
if ((d__1 = crv[j - 1], abs(d__1)) > cmax) {
323
cmax = (d__1 = crv[j - 1], abs(d__1));
329
/* If norm(C) < SMINI, use SMINI*identity. */
333
d__3 = (d__1 = b[b_dim1 + 1], abs(d__1)), d__4 = (d__2 = b[
334
b_dim1 + 2], abs(d__2));
335
bnorm = max(d__3,d__4);
336
if (smini < 1. && bnorm > 1.) {
337
if (bnorm > bignum * smini) {
341
temp = *scale / smini;
342
x[x_dim1 + 1] = temp * b[b_dim1 + 1];
343
x[x_dim1 + 2] = temp * b[b_dim1 + 2];
344
*xnorm = temp * bnorm;
349
/* Gaussian elimination with complete pivoting. */
351
ur11 = crv[icmax - 1];
352
cr21 = crv[ipivot[(icmax << 2) - 3] - 1];
353
ur12 = crv[ipivot[(icmax << 2) - 2] - 1];
354
cr22 = crv[ipivot[(icmax << 2) - 1] - 1];
357
ur22 = cr22 - ur12 * lr21;
359
/* If smaller pivot < SMINI, use SMINI */
361
if (abs(ur22) < smini) {
365
if (rswap[icmax - 1]) {
374
d__2 = (d__1 = br1 * (ur22 * ur11r), abs(d__1)), d__3 = abs(br2);
375
bbnd = max(d__2,d__3);
376
if (bbnd > 1. && abs(ur22) < 1.) {
377
if (bbnd >= bignum * abs(ur22)) {
382
xr2 = br2 * *scale / ur22;
383
xr1 = *scale * br1 * ur11r - xr2 * (ur11r * ur12);
384
if (zswap[icmax - 1]) {
392
d__1 = abs(xr1), d__2 = abs(xr2);
393
*xnorm = max(d__1,d__2);
395
/* Further scaling if norm(A) norm(X) > overflow */
397
if (*xnorm > 1. && cmax > 1.) {
398
if (*xnorm > bignum / cmax) {
399
temp = cmax / bignum;
400
x[x_dim1 + 1] = temp * x[x_dim1 + 1];
401
x[x_dim1 + 2] = temp * x[x_dim1 + 2];
402
*xnorm = temp * *xnorm;
403
*scale = temp * *scale;
408
/* Complex 2x2 system (w is complex) */
410
/* Find the largest element in C */
412
ci[0] = -(*wi) * *d1;
415
ci[3] = -(*wi) * *d2;
419
for (j = 1; j <= 4; ++j) {
420
if ((d__1 = crv[j - 1], abs(d__1)) + (d__2 = civ[j - 1], abs(
422
cmax = (d__1 = crv[j - 1], abs(d__1)) + (d__2 = civ[j - 1]
429
/* If norm(C) < SMINI, use SMINI*identity. */
433
d__5 = (d__1 = b[b_dim1 + 1], abs(d__1)) + (d__2 = b[(b_dim1
434
<< 1) + 1], abs(d__2)), d__6 = (d__3 = b[b_dim1 + 2],
435
abs(d__3)) + (d__4 = b[(b_dim1 << 1) + 2], abs(d__4));
436
bnorm = max(d__5,d__6);
437
if (smini < 1. && bnorm > 1.) {
438
if (bnorm > bignum * smini) {
442
temp = *scale / smini;
443
x[x_dim1 + 1] = temp * b[b_dim1 + 1];
444
x[x_dim1 + 2] = temp * b[b_dim1 + 2];
445
x[(x_dim1 << 1) + 1] = temp * b[(b_dim1 << 1) + 1];
446
x[(x_dim1 << 1) + 2] = temp * b[(b_dim1 << 1) + 2];
447
*xnorm = temp * bnorm;
452
/* Gaussian elimination with complete pivoting. */
454
ur11 = crv[icmax - 1];
455
ui11 = civ[icmax - 1];
456
cr21 = crv[ipivot[(icmax << 2) - 3] - 1];
457
ci21 = civ[ipivot[(icmax << 2) - 3] - 1];
458
ur12 = crv[ipivot[(icmax << 2) - 2] - 1];
459
ui12 = civ[ipivot[(icmax << 2) - 2] - 1];
460
cr22 = crv[ipivot[(icmax << 2) - 1] - 1];
461
ci22 = civ[ipivot[(icmax << 2) - 1] - 1];
462
if (icmax == 1 || icmax == 4) {
464
/* Code when off-diagonals of pivoted C are real */
466
if (abs(ur11) > abs(ui11)) {
468
/* Computing 2nd power */
470
ur11r = 1. / (ur11 * (d__1 * d__1 + 1.));
471
ui11r = -temp * ur11r;
474
/* Computing 2nd power */
476
ui11r = -1. / (ui11 * (d__1 * d__1 + 1.));
477
ur11r = -temp * ui11r;
481
ur12s = ur12 * ur11r;
482
ui12s = ur12 * ui11r;
483
ur22 = cr22 - ur12 * lr21;
484
ui22 = ci22 - ur12 * li21;
487
/* Code when diagonals of pivoted C are real */
493
ur12s = ur12 * ur11r;
494
ui12s = ui12 * ur11r;
495
ur22 = cr22 - ur12 * lr21 + ui12 * li21;
496
ui22 = -ur12 * li21 - ui12 * lr21;
498
u22abs = abs(ur22) + abs(ui22);
500
/* If smaller pivot < SMINI, use SMINI */
502
if (u22abs < smini) {
507
if (rswap[icmax - 1]) {
510
bi2 = b[(b_dim1 << 1) + 1];
511
bi1 = b[(b_dim1 << 1) + 2];
515
bi1 = b[(b_dim1 << 1) + 1];
516
bi2 = b[(b_dim1 << 1) + 2];
518
br2 = br2 - lr21 * br1 + li21 * bi1;
519
bi2 = bi2 - li21 * br1 - lr21 * bi1;
521
d__1 = (abs(br1) + abs(bi1)) * (u22abs * (abs(ur11r) + abs(ui11r))
522
), d__2 = abs(br2) + abs(bi2);
523
bbnd = max(d__1,d__2);
524
if (bbnd > 1. && u22abs < 1.) {
525
if (bbnd >= bignum * u22abs) {
534
igraphdladiv_(&br2, &bi2, &ur22, &ui22, &xr2, &xi2);
535
xr1 = ur11r * br1 - ui11r * bi1 - ur12s * xr2 + ui12s * xi2;
536
xi1 = ui11r * br1 + ur11r * bi1 - ui12s * xr2 - ur12s * xi2;
537
if (zswap[icmax - 1]) {
540
x[(x_dim1 << 1) + 1] = xi2;
541
x[(x_dim1 << 1) + 2] = xi1;
545
x[(x_dim1 << 1) + 1] = xi1;
546
x[(x_dim1 << 1) + 2] = xi2;
549
d__1 = abs(xr1) + abs(xi1), d__2 = abs(xr2) + abs(xi2);
550
*xnorm = max(d__1,d__2);
552
/* Further scaling if norm(A) norm(X) > overflow */
554
if (*xnorm > 1. && cmax > 1.) {
555
if (*xnorm > bignum / cmax) {
556
temp = cmax / bignum;
557
x[x_dim1 + 1] = temp * x[x_dim1 + 1];
558
x[x_dim1 + 2] = temp * x[x_dim1 + 2];
559
x[(x_dim1 << 1) + 1] = temp * x[(x_dim1 << 1) + 1];
560
x[(x_dim1 << 1) + 2] = temp * x[(x_dim1 << 1) + 2];
561
*xnorm = temp * *xnorm;
562
*scale = temp * *scale;
572
} /* igraphdlaln2_ */