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

« back to all changes in this revision

Viewing changes to scipy/linsolve/SuperLU/SRC/clangs.c

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik
  • Date: 2008-06-16 22:58:01 UTC
  • mfrom: (2.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616225801-irdhrpcwiocfbcmt
Tags: 0.6.0-12
* The description updated to match the current SciPy (Closes: #489149).
* Standards-Version bumped to 3.8.0 (no action needed)
* Build-Depends: netcdf-dev changed to libnetcdf-dev

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:   clangs.c
 
12
 * History:     Modified from lapack routine CLANGE
 
13
 */
 
14
#include <math.h>
 
15
#include "csp_defs.h"
 
16
#include "util.h"
 
17
 
 
18
float clangs(char *norm, SuperMatrix *A)
 
19
{
 
20
/* 
 
21
    Purpose   
 
22
    =======   
 
23
 
 
24
    CLANGS returns the value of the one norm, or the Frobenius norm, or 
 
25
    the infinity norm, or the element of largest absolute value of a 
 
26
    real matrix A.   
 
27
 
 
28
    Description   
 
29
    ===========   
 
30
 
 
31
    CLANGE returns the value   
 
32
 
 
33
       CLANGE = ( max(abs(A(i,j))), NORM = 'M' or 'm'   
 
34
                (   
 
35
                ( norm1(A),         NORM = '1', 'O' or 'o'   
 
36
                (   
 
37
                ( normI(A),         NORM = 'I' or 'i'   
 
38
                (   
 
39
                ( normF(A),         NORM = 'F', 'f', 'E' or 'e'   
 
40
 
 
41
    where  norm1  denotes the  one norm of a matrix (maximum column sum), 
 
42
    normI  denotes the  infinity norm  of a matrix  (maximum row sum) and 
 
43
    normF  denotes the  Frobenius norm of a matrix (square root of sum of 
 
44
    squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.   
 
45
 
 
46
    Arguments   
 
47
    =========   
 
48
 
 
49
    NORM    (input) CHARACTER*1   
 
50
            Specifies the value to be returned in CLANGE as described above.   
 
51
    A       (input) SuperMatrix*
 
52
            The M by N sparse matrix A. 
 
53
 
 
54
   ===================================================================== 
 
55
*/
 
56
    
 
57
    /* Local variables */
 
58
    NCformat *Astore;
 
59
    complex   *Aval;
 
60
    int      i, j, irow;
 
61
    float   value, sum;
 
62
    float   *rwork;
 
63
 
 
64
    Astore = A->Store;
 
65
    Aval   = Astore->nzval;
 
66
    
 
67
    if ( SUPERLU_MIN(A->nrow, A->ncol) == 0) {
 
68
        value = 0.;
 
69
        
 
70
    } else if (lsame_(norm, "M")) {
 
71
        /* Find max(abs(A(i,j))). */
 
72
        value = 0.;
 
73
        for (j = 0; j < A->ncol; ++j)
 
74
            for (i = Astore->colptr[j]; i < Astore->colptr[j+1]; i++)
 
75
                value = SUPERLU_MAX( value, c_abs( &Aval[i]) );
 
76
        
 
77
    } else if (lsame_(norm, "O") || *(unsigned char *)norm == '1') {
 
78
        /* Find norm1(A). */
 
79
        value = 0.;
 
80
        for (j = 0; j < A->ncol; ++j) {
 
81
            sum = 0.;
 
82
            for (i = Astore->colptr[j]; i < Astore->colptr[j+1]; i++) 
 
83
                sum += c_abs( &Aval[i] );
 
84
            value = SUPERLU_MAX(value,sum);
 
85
        }
 
86
        
 
87
    } else if (lsame_(norm, "I")) {
 
88
        /* Find normI(A). */
 
89
        if ( !(rwork = (float *) SUPERLU_MALLOC(A->nrow * sizeof(float))) )
 
90
            ABORT("SUPERLU_MALLOC fails for rwork.");
 
91
        for (i = 0; i < A->nrow; ++i) rwork[i] = 0.;
 
92
        for (j = 0; j < A->ncol; ++j)
 
93
            for (i = Astore->colptr[j]; i < Astore->colptr[j+1]; i++) {
 
94
                irow = Astore->rowind[i];
 
95
                rwork[irow] += c_abs( &Aval[i] );
 
96
            }
 
97
        value = 0.;
 
98
        for (i = 0; i < A->nrow; ++i)
 
99
            value = SUPERLU_MAX(value, rwork[i]);
 
100
        
 
101
        SUPERLU_FREE (rwork);
 
102
        
 
103
    } else if (lsame_(norm, "F") || lsame_(norm, "E")) {
 
104
        /* Find normF(A). */
 
105
        ABORT("Not implemented.");
 
106
    } else
 
107
        ABORT("Illegal norm specified.");
 
108
 
 
109
    return (value);
 
110
 
 
111
} /* clangs */
 
112