unify MatrixPtr

This commit is contained in:
dwarning 2023-06-07 00:12:44 +02:00
parent 61ecbbaecf
commit db7b9ecae4
9 changed files with 227 additions and 247 deletions

View File

@ -57,53 +57,64 @@
*/
/* Begin error macros. */
#define spOKAY 0 /*!<
* Error code that indicates that no error has
* occurred.
*/
#define spSMALL_PIVOT 1 /*!<
* Non-fatal error code that indicates that, when
* reordering the matrix, no element was found that
* satisfies the absolute threshold criteria. The
* largest element in the matrix was chosen as pivot.
*/
#define spZERO_DIAG 2 /*!<
* Fatal error code that indicates that, a zero was
* encountered on the diagonal the matrix. This does
* not necessarily imply that the matrix is singular.
* When this error occurs, the matrix should be
* reconstructed and factored using
* spOrderAndFactor().
*/
#define spSINGULAR 3 /*!<
* Fatal error code that indicates that, matrix is
* singular, so no unique solution exists.
*/
#define spMANGLED 4 /*!<
* Fatal error code that indicates that, matrix has
* been mangled, results of requested operation are
* garbage.
*/
#define spNO_MEMORY 5 /*!<
* Fatal error code that indicates that not enough
* memory is available.
*/
#define spPANIC 6 /*!<
* Fatal error code that indicates that the routines
* are not prepared to handle the matrix that has
* been requested. This may occur when the matrix
* is specified to be real and the routines are not
* compiled for real matrices, or when the matrix is
* specified to be complex and the routines are not
* compiled to handle complex matrices.
*/
#define spFATAL 2 /*!<
* Error code that is not an error flag, but rather
* the dividing line between fatal errors and
* warnings.
*/
//#define spOKAY 0 /*!<
// * Error code that indicates that no error has
// * occurred.
// */
//#define spSMALL_PIVOT 1 /*!<
// * Non-fatal error code that indicates that, when
// * reordering the matrix, no element was found that
// * satisfies the absolute threshold criteria. The
// * largest element in the matrix was chosen as pivot.
// */
//#define spZERO_DIAG 2 /*!<
// * Fatal error code that indicates that, a zero was
// * encountered on the diagonal the matrix. This does
// * not necessarily imply that the matrix is singular.
// * When this error occurs, the matrix should be
// * reconstructed and factored using
// * spOrderAndFactor().
// */
//#define spSINGULAR 3 /*!<
// * Fatal error code that indicates that, matrix is
// * singular, so no unique solution exists.
// */
//#define spMANGLED 4 /*!<
// * Fatal error code that indicates that, matrix has
// * been mangled, results of requested operation are
// * garbage.
// */
//#define spNO_MEMORY 5 /*!<
// * Fatal error code that indicates that not enough
// * memory is available.
// */
//#define spPANIC 6 /*!<
// * Fatal error code that indicates that the routines
// * are not prepared to handle the matrix that has
// * been requested. This may occur when the matrix
// * is specified to be real and the routines are not
// * compiled for real matrices, or when the matrix is
// * specified to be complex and the routines are not
// * compiled to handle complex matrices.
// */
//#define spFATAL 2 /*!<
// * Error code that is not an error flag, but rather
// * the dividing line between fatal errors and
// * warnings.
// */
#include "ngspice/sperror.h" /* Spice error definitions. */
/* Begin error macros. */
#define spOKAY OK
#define spSMALL_PIVOT OK
#define spZERO_DIAG E_SINGULAR
#define spSINGULAR E_SINGULAR
#define spNO_MEMORY E_NOMEM
#define spPANIC E_BADMATRIX
#define spMANGLED E_BADMATRIX
#define spFATAL E_BADMATRIX
@ -289,6 +300,7 @@ struct spTemplate
typedef struct MatrixFrame *MatrixPtr;
/*
@ -299,78 +311,78 @@ struct spTemplate
/* Begin function declarations. */
spcEXTERN void spClear( spMatrix );
spcEXTERN spREAL spCondition( spMatrix, spREAL, int* );
spcEXTERN spMatrix spCreate( int, int, spError* );
spcEXTERN void spDeleteRowAndCol( spMatrix, int, int );
spcEXTERN void spDestroy( spMatrix );
spcEXTERN int spElementCount( spMatrix );
spcEXTERN int spOriginalCount( spMatrix );
spcEXTERN spError spErrorState( spMatrix );
spcEXTERN void spClear( MatrixPtr );
spcEXTERN spREAL spCondition( MatrixPtr, spREAL, int* );
spcEXTERN MatrixPtr spCreate( int, int, spError* );
spcEXTERN void spDeleteRowAndCol( MatrixPtr, int, int );
spcEXTERN void spDestroy( MatrixPtr );
spcEXTERN int spElementCount( MatrixPtr );
spcEXTERN int spOriginalCount( MatrixPtr );
spcEXTERN spError spErrorState( MatrixPtr );
#ifdef EOF
spcEXTERN void spErrorMessage( spMatrix, FILE*, char* );
spcEXTERN void spErrorMessage( MatrixPtr, FILE*, char* );
#else
# define spErrorMessage(a,b,c) spcFUNC_NEEDS_FILE(_spErrorMessage,stdio)
#endif
spcEXTERN spError spFactor( spMatrix );
spcEXTERN int spFileMatrix( spMatrix, char*, char*, int, int, int );
spcEXTERN int spFileStats( spMatrix, char*, char* );
spcEXTERN int spFillinCount( spMatrix );
spcEXTERN spElement *spFindElement( spMatrix, int, int );
spcEXTERN spError spGetAdmittance( spMatrix, int, int,
spcEXTERN spError spFactor( MatrixPtr );
spcEXTERN int spFileMatrix( MatrixPtr, char*, char*, int, int, int );
spcEXTERN int spFileStats( MatrixPtr, char*, char* );
spcEXTERN int spFillinCount( MatrixPtr );
spcEXTERN spElement *spFindElement( MatrixPtr, int, int );
spcEXTERN spError spGetAdmittance( MatrixPtr, int, int,
struct spTemplate* );
spcEXTERN spElement *spGetElement( spMatrix, int, int );
spcEXTERN spElement *spGetElement( MatrixPtr, int, int );
spcEXTERN spGenericPtr spGetInitInfo( spElement* );
spcEXTERN spError spGetOnes( spMatrix, int, int, int,
spcEXTERN spError spGetOnes( MatrixPtr, int, int, int,
struct spTemplate* );
spcEXTERN spError spGetQuad( spMatrix, int, int, int, int,
spcEXTERN spError spGetQuad( MatrixPtr, int, int, int, int,
struct spTemplate* );
spcEXTERN int spGetSize( spMatrix, int );
spcEXTERN int spInitialize( spMatrix, int (*pInit)(spElement *, spGenericPtr, int, int) );
spcEXTERN int spGetSize( MatrixPtr, int );
spcEXTERN int spInitialize( MatrixPtr, int (*pInit)(spElement *, spGenericPtr, int, int) );
spcEXTERN void spInstallInitInfo( spElement*, spGenericPtr );
spcEXTERN spREAL spLargestElement( spMatrix );
spcEXTERN void spMNA_Preorder( spMatrix );
spcEXTERN spREAL spNorm( spMatrix );
spcEXTERN spError spOrderAndFactor( spMatrix, spREAL[], spREAL,
spcEXTERN spREAL spLargestElement( MatrixPtr );
spcEXTERN void spMNA_Preorder( MatrixPtr );
spcEXTERN spREAL spNorm( MatrixPtr );
spcEXTERN spError spOrderAndFactor( MatrixPtr, spREAL[], spREAL,
spREAL, int );
spcEXTERN void spPartition( spMatrix, int );
spcEXTERN void spPrint( spMatrix, int, int, int );
spcEXTERN spREAL spPseudoCondition( spMatrix );
spcEXTERN spREAL spRoundoff( spMatrix, spREAL );
spcEXTERN void spScale( spMatrix, spREAL[], spREAL[] );
spcEXTERN void spSetComplex( spMatrix );
spcEXTERN void spSetReal( spMatrix );
spcEXTERN void spStripFills( spMatrix );
spcEXTERN void spWhereSingular( spMatrix, int*, int* );
spcEXTERN void spConstMult( spMatrix, double );
spcEXTERN void spPartition( MatrixPtr, int );
spcEXTERN void spPrint( MatrixPtr, int, int, int );
spcEXTERN spREAL spPseudoCondition( MatrixPtr );
spcEXTERN spREAL spRoundoff( MatrixPtr, spREAL );
spcEXTERN void spScale( MatrixPtr, spREAL[], spREAL[] );
spcEXTERN void spSetComplex( MatrixPtr );
spcEXTERN void spSetReal( MatrixPtr );
spcEXTERN void spStripFills( MatrixPtr );
spcEXTERN void spWhereSingular( MatrixPtr, int*, int* );
spcEXTERN void spConstMult( MatrixPtr, double );
/* Functions with argument lists that are dependent on options. */
#if spCOMPLEX
spcEXTERN void spDeterminant( spMatrix, int*, spREAL*, spREAL* );
spcEXTERN void spDeterminant( MatrixPtr, int*, spREAL*, spREAL* );
#else /* NOT spCOMPLEX */
spcEXTERN void spDeterminant( spMatrix, int*, spREAL* );
spcEXTERN void spDeterminant( MatrixPtr, int*, spREAL* );
#endif /* NOT spCOMPLEX */
#if spCOMPLEX && spSEPARATED_COMPLEX_VECTORS
spcEXTERN int spFileVector( spMatrix, char* ,
spcEXTERN int spFileVector( MatrixPtr, char* ,
spREAL[], spREAL[]);
spcEXTERN void spMultiply( spMatrix, spREAL[], spREAL[],
spcEXTERN void spMultiply( MatrixPtr, spREAL[], spREAL[],
spREAL[], spREAL[] );
spcEXTERN void spMultTransposed( spMatrix, spREAL[], spREAL[],
spcEXTERN void spMultTransposed( MatrixPtr, spREAL[], spREAL[],
spREAL[], spREAL[] );
spcEXTERN void spSolve( spMatrix, spREAL[], spREAL[], spREAL[],
spcEXTERN void spSolve( MatrixPtr, spREAL[], spREAL[], spREAL[],
spREAL[] );
spcEXTERN void spSolveTransposed( spMatrix, spREAL[], spREAL[],
spcEXTERN void spSolveTransposed( MatrixPtr, spREAL[], spREAL[],
spREAL[], spREAL[] );
#else /* NOT (spCOMPLEX && spSEPARATED_COMPLEX_VECTORS) */
spcEXTERN int spFileVector( spMatrix, char* , spREAL[] );
spcEXTERN void spMultiply( spMatrix, spREAL[], spREAL[] );
spcEXTERN void spMultTransposed( spMatrix,
spcEXTERN int spFileVector( MatrixPtr, char* , spREAL[] );
spcEXTERN void spMultiply( MatrixPtr, spREAL[], spREAL[] );
spcEXTERN void spMultTransposed( MatrixPtr,
spREAL[], spREAL[] );
spcEXTERN void spSolve( spMatrix, spREAL[], spREAL[] );
spcEXTERN void spSolveTransposed( spMatrix,
spcEXTERN void spSolve( MatrixPtr, spREAL[], spREAL[] );
spcEXTERN void spSolveTransposed( MatrixPtr,
spREAL[], spREAL[] );
#endif /* NOT (spCOMPLEX && spSEPARATED_COMPLEX_VECTORS) */
#endif /* spOKAY */

View File

@ -119,7 +119,7 @@ static void AllocateBlockOfAllocationList( MatrixPtr );
* A pointer to the matrix frame being created.
*/
spMatrix
MatrixPtr
spCreate(
int Size,
int Complex,
@ -263,14 +263,14 @@ int AllocatedSize;
if (Matrix->Error == spNO_MEMORY)
goto MemoryError;
return (char *)Matrix;
return Matrix;
MemoryError:
/* Deallocate matrix and return no pointer to matrix if there is not enough
memory. */
*pError = spNO_MEMORY;
spDestroy( (char *)Matrix);
spDestroy( Matrix );
return NULL;
}
@ -605,7 +605,7 @@ register AllocationListPtr ListPtr;
/*!
* Destroys a matrix and frees all memory associated with it.
*
* \param eMatrix
* \param Matrix
* Pointer to the matrix frame which is to be destroyed.
*/
/* >>> Local variables:
@ -620,9 +620,8 @@ register AllocationListPtr ListPtr;
*/
void
spDestroy( spMatrix eMatrix )
spDestroy( MatrixPtr Matrix )
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register AllocationListPtr ListPtr, NextListPtr;
/* Begin `spDestroy'. */
@ -666,18 +665,18 @@ register AllocationListPtr ListPtr, NextListPtr;
* \return
* The error status of the given matrix.
*
* \param eMatrix
* \param Matrix
* The pointer to the matrix for which the error status is desired.
*/
spError
spErrorState( spMatrix eMatrix )
spErrorState( MatrixPtr Matrix )
{
/* Begin `spErrorState'. */
if (eMatrix != NULL)
{ ASSERT_IS_SPARSE( (MatrixPtr)eMatrix );
return ((MatrixPtr)eMatrix)->Error;
if (Matrix != NULL)
{ ASSERT_IS_SPARSE( (MatrixPtr)Matrix );
return ((MatrixPtr)Matrix)->Error;
}
else return spNO_MEMORY; /* This error may actually be spPANIC,
* no way to tell. */
@ -698,7 +697,7 @@ spErrorState( spMatrix eMatrix )
* allowed on the last factorization). Pivoting is performed only in
* spOrderAndFactor().
*
* \param eMatrix
* \param Matrix
* The matrix for which the error status is desired.
* \param pRow
* The row number.
@ -708,13 +707,11 @@ spErrorState( spMatrix eMatrix )
void
spWhereSingular(
spMatrix eMatrix,
MatrixPtr Matrix,
int *pRow,
int *pCol
)
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
/* Begin `spWhereSingular'. */
ASSERT_IS_SPARSE( Matrix );
@ -735,7 +732,7 @@ MatrixPtr Matrix = (MatrixPtr)eMatrix;
* Returns the size of the matrix. Either the internal or external size of
* the matrix is returned.
*
* \param eMatrix
* \param Matrix
* Pointer to matrix.
* \param External
* If \a External is set true, the external size , i.e., the value of the
@ -746,12 +743,10 @@ MatrixPtr Matrix = (MatrixPtr)eMatrix;
int
spGetSize(
spMatrix eMatrix,
MatrixPtr Matrix,
int External
)
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
/* Begin `spGetSize'. */
ASSERT_IS_SPARSE( Matrix );
@ -775,18 +770,18 @@ MatrixPtr Matrix = (MatrixPtr)eMatrix;
/*!
* Forces matrix to be real.
*
* \param eMatrix
* \param Matrix
* Pointer to matrix.
*/
void
spSetReal( spMatrix eMatrix )
spSetReal( MatrixPtr Matrix )
{
/* Begin `spSetReal'. */
ASSERT_IS_SPARSE( (MatrixPtr)eMatrix );
ASSERT_IS_SPARSE( (MatrixPtr)Matrix );
vASSERT( REAL, "Sparse not compiled to handle real matrices" );
((MatrixPtr)eMatrix)->Complex = NO;
((MatrixPtr)Matrix)->Complex = NO;
return;
}
@ -794,18 +789,18 @@ spSetReal( spMatrix eMatrix )
/*!
* Forces matrix to be complex.
*
* \param eMatrix
* \param Matrix
* Pointer to matrix.
*/
void
spSetComplex( spMatrix eMatrix )
spSetComplex( MatrixPtr Matrix )
{
/* Begin `spSetComplex'. */
ASSERT_IS_SPARSE( (MatrixPtr)eMatrix );
ASSERT_IS_SPARSE( (MatrixPtr)Matrix );
vASSERT( spCOMPLEX, "Sparse not compiled to handle complex matrices" );
((MatrixPtr)eMatrix)->Complex = YES;
((MatrixPtr)Matrix)->Complex = YES;
return;
}
@ -820,44 +815,44 @@ spSetComplex( spMatrix eMatrix )
/*!
* This function returns the number of fill-ins that currently exists in a matrix.
*
* \param eMatrix
* \param Matrix
* Pointer to matrix.
*/
int
spFillinCount( spMatrix eMatrix )
spFillinCount( MatrixPtr Matrix )
{
/* Begin `spFillinCount'. */
ASSERT_IS_SPARSE( (MatrixPtr)eMatrix );
return ((MatrixPtr)eMatrix)->Fillins;
ASSERT_IS_SPARSE( (MatrixPtr)Matrix );
return ((MatrixPtr)Matrix)->Fillins;
}
/*!
* This function returns the total number of elements (including fill-ins) that currently exists in a matrix.
*
* \param eMatrix
* \param Matrix
* Pointer to matrix.
*/
/* FIXME: Seems no different size entries available anymore */
int
spElementCount( spMatrix eMatrix )
spElementCount( MatrixPtr Matrix )
{
/* Begin `spElementCount'. */
ASSERT_IS_SPARSE( (MatrixPtr)eMatrix );
return ((MatrixPtr)eMatrix)->Elements;
ASSERT_IS_SPARSE( (MatrixPtr)Matrix );
return ((MatrixPtr)Matrix)->Elements;
}
int
spOriginalCount( spMatrix eMatrix )
spOriginalCount( MatrixPtr Matrix )
{
/* Begin `spOriginalCount'. */
ASSERT_IS_SPARSE( (MatrixPtr)eMatrix );
return ((MatrixPtr)eMatrix)->Elements;
ASSERT_IS_SPARSE( (MatrixPtr)Matrix );
return ((MatrixPtr)Matrix)->Elements;
}

View File

@ -85,7 +85,7 @@ static void EnlargeMatrix( MatrixPtr, int );
/*!
* Sets every element of the matrix to zero and clears the error flag.
*
* \param eMatrix
* \param Matrix
* Pointer to matrix that is to be cleared.
*/
/* >>> Local variables:
@ -94,9 +94,8 @@ static void EnlargeMatrix( MatrixPtr, int );
*/
void
spClear( spMatrix eMatrix )
spClear( MatrixPtr Matrix )
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register ElementPtr pElement;
register int I;
@ -156,7 +155,7 @@ register int I;
* \return
* A pointer to the desired element, or \a NULL if it does not exist.
*
* \param eMatrix
* \param Matrix
* Pointer to matrix.
* \param Row
* Row index for element.
@ -172,12 +171,11 @@ register int I;
spElement *
spFindElement(
spMatrix eMatrix,
MatrixPtr Matrix,
int Row,
int Col
)
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register ElementPtr pElement;
int StartAt;
long int Min = LARGEST_LONG_INTEGER;
@ -256,7 +254,7 @@ long int Min = LARGEST_LONG_INTEGER;
* Returns a pointer to the element. This pointer is then used to directly
* access the element during successive builds.
*
* \param eMatrix
* \param Matrix
* Pointer to the matrix that the element is to be added to.
* \param Row
* Row index for element. Must be in the range of [0..Size] unless
@ -280,12 +278,11 @@ long int Min = LARGEST_LONG_INTEGER;
spElement *
spGetElement(
spMatrix eMatrix,
MatrixPtr Matrix,
int Row,
int Col
)
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
ElementPtr pElement;
/* Begin `spGetElement'. */
@ -1152,7 +1149,7 @@ register int I, OldAllocatedSize = Matrix->AllocatedExtSize;
*
* \return
* Returns the return value of the \a pInit() function.
* \param eMatrix
* \param Matrix
* Pointer to matrix.
* \param pInit
* Pointer to a function that initializes an element.
@ -1162,7 +1159,7 @@ register int I, OldAllocatedSize = Matrix->AllocatedExtSize;
int
spInitialize(
spMatrix eMatrix,
MatrixPtr Matrix,
int (*pInit)(
spElement *pElement,
spGenericPtr pInitInfo,
@ -1171,7 +1168,6 @@ spInitialize(
)
)
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register ElementPtr pElement;
int J, Error, Col;

View File

@ -110,7 +110,7 @@ static void WriteStatus( MatrixPtr, int );
* \a spSINGULAR and \a spSMALL_PIVOT.
* Error is cleared upon entering this function.
*
* \param eMatrix
* \param Matrix
* Pointer to the matrix.
* \param RHS
* Representative right-hand side vector that is used to determine
@ -187,14 +187,13 @@ static void WriteStatus( MatrixPtr, int );
spError
spOrderAndFactor(
spMatrix eMatrix,
MatrixPtr Matrix,
spREAL RHS[],
spREAL RelThreshold,
spREAL AbsThreshold,
int DiagPivoting
)
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
ElementPtr pPivot;
int Step, Size;
ElementPtr SearchForPivot();
@ -318,15 +317,14 @@ Done:
* \a spNO_MEMORY, \a spSINGULAR, \a spZERO_DIAG and \a spSMALL_PIVOT.
* Error is cleared upon entering this function.
*
* \param eMatrix
* \param Matrix
* Pointer to matrix.
* \see spOrderAndFactor()
*/
spError
spFactor( spMatrix eMatrix )
spFactor( MatrixPtr Matrix )
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register ElementPtr pElement;
register ElementPtr pColumn;
register int Step, Size;
@ -338,10 +336,10 @@ RealNumber Mult;
ASSERT_IS_NOT_FACTORED( Matrix );
if (Matrix->NeedsOrdering)
{ return spOrderAndFactor( eMatrix, (RealVector)NULL,
{ return spOrderAndFactor( Matrix, (RealVector)NULL,
0.0, 0.0, DIAG_PIVOTING_AS_DEFAULT );
}
if (NOT Matrix->Partitioned) spPartition( eMatrix, spDEFAULT_PARTITION );
if (NOT Matrix->Partitioned) spPartition( Matrix, spDEFAULT_PARTITION );
#if spCOMPLEX
if (Matrix->Complex) return FactorComplexMatrix( Matrix );
#endif
@ -444,7 +442,7 @@ RealNumber Mult;
*/
static int
FactorComplexMatrix( MatrixPtr Matrix )
FactorComplexMatrix( MatrixPtr Matrix )
{
register ElementPtr pElement;
register ElementPtr pColumn;
@ -570,7 +568,7 @@ ComplexNumber Mult, Pivot;
* best to let Sparse choose the partition. Otherwise, you should
* choose the partition based on the predicted density of the matrix.
*
* \param eMatrix
* \param Matrix
* Pointer to matrix.
* \param Mode
* Mode must be one of three special codes: \a spDIRECT_PARTITION,
@ -579,11 +577,10 @@ ComplexNumber Mult, Pivot;
void
spPartition(
spMatrix eMatrix,
MatrixPtr Matrix,
int Mode
)
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register ElementPtr pElement, pColumn;
register int Step, Size;
register int *Nc, *No;

View File

@ -65,7 +65,7 @@
* statistics are also output. The matrix is output in a format that is
* readable by people.
*
* \param eMatrix
* \param Matrix
* Pointer to matrix.
* \param PrintReordered
* Indicates whether the matrix should be printed out in its original
@ -129,13 +129,12 @@
void
spPrint(
spMatrix eMatrix,
MatrixPtr Matrix,
int PrintReordered,
int Data,
int Header
)
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register int J = 0;
int I, Row, Col, Size, Top, StartCol = 1, StopCol, Columns, ElementCount = 0;
double Magnitude, SmallestDiag, SmallestElement;
@ -365,7 +364,7 @@ int *PrintOrdToIntRowMap, *PrintOrdToIntColMap;
* The calling function can query \a errno (the system global error variable)
* as to the reason why this routine failed.
*
* \param eMatrix
* \param Matrix
* Pointer to matrix.
* \param File
* Name of file into which matrix is to be written.
@ -397,7 +396,7 @@ int *PrintOrdToIntRowMap, *PrintOrdToIntColMap;
int
spFileMatrix(
spMatrix eMatrix,
MatrixPtr Matrix,
char *File,
char *Label,
int Reordered,
@ -405,7 +404,6 @@ spFileMatrix(
int Header
)
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register int I, Size;
register ElementPtr pElement;
int Row, Col, Err;
@ -528,7 +526,7 @@ FILE *pMatrixFile;
* The calling function can query \a errno (the system global error variable)
* as to the reason why this routine failed.
*
* \param eMatrix
* \param Matrix
* Pointer to matrix.
* \param File
* Name of file into which matrix is to be written.
@ -551,7 +549,7 @@ FILE *pMatrixFile;
int
spFileVector(
spMatrix eMatrix,
MatrixPtr Matrix,
char *File,
spREAL RHS[]
#if spCOMPLEX AND spSEPARATED_COMPLEX_VECTORS
@ -559,7 +557,6 @@ spFileVector(
#endif
)
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register int I, Size, Err;
FILE *pMatrixFile;
@ -649,7 +646,7 @@ FILE *pMatrixFile;
* The calling function can query \a errno (the system global error variable)
* as to the reason why this routine failed.
*
* \param eMatrix
* \param Matrix
* Pointer to matrix.
* \param File
* Name of file into which matrix is to be written.
@ -675,12 +672,11 @@ FILE *pMatrixFile;
int
spFileStats(
spMatrix eMatrix,
MatrixPtr Matrix,
char *File,
char *Label
)
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register int Size, I;
register ElementPtr pElement;
int NumberOfElements;

View File

@ -98,7 +98,7 @@
typedef spREAL *RealVector;
static void LoadGmin(char *Matrix, double Gmin);
static void LoadGmin(MatrixPtr Matrix, double Gmin);
/*
* SMPaddElt()
@ -109,8 +109,8 @@ SMPmatrix *Matrix,
int Row, int Col,
double Value)
{
*spGetElement( (char *)Matrix, Row, Col ) = Value;
return spErrorState( (char *)Matrix );
*spGetElement( Matrix, Row, Col ) = Value;
return spErrorState( Matrix );
}
/*
@ -121,7 +121,7 @@ SMPmakeElt(
SMPmatrix *Matrix,
int Row, int Col)
{
return spGetElement( (char *)Matrix, Row, Col );
return spGetElement( Matrix, Row, Col );
}
/*
@ -131,7 +131,7 @@ void
SMPcClear(
SMPmatrix *Matrix)
{
spClear( (char *)Matrix );
spClear( Matrix );
}
/*
@ -141,7 +141,7 @@ void
SMPclear(
SMPmatrix *Matrix)
{
spClear( (char *)Matrix );
spClear( Matrix );
}
/*
@ -153,8 +153,8 @@ SMPcLUfac(
SMPmatrix *Matrix,
double PivTol)
{
spSetComplex( (char *)Matrix );
return spFactor( (char *)Matrix );
spSetComplex( Matrix );
return spFactor( Matrix );
}
/*
@ -166,9 +166,9 @@ SMPluFac(
SMPmatrix *Matrix,
double PivTol, double Gmin)
{
spSetReal( (char *)Matrix );
LoadGmin( (char *)Matrix, Gmin );
return spFactor( (char *)Matrix );
spSetReal( Matrix );
LoadGmin( Matrix, Gmin );
return spFactor( Matrix );
}
/*
@ -181,8 +181,8 @@ double PivTol, double PivRel,
int *NumSwaps)
{
*NumSwaps = 0;
spSetComplex( (char *)Matrix );
return spOrderAndFactor( (char *)Matrix, (spREAL*)NULL,
spSetComplex( Matrix );
return spOrderAndFactor( Matrix, (spREAL*)NULL,
(spREAL)PivRel, (spREAL)PivTol, YES );
}
@ -194,9 +194,9 @@ SMPreorder(
SMPmatrix *Matrix,
double PivTol, double PivRel, double Gmin)
{
spSetComplex( (char *)Matrix );
LoadGmin( (char *)Matrix, Gmin );
return spOrderAndFactor( (char *)Matrix, (spREAL*)NULL,
spSetComplex( Matrix );
LoadGmin( Matrix, Gmin );
return spOrderAndFactor( Matrix, (spREAL*)NULL,
(spREAL)PivRel, (spREAL)PivTol, YES );
}
@ -208,7 +208,7 @@ SMPcaSolve(
SMPmatrix *Matrix,
double RHS[], double iRHS[], double Spare[], double iSpare[])
{
spSolveTransposed( (char *)Matrix, RHS, RHS, iRHS, iRHS );
spSolveTransposed( Matrix, RHS, RHS, iRHS, iRHS );
}
/*
@ -219,7 +219,7 @@ SMPcSolve(
SMPmatrix *Matrix,
double RHS[], double iRHS[], double Spare[], double iSpare[])
{
spSolve( (char *)Matrix, RHS, RHS, iRHS, iRHS );
spSolve( Matrix, RHS, RHS, iRHS, iRHS );
}
/*
@ -230,7 +230,7 @@ SMPsolve(
SMPmatrix *Matrix,
double RHS[], double Spare[])
{
spSolve( (char *)Matrix, RHS, RHS, (spREAL*)NULL, (spREAL*)NULL );
spSolve( Matrix, RHS, RHS, (spREAL*)NULL, (spREAL*)NULL );
}
/*
@ -240,7 +240,7 @@ int
SMPmatSize(
SMPmatrix *Matrix)
{
return spGetSize( (char *)Matrix, 1 );
return spGetSize( Matrix, 1 );
}
/*
@ -263,7 +263,7 @@ void
SMPdestroy(
SMPmatrix *Matrix)
{
spDestroy( (char *)Matrix );
spDestroy( Matrix );
}
/*
@ -273,8 +273,8 @@ int
SMPpreOrder(
SMPmatrix *Matrix)
{
spMNA_Preorder( (char *)Matrix );
return spErrorState( (char *)Matrix );
spMNA_Preorder( Matrix );
return spErrorState( Matrix );
}
/*
@ -295,7 +295,7 @@ SMPprint(
SMPmatrix *Matrix,
char *File)
{
spPrint( (char *)Matrix, 0, 1, 1 );
spPrint( Matrix, 0, 1, 1 );
}
/*
@ -306,7 +306,7 @@ SMPgetError(
SMPmatrix *Matrix,
int *Row, int *Col)
{
spWhereSingular( (char *)Matrix, Row, Col );
spWhereSingular( Matrix, Row, Col );
}
/*
@ -318,9 +318,9 @@ SMPmatrix *Matrix,
SPcomplex *pMantissa,
int *pExponent)
{
spDeterminant( (char *)Matrix, pExponent, &(pMantissa->real),
spDeterminant( Matrix, pExponent, &(pMantissa->real),
&(pMantissa->imag) );
return spErrorState( (char *)Matrix );
return spErrorState( Matrix );
}
/*
@ -419,10 +419,9 @@ SMPcDProd(SMPmatrix *Matrix, SPcomplex *pMantissa, int *pExponent)
#include "spDefs.h"
static void
LoadGmin(
char *eMatrix,
MatrixPtr Matrix,
register double Gmin)
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register int I;
register ArrayOfElementPtrs Diag;

View File

@ -85,7 +85,7 @@ static void SolveComplexTransposedMatrix( MatrixPtr,
* in different way than is traditionally used in order to exploit the
* sparsity of the right-hand side. See the reference in spRevision.
*
* \param eMatrix
* \param Matrix
* Pointer to matrix.
* \param RHS
* \a RHS is the input data array, the right hand side. This data is
@ -137,7 +137,7 @@ static void SolveComplexTransposedMatrix( MatrixPtr,
void
spSolve(
spMatrix eMatrix,
MatrixPtr Matrix,
spREAL RHS[],
spREAL Solution[]
# if spCOMPLEX AND spSEPARATED_COMPLEX_VECTORS
@ -146,7 +146,6 @@ spSolve(
# endif
)
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register ElementPtr pElement;
register RealVector Intermediate;
register RealNumber Temp;
@ -405,7 +404,7 @@ ComplexNumber Temp;
* matrix and that the diagonal of the untransposed upper
* triangular matrix consists of ones.
*
* \param eMatrix
* \param Matrix
* Pointer to matrix.
* \param RHS
* \a RHS is the input data array, the right hand side. This data is
@ -451,7 +450,7 @@ ComplexNumber Temp;
void
spSolveTransposed(
spMatrix eMatrix,
MatrixPtr Matrix,
spREAL RHS[],
spREAL Solution[]
# if spCOMPLEX AND spSEPARATED_COMPLEX_VECTORS
@ -460,7 +459,6 @@ spSolveTransposed(
# endif
)
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register ElementPtr pElement;
register RealVector Intermediate;
register int I, *pExtOrder, Size;

View File

@ -170,7 +170,7 @@ static RealNumber ComplexCondition( MatrixPtr, RealNumber, int* );
* The algorithm used in this function was developed by Ken Kundert and
* Tom Quarles.
*
* \param * eMatrix
* \param * Matrix
* Pointer to the matrix to be preordered.
*/
/* >>> Local variables;
@ -193,9 +193,8 @@ static RealNumber ComplexCondition( MatrixPtr, RealNumber, int* );
*/
void
spMNA_Preorder( spMatrix eMatrix )
spMNA_Preorder( MatrixPtr Matrix )
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register int J, Size;
ElementPtr pTwin1, pTwin2;
int Twins, StartAt = 1;
@ -362,7 +361,7 @@ int Col1 = pTwin1->Col, Col2 = pTwin2->Col;
* the RHS and Solution vectors descaled. Lastly, this function
* should not be executed before the function spMNA_Preorder().
*
* \param eMatrix
* \param Matrix
* Pointer to the matrix to be scaled.
* \param SolutionScaleFactors
* The array of Solution scale factors. These factors scale the columns.
@ -385,12 +384,11 @@ int Col1 = pTwin1->Col, Col2 = pTwin2->Col;
void
spScale(
spMatrix eMatrix,
MatrixPtr Matrix,
spREAL RHS_ScaleFactors[],
spREAL SolutionScaleFactors[]
)
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register ElementPtr pElement;
register int I, lSize, *pExtOrder;
RealNumber ScaleFactor;
@ -579,7 +577,7 @@ RealNumber ScaleFactor;
* as a test to see if solutions are correct. It should not be used
* before spMNA_Preorder().
*
* \param eMatrix
* \param Matrix
* Pointer to the matrix.
* \param RHS
* RHS is the right hand side. This is what is being solved for.
@ -597,7 +595,7 @@ RealNumber ScaleFactor;
void
spMultiply(
spMatrix eMatrix,
MatrixPtr Matrix,
spREAL RHS[],
spREAL Solution[]
#if spCOMPLEX AND spSEPARATED_COMPLEX_VECTORS
@ -610,7 +608,6 @@ register ElementPtr pElement;
register RealVector Vector;
register RealNumber Sum;
register int I, *pExtOrder;
MatrixPtr Matrix = (MatrixPtr)eMatrix;
extern void ComplexMatrixMultiply();
/* Begin `spMultiply'. */
@ -770,7 +767,7 @@ register int I, *pExtOrder;
* as a test to see if solutions are correct. It should not be used
* before spMNA_Preorder().
*
* \param eMatrix
* \param Matrix
* Pointer to the matrix.
* \param RHS
* RHS is the right hand side. This is what is being solved for.
@ -788,7 +785,7 @@ register int I, *pExtOrder;
void
spMultTransposed(
spMatrix eMatrix,
MatrixPtr Matrix,
spREAL RHS[],
spREAL Solution[]
#if spCOMPLEX AND spSEPARATED_COMPLEX_VECTORS
@ -801,7 +798,6 @@ register ElementPtr pElement;
register RealVector Vector;
register RealNumber Sum;
register int I, *pExtOrder;
MatrixPtr Matrix = (MatrixPtr)eMatrix;
extern void ComplexTransposedMatrixMultiply();
/* Begin `spMultTransposed'. */
@ -973,7 +969,7 @@ register int I, *pExtOrder;
* point number. For this reason the determinant is scaled to a
* reasonable value and the logarithm of the scale factor is returned.
*
* \param eMatrix
* \param Matrix
* A pointer to the matrix for which the determinant is desired.
* \param pExponent
* The logarithm base 10 of the scale factor for the determinant. To find
@ -998,7 +994,7 @@ register int I, *pExtOrder;
void
spDeterminant(
spMatrix eMatrix,
MatrixPtr Matrix,
int *pExponent,
spREAL *pDeterminant
#if spCOMPLEX
@ -1006,7 +1002,6 @@ spDeterminant(
#endif
)
{
register MatrixPtr Matrix = (MatrixPtr)eMatrix;
register int I, Size;
RealNumber Norm, nr, ni;
ComplexNumber Pivot, cDeterminant;
@ -1133,7 +1128,7 @@ ComplexNumber Pivot, cDeterminant;
/*!
* Strips the matrix of all fill-ins.
*
* \param eMatrix
* \param Matrix
* Pointer to the matrix to be stripped.
*/
/* >>> Local variables:
@ -1151,9 +1146,8 @@ ComplexNumber Pivot, cDeterminant;
*/
void
spStripFills( spMatrix eMatrix )
spStripFills( MatrixPtr Matrix )
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
struct FillinListNodeStruct *pListNode;
/* Begin `spStripFills'. */
@ -1225,7 +1219,7 @@ struct FillinListNodeStruct *pListNode;
* Sparse will abort if an attempt is made to delete a row or column that
* doesn't exist.
*
* \param eMatrix
* \param Matrix
* Pointer to the matrix in which the row and column are to be deleted.
* \param Row
* Row to be deleted.
@ -1252,12 +1246,11 @@ struct FillinListNodeStruct *pListNode;
void
spDeleteRowAndCol(
spMatrix eMatrix,
MatrixPtr Matrix,
int Row,
int Col
)
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register ElementPtr pElement, *ppElement, pLastElement;
int Size, ExtRow, ExtCol;
@ -1358,14 +1351,13 @@ int Size, ExtRow, ExtCol;
* The magnitude of the ratio of the largest to smallest pivot used during
* previous factorization. If the matrix was singular, zero is returned.
*
* \param eMatrix
* \param Matrix
* Pointer to the matrix.
*/
spREAL
spPseudoCondition( spMatrix eMatrix )
spPseudoCondition( MatrixPtr Matrix )
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register int I;
register ArrayOfElementPtrs Diag;
RealNumber MaxPivot, MinPivot, Mag;
@ -1437,7 +1429,7 @@ spPseudoCondition( spMatrix eMatrix )
* The reciprocal of the condition number. If the matrix was singular,
* zero is returned.
*
* \param eMatrix
* \param Matrix
* Pointer to the matrix.
* \param NormOfMatrix
* The L-infinity norm of the unfactored matrix as computed by
@ -1449,12 +1441,11 @@ spPseudoCondition( spMatrix eMatrix )
spREAL
spCondition(
spMatrix eMatrix,
MatrixPtr Matrix,
spREAL NormOfMatrix,
int *pError
)
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register ElementPtr pElement;
register RealVector T, Tm;
register int I, K, Row;
@ -1844,14 +1835,13 @@ ComplexNumber Wp, Wm;
* \return
* The largest absolute row sum of matrix.
*
* \param eMatrix
* \param Matrix
* Pointer to the matrix.
*/
spREAL
spNorm( spMatrix eMatrix )
spNorm( MatrixPtr Matrix )
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register ElementPtr pElement;
register int I;
RealNumber Max = 0.0, AbsRowSum;
@ -1959,14 +1949,13 @@ RealNumber Max = 0.0, AbsRowSum;
* the matrix. If the matrix is factored, a bound on the magnitude of the
* largest element in any of the reduced submatrices is returned.
*
* \param eMatrix
* \param Matrix
* Pointer to the matrix.
*/
spREAL
spLargestElement( spMatrix eMatrix )
spLargestElement( MatrixPtr Matrix )
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register int I;
RealNumber Mag, AbsColSum, Max = 0.0, MaxRow = 0.0, MaxCol = 0.0;
RealNumber Pivot;
@ -2073,7 +2062,7 @@ register ElementPtr pElement, pDiag;
* Returns a bound on the magnitude of the largest element in
* \f$ E = A - LU \f$.
*
* \param eMatrix
* \param Matrix
* Pointer to the matrix.
* \param Rho
* The bound on the magnitude of the largest element in any of the
@ -2084,11 +2073,10 @@ register ElementPtr pElement, pDiag;
spREAL
spRoundoff(
spMatrix eMatrix,
MatrixPtr Matrix,
spREAL Rho
)
{
MatrixPtr Matrix = (MatrixPtr)eMatrix;
register ElementPtr pElement;
register int Count, I, MaxCount = 0;
RealNumber Reid, Gear;
@ -2099,7 +2087,7 @@ RealNumber Reid, Gear;
ASSERT_IS_FACTORED( Matrix );
/* Compute Barlow's bound if it is not given. */
if (Rho < 0.0) Rho = spLargestElement( eMatrix );
if (Rho < 0.0) Rho = spLargestElement( Matrix );
/* Find the maximum number of off-diagonals in L if not previously computed. */
if (Matrix->MaxRowCountInLowerTri < 0)
@ -2139,7 +2127,7 @@ RealNumber Reid, Gear;
* of sparse. No message is produced if there is no error.
* The error state is cleared.
*
* \param eMatrix
* \param Matrix
* Matrix for which the error message is to be printed.
* \param Stream
* Stream to which the error message is to be printed.
@ -2150,7 +2138,7 @@ RealNumber Reid, Gear;
void
spErrorMessage(
spMatrix eMatrix,
MatrixPtr Matrix,
FILE *Stream,
char *Originator
)
@ -2158,11 +2146,11 @@ spErrorMessage(
int Row, Col, Error;
/* Begin `spErrorMessage'. */
if (eMatrix == NULL)
if (Matrix == NULL)
Error = spNO_MEMORY;
else
{ ASSERT_IS_SPARSE( (MatrixPtr)eMatrix );
Error = ((MatrixPtr)eMatrix)->Error;
{ ASSERT_IS_SPARSE( (MatrixPtr)Matrix );
Error = ((MatrixPtr)Matrix)->Error;
}
if (Error == spOKAY) return;
@ -2184,12 +2172,12 @@ int Row, Col, Error;
else if (Error == spMANGLED)
fprintf( Stream, "matrix is mangled.\n");
else if (Error == spSINGULAR)
{ spWhereSingular( eMatrix, &Row, &Col );
{ spWhereSingular( Matrix, &Row, &Col );
fprintf( Stream, "singular matrix detected at row %d and column %d.\n",
Row, Col);
}
else if (Error == spZERO_DIAG)
{ spWhereSingular( eMatrix, &Row, &Col );
{ spWhereSingular( Matrix, &Row, &Col );
fprintf( Stream, "zero diagonal detected at row %d and column %d.\n",
Row, Col);
}
@ -2199,7 +2187,7 @@ int Row, Col, Error;
}
else ABORT();
((MatrixPtr)eMatrix)->Error = spOKAY;
((MatrixPtr)Matrix)->Error = spOKAY;
return;
}
#endif /* DOCUMENTATION */

View File

@ -30,13 +30,12 @@
void
spConstMult(
spMatrix eMatrix,
MatrixPtr Matrix,
double constant
)
{
ElementPtr pElement;
int I;
MatrixPtr Matrix = (MatrixPtr)eMatrix;
int size = Matrix->Size;
ASSERT_IS_SPARSE( Matrix );