diff --git a/src/maths/sparse/spAllocate.c b/src/maths/sparse/spAllocate.c index 6f7add724..ca0559122 100644 --- a/src/maths/sparse/spAllocate.c +++ b/src/maths/sparse/spAllocate.c @@ -675,8 +675,8 @@ spErrorState( MatrixPtr Matrix ) /* Begin `spErrorState'. */ if (Matrix != NULL) - { ASSERT_IS_SPARSE( (MatrixPtr)Matrix ); - return ((MatrixPtr)Matrix)->Error; + { ASSERT_IS_SPARSE( Matrix ); + return (Matrix)->Error; } else return spNO_MEMORY; /* This error may actually be spPANIC, * no way to tell. */ @@ -779,9 +779,9 @@ spSetReal( MatrixPtr Matrix ) { /* Begin `spSetReal'. */ - ASSERT_IS_SPARSE( (MatrixPtr)Matrix ); + ASSERT_IS_SPARSE( Matrix ); vASSERT( REAL, "Sparse not compiled to handle real matrices" ); - ((MatrixPtr)Matrix)->Complex = NO; + Matrix->Complex = NO; return; } @@ -798,9 +798,9 @@ spSetComplex( MatrixPtr Matrix ) { /* Begin `spSetComplex'. */ - ASSERT_IS_SPARSE( (MatrixPtr)Matrix ); + ASSERT_IS_SPARSE( Matrix ); vASSERT( spCOMPLEX, "Sparse not compiled to handle complex matrices" ); - ((MatrixPtr)Matrix)->Complex = YES; + Matrix->Complex = YES; return; } @@ -824,8 +824,8 @@ spFillinCount( MatrixPtr Matrix ) { /* Begin `spFillinCount'. */ - ASSERT_IS_SPARSE( (MatrixPtr)Matrix ); - return ((MatrixPtr)Matrix)->Fillins; + ASSERT_IS_SPARSE( Matrix ); + return Matrix->Fillins; } @@ -843,8 +843,8 @@ spElementCount( MatrixPtr Matrix ) { /* Begin `spElementCount'. */ - ASSERT_IS_SPARSE( (MatrixPtr)Matrix ); - return ((MatrixPtr)Matrix)->Elements; + ASSERT_IS_SPARSE( Matrix ); + return Matrix->Elements; } int @@ -852,7 +852,7 @@ spOriginalCount( MatrixPtr Matrix ) { /* Begin `spOriginalCount'. */ - ASSERT_IS_SPARSE( (MatrixPtr)Matrix ); - return ((MatrixPtr)Matrix)->Elements; + ASSERT_IS_SPARSE( Matrix ); + return Matrix->Elements; } diff --git a/src/maths/sparse/spBuild.c b/src/maths/sparse/spBuild.c index 3ec93bcb7..0497a8550 100644 --- a/src/maths/sparse/spBuild.c +++ b/src/maths/sparse/spBuild.c @@ -75,8 +75,9 @@ static void Translate( MatrixPtr, int*, int* ); static void ExpandTranslationArrays( MatrixPtr, int ); #endif +#if EXPANDABLE static void EnlargeMatrix( MatrixPtr, int ); - +#endif @@ -969,7 +970,7 @@ register int Col; - +#if EXPANDABLE /* * ENLARGE MATRIX @@ -1049,7 +1050,7 @@ register int I, OldAllocatedSize = Matrix->AllocatedSize; return; } - +#endif diff --git a/src/maths/sparse/spFactor.c b/src/maths/sparse/spFactor.c index 7fd305099..c506150da 100644 --- a/src/maths/sparse/spFactor.c +++ b/src/maths/sparse/spFactor.c @@ -69,14 +69,18 @@ * Function declarations */ +#if spCOMPLEX static int FactorComplexMatrix( MatrixPtr ); +#endif //static void CreateInternalVectors( MatrixPtr ); static void CountMarkowitz( MatrixPtr, RealVector, int ); static void MarkowitzProducts( MatrixPtr, int ); static ElementPtr SearchForPivot( MatrixPtr, int, int ); static ElementPtr SearchForSingleton( MatrixPtr, int ); +#if DIAGONAL_PIVOTING static ElementPtr QuicklySearchDiagonal( MatrixPtr, int ); static ElementPtr SearchDiagonal( MatrixPtr, int ); +#endif static ElementPtr SearchEntireMatrix( MatrixPtr, int ); static RealNumber FindLargestInCol( ElementPtr ); static RealNumber FindBiggestInColExclude( MatrixPtr, ElementPtr, int ); @@ -325,11 +329,12 @@ Done: spError spFactor( MatrixPtr Matrix ) { +#if REAL register ElementPtr pElement; register ElementPtr pColumn; register int Step, Size; RealNumber Mult; - +#endif /* Begin `spFactor'. */ ASSERT_IS_SPARSE( Matrix ); ASSERT_NO_ERRORS( Matrix ); @@ -585,15 +590,23 @@ register ElementPtr pElement, pColumn; register int Step, Size; register int *Nc, *No; register long *Nm; -BOOLEAN *DoRealDirect, *DoCmplxDirect; - +#if spCOMPLEX +BOOLEAN *DoCmplxDirect; +#endif +#if REAL +BOOLEAN *DoRealDirect; +#endif /* Begin `spPartition'. */ ASSERT_IS_SPARSE( Matrix ); if (Matrix->Partitioned) return; Size = Matrix->Size; +#if REAL DoRealDirect = Matrix->DoRealDirect; +#endif +#if spCOMPLEX DoCmplxDirect = Matrix->DoCmplxDirect; +#endif Matrix->Partitioned = YES; /* If partition is specified by the user, this is easy. */ diff --git a/src/maths/sparse/spOutput.c b/src/maths/sparse/spOutput.c index b56a4274b..e08588c7d 100644 --- a/src/maths/sparse/spOutput.c +++ b/src/maths/sparse/spOutput.c @@ -139,7 +139,10 @@ register int J = 0; int I, Row, Col, Size, Top, StartCol = 1, StopCol, Columns, ElementCount = 0; double Magnitude, SmallestDiag, SmallestElement; double LargestElement = 0.0, LargestDiag = 0.0; -ElementPtr pElement, pImagElements[PRINTER_WIDTH/10+1]; +ElementPtr pElement; +#if spCOMPLEX +ElementPtr pImagElements[PRINTER_WIDTH/10+1]; +#endif int *PrintOrdToIntRowMap, *PrintOrdToIntColMap; /* Begin `spPrint'. */ @@ -258,8 +261,10 @@ int *PrintOrdToIntRowMap, *PrintOrdToIntColMap; while(pElement != NULL AND pElement->Row != Row) pElement = pElement->NextInCol; +#if spCOMPLEX if (Data) pImagElements[J - StartCol] = pElement; +#endif if (pElement != NULL) @@ -557,7 +562,10 @@ spFileVector( #endif ) { -register int I, Size, Err; +register int I, Size; +#if spCOMPLEX +register int Err; +#endif FILE *pMatrixFile; /* Begin `spFileVector'. */ diff --git a/src/maths/sparse/spSMP.c b/src/maths/sparse/spSMP.c index fbbcc2d4f..4b05fdc61 100644 --- a/src/maths/sparse/spSMP.c +++ b/src/maths/sparse/spSMP.c @@ -208,7 +208,11 @@ SMPcaSolve( SMPmatrix *Matrix, double RHS[], double iRHS[], double Spare[], double iSpare[]) { +#if spCOMPLEX spSolveTransposed( Matrix, RHS, RHS, iRHS, iRHS ); +#else + spSolveTransposed( Matrix, RHS, RHS ); +#endif } /* @@ -219,7 +223,11 @@ SMPcSolve( SMPmatrix *Matrix, double RHS[], double iRHS[], double Spare[], double iSpare[]) { +#if spCOMPLEX spSolve( Matrix, RHS, RHS, iRHS, iRHS ); +#else + spSolve( Matrix, RHS, RHS ); +#endif } /* @@ -230,7 +238,11 @@ SMPsolve( SMPmatrix *Matrix, double RHS[], double Spare[]) { +#if spCOMPLEX spSolve( Matrix, RHS, RHS, (spREAL*)NULL, (spREAL*)NULL ); +#else + spSolve( Matrix, RHS, RHS ); +#endif } /* @@ -283,7 +295,11 @@ SMPmatrix *Matrix) void SMPprintRHS(SMPmatrix *Matrix, char *Filename, RealVector RHS, RealVector iRHS) { +#if spCOMPLEX spFileVector( Matrix, Filename, RHS, iRHS ); +#else + spFileVector( Matrix, Filename, RHS ); +#endif } /* @@ -318,8 +334,12 @@ SMPmatrix *Matrix, SPcomplex *pMantissa, int *pExponent) { +#if spCOMPLEX spDeterminant( Matrix, pExponent, &(pMantissa->real), &(pMantissa->imag) ); +#else + spDeterminant( Matrix, pExponent, &(pMantissa->real) ); +#endif return spErrorState( Matrix ); } @@ -332,8 +352,12 @@ SMPcDProd(SMPmatrix *Matrix, SPcomplex *pMantissa, int *pExponent) double re, im, x, y, z; int p; +#if spCOMPLEX spDeterminant( Matrix, &p, &re, &im); - +#else + spDeterminant( Matrix, &p, &re ); + im = 0.0; +#endif #ifndef M_LN2 #define M_LN2 0.69314718055994530942 #endif @@ -504,7 +528,9 @@ SMPcZeroCol(SMPmatrix *Matrix, int Col) Element = Element->NextInCol) { Element->Real = 0.0; +#if spCOMPLEX Element->Imag = 0.0; +#endif } return spErrorState( Matrix ); @@ -534,7 +560,9 @@ SMPcAddCol(SMPmatrix *Matrix, int Accum_Col, int Addend_Col) Accum = spcCreateElement(Matrix, Addend->Row, Accum_Col, Prev, 0, 0); } Accum->Real += Addend->Real; +#if spCOMPLEX Accum->Imag += Addend->Imag; +#endif Addend = Addend->NextInCol; } @@ -548,7 +576,11 @@ SMPcAddCol(SMPmatrix *Matrix, int Accum_Col, int Addend_Col) void SMPmultiply(SMPmatrix *Matrix, double *RHS, double *Solution, double *iRHS, double *iSolution) { +#if spCOMPLEX spMultiply(Matrix, RHS, Solution, iRHS, iSolution); +#else + spMultiply(Matrix, RHS, Solution); +#endif } /* diff --git a/src/maths/sparse/spSolve.c b/src/maths/sparse/spSolve.c index ec87f53d0..795b2c0c7 100644 --- a/src/maths/sparse/spSolve.c +++ b/src/maths/sparse/spSolve.c @@ -60,10 +60,12 @@ */ #if spSEPARATED_COMPLEX_VECTORS +#if spCOMPLEX static void SolveComplexMatrix( MatrixPtr, RealVector, RealVector, RealVector, RealVector ); static void SolveComplexTransposedMatrix( MatrixPtr, RealVector, RealVector, RealVector, RealVector ); +#endif #else static void SolveComplexMatrix( MatrixPtr, RealVector, RealVector ); static void SolveComplexTransposedMatrix( MatrixPtr, @@ -146,11 +148,13 @@ spSolve( # endif ) { +#if REAL register ElementPtr pElement; register RealVector Intermediate; register RealNumber Temp; register int I, *pExtOrder, Size; ElementPtr pPivot; +#endif void SolveComplexMatrix(); /* Begin `spSolve'. */ @@ -459,11 +463,13 @@ spSolveTransposed( # endif ) { +#if REAL register ElementPtr pElement; register RealVector Intermediate; register int I, *pExtOrder, Size; ElementPtr pPivot; RealNumber Temp; +#endif void SolveComplexTransposedMatrix(); /* Begin `spSolveTransposed'. */ diff --git a/src/maths/sparse/spUtils.c b/src/maths/sparse/spUtils.c index c01362e30..9cb1eddcd 100644 --- a/src/maths/sparse/spUtils.c +++ b/src/maths/sparse/spUtils.c @@ -71,9 +71,10 @@ /* * Function declarations */ - +#if MODIFIED_NODAL static int CountTwins( MatrixPtr, int, ElementPtr*, ElementPtr* ); static void SwapCols( MatrixPtr, ElementPtr, ElementPtr ); +#endif #if spCOMPLEX AND SCALING static void ScaleComplexMatrix( MatrixPtr, RealVector, RealVector ); #endif @@ -604,10 +605,12 @@ spMultiply( #endif ) { +#if REAL register ElementPtr pElement; register RealVector Vector; register RealNumber Sum; register int I, *pExtOrder; +#endif extern void ComplexMatrixMultiply(); /* Begin `spMultiply'. */ @@ -794,11 +797,13 @@ spMultTransposed( #endif ) { +#if REAL register ElementPtr pElement; register RealVector Vector; register RealNumber Sum; register int I, *pExtOrder; extern void ComplexTransposedMatrixMultiply(); +#endif /* Begin `spMultTransposed'. */ ASSERT_IS_SPARSE( Matrix ); @@ -2149,8 +2154,8 @@ int Row, Col, Error; if (Matrix == NULL) Error = spNO_MEMORY; else - { ASSERT_IS_SPARSE( (MatrixPtr)Matrix ); - Error = ((MatrixPtr)Matrix)->Error; + { ASSERT_IS_SPARSE( Matrix ); + Error = Matrix->Error; } if (Error == spOKAY) return; @@ -2187,7 +2192,7 @@ int Row, Col, Error; } else ABORT(); - ((MatrixPtr)Matrix)->Error = spOKAY; + Matrix->Error = spOKAY; return; } #endif /* DOCUMENTATION */