~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to Lib/sparse/SuperLU/SRC/claqgs.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T. Chen (new)
  • Date: 2005-03-16 02:15:29 UTC
  • Revision ID: james.westby@ubuntu.com-20050316021529-xrjlowsejs0cijig
Tags: upstream-0.3.2
ImportĀ upstreamĀ versionĀ 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
/*
 
4
 * -- SuperLU routine (version 2.0) --
 
5
 * Univ. of California Berkeley, Xerox Palo Alto Research Center,
 
6
 * and Lawrence Berkeley National Lab.
 
7
 * November 15, 1997
 
8
 *
 
9
 */
 
10
/*
 
11
 * File name:   claqgs.c
 
12
 * History:     Modified from LAPACK routine CLAQGE
 
13
 */
 
14
#include <math.h>
 
15
#include "csp_defs.h"
 
16
#include "util.h"
 
17
 
 
18
void
 
19
claqgs(SuperMatrix *A, float *r, float *c, 
 
20
        float rowcnd, float colcnd, float amax, char *equed)
 
21
{
 
22
/*
 
23
    Purpose   
 
24
    =======   
 
25
 
 
26
    CLAQGS equilibrates a general sparse M by N matrix A using the row and   
 
27
    scaling factors in the vectors R and C.   
 
28
 
 
29
    See supermatrix.h for the definition of 'SuperMatrix' structure.
 
30
 
 
31
    Arguments   
 
32
    =========   
 
33
 
 
34
    A       (input/output) SuperMatrix*
 
35
            On exit, the equilibrated matrix.  See EQUED for the form of 
 
36
            the equilibrated matrix. The type of A can be:
 
37
            Stype = NC; Dtype = SLU_C; Mtype = GE.
 
38
            
 
39
    R       (input) float*, dimension (A->nrow)
 
40
            The row scale factors for A.
 
41
            
 
42
    C       (input) float*, dimension (A->ncol)
 
43
            The column scale factors for A.
 
44
            
 
45
    ROWCND  (input) float
 
46
            Ratio of the smallest R(i) to the largest R(i).
 
47
            
 
48
    COLCND  (input) float
 
49
            Ratio of the smallest C(i) to the largest C(i).
 
50
            
 
51
    AMAX    (input) float
 
52
            Absolute value of largest matrix entry.
 
53
            
 
54
    EQUED   (output) char*
 
55
            Specifies the form of equilibration that was done.   
 
56
            = 'N':  No equilibration   
 
57
            = 'R':  Row equilibration, i.e., A has been premultiplied by  
 
58
                    diag(R).   
 
59
            = 'C':  Column equilibration, i.e., A has been postmultiplied  
 
60
                    by diag(C).   
 
61
            = 'B':  Both row and column equilibration, i.e., A has been
 
62
                    replaced by diag(R) * A * diag(C).   
 
63
 
 
64
    Internal Parameters   
 
65
    ===================   
 
66
 
 
67
    THRESH is a threshold value used to decide if row or column scaling   
 
68
    should be done based on the ratio of the row or column scaling   
 
69
    factors.  If ROWCND < THRESH, row scaling is done, and if   
 
70
    COLCND < THRESH, column scaling is done.   
 
71
 
 
72
    LARGE and SMALL are threshold values used to decide if row scaling   
 
73
    should be done based on the absolute size of the largest matrix   
 
74
    element.  If AMAX > LARGE or AMAX < SMALL, row scaling is done.   
 
75
 
 
76
    ===================================================================== 
 
77
*/
 
78
 
 
79
#define THRESH    (0.1)
 
80
    
 
81
    /* Local variables */
 
82
    NCformat *Astore;
 
83
    complex   *Aval;
 
84
    int i, j, irow;
 
85
    float large, small, cj;
 
86
    extern double slamch_(char *);
 
87
    float temp;
 
88
 
 
89
 
 
90
    /* Quick return if possible */
 
91
    if (A->nrow <= 0 || A->ncol <= 0) {
 
92
        *(unsigned char *)equed = 'N';
 
93
        return;
 
94
    }
 
95
 
 
96
    Astore = A->Store;
 
97
    Aval = Astore->nzval;
 
98
    
 
99
    /* Initialize LARGE and SMALL. */
 
100
    small = slamch_("Safe minimum") / slamch_("Precision");
 
101
    large = 1. / small;
 
102
 
 
103
    if (rowcnd >= THRESH && amax >= small && amax <= large) {
 
104
        if (colcnd >= THRESH)
 
105
            *(unsigned char *)equed = 'N';
 
106
        else {
 
107
            /* Column scaling */
 
108
            for (j = 0; j < A->ncol; ++j) {
 
109
                cj = c[j];
 
110
                for (i = Astore->colptr[j]; i < Astore->colptr[j+1]; ++i) {
 
111
                    cs_mult(&Aval[i], &Aval[i], cj);
 
112
                }
 
113
            }
 
114
            *(unsigned char *)equed = 'C';
 
115
        }
 
116
    } else if (colcnd >= THRESH) {
 
117
        /* Row scaling, no column scaling */
 
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
                cs_mult(&Aval[i], &Aval[i], r[irow]);
 
122
            }
 
123
        *(unsigned char *)equed = 'R';
 
124
    } else {
 
125
        /* Row and column scaling */
 
126
        for (j = 0; j < A->ncol; ++j) {
 
127
            cj = c[j];
 
128
            for (i = Astore->colptr[j]; i < Astore->colptr[j+1]; ++i) {
 
129
                irow = Astore->rowind[i];
 
130
                temp = cj * r[irow];
 
131
                cs_mult(&Aval[i], &Aval[i], temp);
 
132
            }
 
133
        }
 
134
        *(unsigned char *)equed = 'B';
 
135
    }
 
136
 
 
137
    return;
 
138
 
 
139
} /* claqgs */
 
140