4
* -- SuperLU routine (version 2.0) --
5
* Univ. of California Berkeley, Xerox Palo Alto Research Center,
6
* and Lawrence Berkeley National Lab.
12
* History: Modified from LAPACK routine SGEEQU
19
sgsequ(SuperMatrix *A, float *r, float *c, float *rowcnd,
20
float *colcnd, float *amax, int *info)
26
SGSEQU computes row and column scalings intended to equilibrate an
27
M-by-N sparse matrix A and reduce its condition number. R returns the row
28
scale factors and C the column scale factors, chosen to try to make
29
the largest element in each row and column of the matrix B with
30
elements B(i,j)=R(i)*A(i,j)*C(j) have absolute value 1.
32
R(i) and C(j) are restricted to be between SMLNUM = smallest safe
33
number and BIGNUM = largest safe number. Use of these scaling
34
factors is not guaranteed to reduce the condition number of A but
35
works well in practice.
37
See supermatrix.h for the definition of 'SuperMatrix' structure.
42
A (input) SuperMatrix*
43
The matrix of dimension (A->nrow, A->ncol) whose equilibration
44
factors are to be computed. The type of A can be:
45
Stype = NC; Dtype = S_; Mtype = GE.
47
R (output) float*, size A->nrow
48
If INFO = 0 or INFO > M, R contains the row scale factors
51
C (output) float*, size A->ncol
52
If INFO = 0, C contains the column scale factors for A.
54
ROWCND (output) float*
55
If INFO = 0 or INFO > M, ROWCND contains the ratio of the
56
smallest R(i) to the largest R(i). If ROWCND >= 0.1 and
57
AMAX is neither too large nor too small, it is not worth
60
COLCND (output) float*
61
If INFO = 0, COLCND contains the ratio of the smallest
62
C(i) to the largest C(i). If COLCND >= 0.1, it is not
66
Absolute value of largest matrix element. If AMAX is very
67
close to overflow or very close to underflow, the matrix
72
< 0: if INFO = -i, the i-th argument had an illegal value
73
> 0: if INFO = i, and i is
74
<= A->nrow: the i-th row of A is exactly zero
75
> A->ncol: the (i-M)-th column of A is exactly zero
77
=====================================================================
86
extern double slamch_(char *);
88
/* Test the input parameters. */
90
if ( A->nrow < 0 || A->ncol < 0 ||
91
A->Stype != NC || A->Dtype != S_ || A->Mtype != GE )
95
xerbla_("sgsequ", &i);
99
/* Quick return if possible */
100
if ( A->nrow == 0 || A->ncol == 0 ) {
108
Aval = Astore->nzval;
110
/* Get machine constants. */
111
smlnum = slamch_("S");
112
bignum = 1. / smlnum;
114
/* Compute row scale factors. */
115
for (i = 0; i < A->nrow; ++i) r[i] = 0.;
117
/* Find the maximum element in each row. */
118
for (j = 0; j < A->ncol; ++j)
119
for (i = Astore->colptr[j]; i < Astore->colptr[j+1]; ++i) {
120
irow = Astore->rowind[i];
121
r[irow] = SUPERLU_MAX( r[irow], fabs(Aval[i]) );
124
/* Find the maximum and minimum scale factors. */
127
for (i = 0; i < A->nrow; ++i) {
128
rcmax = SUPERLU_MAX(rcmax, r[i]);
129
rcmin = SUPERLU_MIN(rcmin, r[i]);
134
/* Find the first zero scale factor and return an error code. */
135
for (i = 0; i < A->nrow; ++i)
141
/* Invert the scale factors. */
142
for (i = 0; i < A->nrow; ++i)
143
r[i] = 1. / SUPERLU_MIN( SUPERLU_MAX( r[i], smlnum ), bignum );
144
/* Compute ROWCND = min(R(I)) / max(R(I)) */
145
*rowcnd = SUPERLU_MAX( rcmin, smlnum ) / SUPERLU_MIN( rcmax, bignum );
148
/* Compute column scale factors */
149
for (j = 0; j < A->ncol; ++j) c[j] = 0.;
151
/* Find the maximum element in each column, assuming the row
152
scalings computed above. */
153
for (j = 0; j < A->ncol; ++j)
154
for (i = Astore->colptr[j]; i < Astore->colptr[j+1]; ++i) {
155
irow = Astore->rowind[i];
156
c[j] = SUPERLU_MAX( c[j], fabs(Aval[i]) * r[irow] );
159
/* Find the maximum and minimum scale factors. */
162
for (j = 0; j < A->ncol; ++j) {
163
rcmax = SUPERLU_MAX(rcmax, c[j]);
164
rcmin = SUPERLU_MIN(rcmin, c[j]);
168
/* Find the first zero scale factor and return an error code. */
169
for (j = 0; j < A->ncol; ++j)
171
*info = A->nrow + j + 1;
175
/* Invert the scale factors. */
176
for (j = 0; j < A->ncol; ++j)
177
c[j] = 1. / SUPERLU_MIN( SUPERLU_MAX( c[j], smlnum ), bignum);
178
/* Compute COLCND = min(C(J)) / max(C(J)) */
179
*colcnd = SUPERLU_MAX( rcmin, smlnum ) / SUPERLU_MIN( rcmax, bignum );