|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*! @file slangs.c
|
|
kusano |
7d535a |
* \brief Returns the value of the one norm
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* -- SuperLU routine (version 2.0) --
|
|
kusano |
7d535a |
* Univ. of California Berkeley, Xerox Palo Alto Research Center,
|
|
kusano |
7d535a |
* and Lawrence Berkeley National Lab.
|
|
kusano |
7d535a |
* November 15, 1997
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* Modified from lapack routine SLANGE
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* File name: slangs.c
|
|
kusano |
7d535a |
* History: Modified from lapack routine SLANGE
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
#include <math.h></math.h>
|
|
kusano |
7d535a |
#include "slu_sdefs.h"
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*! \brief
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* Purpose
|
|
kusano |
7d535a |
* =======
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* SLANGS returns the value of the one norm, or the Frobenius norm, or
|
|
kusano |
7d535a |
* the infinity norm, or the element of largest absolute value of a
|
|
kusano |
7d535a |
* real matrix A.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* Description
|
|
kusano |
7d535a |
* ===========
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* SLANGE returns the value
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* SLANGE = ( max(abs(A(i,j))), NORM = 'M' or 'm'
|
|
kusano |
7d535a |
* (
|
|
kusano |
7d535a |
* ( norm1(A), NORM = '1', 'O' or 'o'
|
|
kusano |
7d535a |
* (
|
|
kusano |
7d535a |
* ( normI(A), NORM = 'I' or 'i'
|
|
kusano |
7d535a |
* (
|
|
kusano |
7d535a |
* ( normF(A), NORM = 'F', 'f', 'E' or 'e'
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* where norm1 denotes the one norm of a matrix (maximum column sum),
|
|
kusano |
7d535a |
* normI denotes the infinity norm of a matrix (maximum row sum) and
|
|
kusano |
7d535a |
* normF denotes the Frobenius norm of a matrix (square root of sum of
|
|
kusano |
7d535a |
* squares). Note that max(abs(A(i,j))) is not a matrix norm.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* Arguments
|
|
kusano |
7d535a |
* =========
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* NORM (input) CHARACTER*1
|
|
kusano |
7d535a |
* Specifies the value to be returned in SLANGE as described above.
|
|
kusano |
7d535a |
* A (input) SuperMatrix*
|
|
kusano |
7d535a |
* The M by N sparse matrix A.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* =====================================================================
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
float slangs(char *norm, SuperMatrix *A)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Local variables */
|
|
kusano |
7d535a |
NCformat *Astore;
|
|
kusano |
7d535a |
float *Aval;
|
|
kusano |
7d535a |
int i, j, irow;
|
|
kusano |
7d535a |
float value, sum;
|
|
kusano |
7d535a |
float *rwork;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Astore = A->Store;
|
|
kusano |
7d535a |
Aval = Astore->nzval;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
if ( SUPERLU_MIN(A->nrow, A->ncol) == 0) {
|
|
kusano |
7d535a |
value = 0.;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
} else if (lsame_(norm, "M")) {
|
|
kusano |
7d535a |
/* Find max(abs(A(i,j))). */
|
|
kusano |
7d535a |
value = 0.;
|
|
kusano |
7d535a |
for (j = 0; j < A->ncol; ++j)
|
|
kusano |
7d535a |
for (i = Astore->colptr[j]; i < Astore->colptr[j+1]; i++)
|
|
kusano |
7d535a |
value = SUPERLU_MAX( value, fabs( Aval[i]) );
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
} else if (lsame_(norm, "O") || *(unsigned char *)norm == '1') {
|
|
kusano |
7d535a |
/* Find norm1(A). */
|
|
kusano |
7d535a |
value = 0.;
|
|
kusano |
7d535a |
for (j = 0; j < A->ncol; ++j) {
|
|
kusano |
7d535a |
sum = 0.;
|
|
kusano |
7d535a |
for (i = Astore->colptr[j]; i < Astore->colptr[j+1]; i++)
|
|
kusano |
7d535a |
sum += fabs(Aval[i]);
|
|
kusano |
7d535a |
value = SUPERLU_MAX(value,sum);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
} else if (lsame_(norm, "I")) {
|
|
kusano |
7d535a |
/* Find normI(A). */
|
|
kusano |
7d535a |
if ( !(rwork = (float *) SUPERLU_MALLOC(A->nrow * sizeof(float))) )
|
|
kusano |
7d535a |
ABORT("SUPERLU_MALLOC fails for rwork.");
|
|
kusano |
7d535a |
for (i = 0; i < A->nrow; ++i) rwork[i] = 0.;
|
|
kusano |
7d535a |
for (j = 0; j < A->ncol; ++j)
|
|
kusano |
7d535a |
for (i = Astore->colptr[j]; i < Astore->colptr[j+1]; i++) {
|
|
kusano |
7d535a |
irow = Astore->rowind[i];
|
|
kusano |
7d535a |
rwork[irow] += fabs(Aval[i]);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
value = 0.;
|
|
kusano |
7d535a |
for (i = 0; i < A->nrow; ++i)
|
|
kusano |
7d535a |
value = SUPERLU_MAX(value, rwork[i]);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
SUPERLU_FREE (rwork);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
} else if (lsame_(norm, "F") || lsame_(norm, "E")) {
|
|
kusano |
7d535a |
/* Find normF(A). */
|
|
kusano |
7d535a |
ABORT("Not implemented.");
|
|
kusano |
7d535a |
} else
|
|
kusano |
7d535a |
ABORT("Illegal norm specified.");
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
return (value);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
} /* slangs */
|
|
kusano |
7d535a |
|