rename ALLOC, REALLOC, CALLOC, FREE, in the "src/maths/sparse" domain

This commit is contained in:
rlar 2010-10-24 12:51:43 +00:00
parent 46aeab65a8
commit 3cc50320e3
7 changed files with 79 additions and 69 deletions

View File

@ -1,3 +1,13 @@
2010-10-24 Robert Larice
* src/maths/sparse/spalloc.c ,
* src/maths/sparse/spbuild.c ,
* src/maths/sparse/spdefs.h ,
* src/maths/sparse/spfactor.c ,
* src/maths/sparse/spoutput.c ,
* src/maths/sparse/sputils.c :
rename ALLOC, REALLOC, CALLOC, FREE, in the "src/maths/sparse" domain
-> SP_MALLOC, SP_REALLOC, SP_CALLOC, SP_FREE
2010-10-24 Robert Larice
* src/include/complex.h :
ngcomplex_t instead of complex, #2/2

View File

@ -149,7 +149,7 @@ spCreate(int Size, int Complex, int *pError)
AllocatedSize = MAX( Size, MINIMUM_ALLOCATED_SIZE );
SizePlusOne = (unsigned)(AllocatedSize + 1);
if ((Matrix = ALLOC(struct MatrixFrame, 1)) == NULL) {
if ((Matrix = SP_MALLOC(struct MatrixFrame, 1)) == NULL) {
*pError = spNO_MEMORY;
return NULL;
}
@ -209,26 +209,26 @@ spCreate(int Size, int Complex, int *pError)
#endif
/* Allocate space in memory for Diag pointer vector. */
CALLOC( Matrix->Diag, ElementPtr, SizePlusOne);
SP_CALLOC( Matrix->Diag, ElementPtr, SizePlusOne);
if (Matrix->Diag == NULL)
goto MemoryError;
/* Allocate space in memory for FirstInCol pointer vector. */
CALLOC( Matrix->FirstInCol, ElementPtr, SizePlusOne);
SP_CALLOC( Matrix->FirstInCol, ElementPtr, SizePlusOne);
if (Matrix->FirstInCol == NULL)
goto MemoryError;
/* Allocate space in memory for FirstInRow pointer vector. */
CALLOC( Matrix->FirstInRow, ElementPtr, SizePlusOne);
SP_CALLOC( Matrix->FirstInRow, ElementPtr, SizePlusOne);
if (Matrix->FirstInRow == NULL)
goto MemoryError;
/* Allocate space in memory for IntToExtColMap vector. */
if (( Matrix->IntToExtColMap = ALLOC(int, SizePlusOne)) == NULL)
if (( Matrix->IntToExtColMap = SP_MALLOC(int, SizePlusOne)) == NULL)
goto MemoryError;
/* Allocate space in memory for IntToExtRowMap vector. */
if (( Matrix->IntToExtRowMap = ALLOC(int, SizePlusOne)) == NULL)
if (( Matrix->IntToExtRowMap = SP_MALLOC(int, SizePlusOne)) == NULL)
goto MemoryError;
/* Initialize MapIntToExt vectors. */
@ -240,11 +240,11 @@ spCreate(int Size, int Complex, int *pError)
#if TRANSLATE
/* Allocate space in memory for ExtToIntColMap vector. */
if (( Matrix->ExtToIntColMap = ALLOC(int, SizePlusOne)) == NULL)
if (( Matrix->ExtToIntColMap = SP_MALLOC(int, SizePlusOne)) == NULL)
goto MemoryError;
/* Allocate space in memory for ExtToIntRowMap vector. */
if (( Matrix->ExtToIntRowMap = ALLOC(int, SizePlusOne)) == NULL)
if (( Matrix->ExtToIntRowMap = SP_MALLOC(int, SizePlusOne)) == NULL)
goto MemoryError;
/* Initialize MapExtToInt vectors. */
@ -314,7 +314,7 @@ spcGetElement(MatrixPtr Matrix)
#if !COMBINE || STRIP || LINT
/* Allocate block of MatrixElements if necessary. */
if (Matrix->ElementsRemaining == 0) {
pElements = ALLOC(struct MatrixElement, ELEMENTS_PER_ALLOCATION);
pElements = SP_MALLOC(struct MatrixElement, ELEMENTS_PER_ALLOCATION);
RecordAllocation( Matrix, (void *)pElements );
if (Matrix->Error == spNO_MEMORY) return NULL;
Matrix->ElementsRemaining = ELEMENTS_PER_ALLOCATION;
@ -334,14 +334,14 @@ spcGetElement(MatrixPtr Matrix)
Matrix->NextAvailElement = pListNode->pElementList;
} else {
/* Allocate block of elements. */
pElements = ALLOC(struct MatrixElement, ELEMENTS_PER_ALLOCATION);
pElements = SP_MALLOC(struct MatrixElement, ELEMENTS_PER_ALLOCATION);
RecordAllocation( Matrix, (void *)pElements );
if (Matrix->Error == spNO_MEMORY) return NULL;
Matrix->ElementsRemaining = ELEMENTS_PER_ALLOCATION;
Matrix->NextAvailElement = pElements;
/* Allocate an element list structure. */
pListNode->Next = ALLOC(struct ElementListNodeStruct,1);
pListNode->Next = SP_MALLOC(struct ElementListNodeStruct,1);
RecordAllocation( Matrix, (void *)pListNode->Next );
if (Matrix->Error == spNO_MEMORY)
return NULL;
@ -405,14 +405,14 @@ InitializeElementBlocks(MatrixPtr Matrix, int InitialNumberOfElements,
/* Begin `InitializeElementBlocks'. */
/* Allocate block of MatrixElements for elements. */
pElement = ALLOC(struct MatrixElement, InitialNumberOfElements);
pElement = SP_MALLOC(struct MatrixElement, InitialNumberOfElements);
RecordAllocation( Matrix, (void *)pElement );
if (Matrix->Error == spNO_MEMORY) return;
Matrix->ElementsRemaining = InitialNumberOfElements;
Matrix->NextAvailElement = pElement;
/* Allocate an element list structure. */
Matrix->FirstElementListNode = ALLOC(struct ElementListNodeStruct,1);
Matrix->FirstElementListNode = SP_MALLOC(struct ElementListNodeStruct,1);
RecordAllocation( Matrix, (void *)Matrix->FirstElementListNode );
if (Matrix->Error == spNO_MEMORY) return;
Matrix->LastElementListNode = Matrix->FirstElementListNode;
@ -423,14 +423,14 @@ InitializeElementBlocks(MatrixPtr Matrix, int InitialNumberOfElements,
Matrix->FirstElementListNode->Next = NULL;
/* Allocate block of MatrixElements for fill-ins. */
pElement = ALLOC(struct MatrixElement, NumberOfFillinsExpected);
pElement = SP_MALLOC(struct MatrixElement, NumberOfFillinsExpected);
RecordAllocation( Matrix, (void *)pElement );
if (Matrix->Error == spNO_MEMORY) return;
Matrix->FillinsRemaining = NumberOfFillinsExpected;
Matrix->NextAvailFillin = pElement;
/* Allocate a fill-in list structure. */
Matrix->FirstFillinListNode = ALLOC(struct FillinListNodeStruct,1);
Matrix->FirstFillinListNode = SP_MALLOC(struct FillinListNodeStruct,1);
RecordAllocation( Matrix, (void *)Matrix->FirstFillinListNode );
if (Matrix->Error == spNO_MEMORY) return;
Matrix->LastFillinListNode = Matrix->FirstFillinListNode;
@ -490,14 +490,14 @@ spcGetFillin(MatrixPtr Matrix)
Matrix->NextAvailFillin = pListNode->pFillinList;
} else {
/* Allocate block of fill-ins. */
pFillins = ALLOC(struct MatrixElement, ELEMENTS_PER_ALLOCATION);
pFillins = SP_MALLOC(struct MatrixElement, ELEMENTS_PER_ALLOCATION);
RecordAllocation( Matrix, (void *)pFillins );
if (Matrix->Error == spNO_MEMORY) return NULL;
Matrix->FillinsRemaining = ELEMENTS_PER_ALLOCATION;
Matrix->NextAvailFillin = pFillins;
/* Allocate a fill-in list structure. */
pListNode->Next = ALLOC(struct FillinListNodeStruct,1);
pListNode->Next = SP_MALLOC(struct FillinListNodeStruct,1);
RecordAllocation( Matrix, (void *)pListNode->Next );
if (Matrix->Error == spNO_MEMORY) return NULL;
Matrix->LastFillinListNode = pListNode = pListNode->Next;
@ -553,7 +553,7 @@ RecordAllocation(MatrixPtr Matrix, void *AllocatedPtr )
if (Matrix->RecordsRemaining == 0) {
AllocateBlockOfAllocationList( Matrix );
if (Matrix->Error == spNO_MEMORY) {
FREE(AllocatedPtr);
SP_FREE(AllocatedPtr);
return;
}
}
@ -597,7 +597,7 @@ AllocateBlockOfAllocationList(MatrixPtr Matrix)
/* Begin `AllocateBlockOfAllocationList'. */
/* Allocate block of records for allocation list. */
ListPtr = ALLOC(struct AllocationRecord, (ELEMENTS_PER_ALLOCATION+1));
ListPtr = SP_MALLOC(struct AllocationRecord, (ELEMENTS_PER_ALLOCATION+1));
if (ListPtr == NULL) {
Matrix->Error = spNO_MEMORY;
return;
@ -660,19 +660,19 @@ spDestroy(MatrixPtr eMatrix)
assert( IS_SPARSE( Matrix ) );
/* Deallocate the vectors that are located in the matrix frame. */
FREE( Matrix->IntToExtColMap );
FREE( Matrix->IntToExtRowMap );
FREE( Matrix->ExtToIntColMap );
FREE( Matrix->ExtToIntRowMap );
FREE( Matrix->Diag );
FREE( Matrix->FirstInRow );
FREE( Matrix->FirstInCol );
FREE( Matrix->MarkowitzRow );
FREE( Matrix->MarkowitzCol );
FREE( Matrix->MarkowitzProd );
FREE( Matrix->DoCmplxDirect );
FREE( Matrix->DoRealDirect );
FREE( Matrix->Intermediate );
SP_FREE( Matrix->IntToExtColMap );
SP_FREE( Matrix->IntToExtRowMap );
SP_FREE( Matrix->ExtToIntColMap );
SP_FREE( Matrix->ExtToIntRowMap );
SP_FREE( Matrix->Diag );
SP_FREE( Matrix->FirstInRow );
SP_FREE( Matrix->FirstInCol );
SP_FREE( Matrix->MarkowitzRow );
SP_FREE( Matrix->MarkowitzCol );
SP_FREE( Matrix->MarkowitzProd );
SP_FREE( Matrix->DoCmplxDirect );
SP_FREE( Matrix->DoRealDirect );
SP_FREE( Matrix->Intermediate );
/* Sequentially step through the list of allocated pointers
* freeing pointers along the way. */
@ -680,9 +680,9 @@ spDestroy(MatrixPtr eMatrix)
while (ListPtr != NULL) {
NextListPtr = ListPtr->NextRecord;
if ((void *) ListPtr == ListPtr->AllocatedPtr) {
FREE( ListPtr );
SP_FREE( ListPtr );
} else {
FREE( ListPtr->AllocatedPtr );
SP_FREE( ListPtr->AllocatedPtr );
}
ListPtr = NextListPtr;
}

View File

@ -972,27 +972,27 @@ EnlargeMatrix(MatrixPtr Matrix, int NewSize)
NewSize = MAX( NewSize, EXPANSION_FACTOR * OldAllocatedSize );
Matrix->AllocatedSize = NewSize;
if (( REALLOC(Matrix->IntToExtColMap, int, NewSize+1)) == NULL)
if (( SP_REALLOC(Matrix->IntToExtColMap, int, NewSize+1)) == NULL)
{
Matrix->Error = spNO_MEMORY;
return;
}
if (( REALLOC(Matrix->IntToExtRowMap, int, NewSize+1)) == NULL)
if (( SP_REALLOC(Matrix->IntToExtRowMap, int, NewSize+1)) == NULL)
{
Matrix->Error = spNO_MEMORY;
return;
}
if (( REALLOC(Matrix->Diag, ElementPtr, NewSize+1)) == NULL)
if (( SP_REALLOC(Matrix->Diag, ElementPtr, NewSize+1)) == NULL)
{
Matrix->Error = spNO_MEMORY;
return;
}
if (( REALLOC(Matrix->FirstInCol, ElementPtr, NewSize+1)) == NULL)
if (( SP_REALLOC(Matrix->FirstInCol, ElementPtr, NewSize+1)) == NULL)
{
Matrix->Error = spNO_MEMORY;
return;
}
if (( REALLOC(Matrix->FirstInRow, ElementPtr, NewSize+1)) == NULL)
if (( SP_REALLOC(Matrix->FirstInRow, ElementPtr, NewSize+1)) == NULL)
{
Matrix->Error = spNO_MEMORY;
return;
@ -1000,12 +1000,12 @@ EnlargeMatrix(MatrixPtr Matrix, int NewSize)
/* Destroy the Markowitz and Intermediate vectors, they will be
* recreated in spOrderAndFactor(). */
FREE( Matrix->MarkowitzRow );
FREE( Matrix->MarkowitzCol );
FREE( Matrix->MarkowitzProd );
FREE( Matrix->DoRealDirect );
FREE( Matrix->DoCmplxDirect );
FREE( Matrix->Intermediate );
SP_FREE( Matrix->MarkowitzRow );
SP_FREE( Matrix->MarkowitzCol );
SP_FREE( Matrix->MarkowitzProd );
SP_FREE( Matrix->DoRealDirect );
SP_FREE( Matrix->DoCmplxDirect );
SP_FREE( Matrix->Intermediate );
Matrix->InternalVectorsAllocated = NO;
/* Initialize the new portion of the vectors. */
@ -1062,12 +1062,12 @@ ExpandTranslationArrays(MatrixPtr Matrix, int NewSize)
NewSize = MAX( NewSize, EXPANSION_FACTOR * OldAllocatedSize );
Matrix->AllocatedExtSize = NewSize;
if (( REALLOC(Matrix->ExtToIntRowMap, int, NewSize+1)) == NULL)
if (( SP_REALLOC(Matrix->ExtToIntRowMap, int, NewSize+1)) == NULL)
{
Matrix->Error = spNO_MEMORY;
return;
}
if (( REALLOC(Matrix->ExtToIntColMap, int, NewSize+1)) == NULL)
if (( SP_REALLOC(Matrix->ExtToIntColMap, int, NewSize+1)) == NULL)
{
Matrix->Error = spNO_MEMORY;
return;

View File

@ -369,20 +369,20 @@ extern void * tmalloc(size_t);
extern void txfree(void *);
extern void * trealloc(void *, size_t);
#define ALLOC(type,number) ((type *)tmalloc((size_t)(sizeof(type)*(number))))
#define REALLOC(ptr,type,number) \
#define SP_MALLOC(type,number) ((type *)tmalloc((size_t)(sizeof(type)*(number))))
#define SP_REALLOC(ptr,type,number) \
ptr = (type *)trealloc((char *)ptr,(unsigned)(sizeof(type)*(number)))
#define FREE(ptr) { if ((ptr) != NULL) txfree((char *)(ptr)); (ptr) = NULL; }
#define SP_FREE(ptr) { if ((ptr) != NULL) txfree((char *)(ptr)); (ptr) = NULL; }
/* A new calloc */
#ifndef HAVE_LIBGC
#define CALLOC(ptr,type,number) \
#define SP_CALLOC(ptr,type,number) \
{ ptr = (type *) calloc(number, sizeof(type)); \
}
#else /* HAVE_LIBCG */
#define CALLOC(ptr,type,number) \
#define SP_CALLOC(ptr,type,number) \
{ ptr = (type *) tmalloc(((size_t)number) * sizeof(type)); \
}
#endif

View File

@ -744,33 +744,33 @@ spcCreateInternalVectors( MatrixPtr Matrix )
if (Matrix->MarkowitzRow == NULL)
{
if (( Matrix->MarkowitzRow = ALLOC(int, Size+1)) == NULL)
if (( Matrix->MarkowitzRow = SP_MALLOC(int, Size+1)) == NULL)
Matrix->Error = spNO_MEMORY;
}
if (Matrix->MarkowitzCol == NULL)
{
if (( Matrix->MarkowitzCol = ALLOC(int, Size+1)) == NULL)
if (( Matrix->MarkowitzCol = SP_MALLOC(int, Size+1)) == NULL)
Matrix->Error = spNO_MEMORY;
}
if (Matrix->MarkowitzProd == NULL)
{
if (( Matrix->MarkowitzProd = ALLOC(long, Size+2)) == NULL)
if (( Matrix->MarkowitzProd = SP_MALLOC(long, Size+2)) == NULL)
Matrix->Error = spNO_MEMORY;
}
/* Create DoDirect vectors for use in spFactor(). */
if (Matrix->DoRealDirect == NULL) {
if (( Matrix->DoRealDirect = ALLOC(int, Size+1)) == NULL)
if (( Matrix->DoRealDirect = SP_MALLOC(int, Size+1)) == NULL)
Matrix->Error = spNO_MEMORY;
}
if (Matrix->DoCmplxDirect == NULL) {
if (( Matrix->DoCmplxDirect = ALLOC(int, Size+1)) == NULL)
if (( Matrix->DoCmplxDirect = SP_MALLOC(int, Size+1)) == NULL)
Matrix->Error = spNO_MEMORY;
}
/* Create Intermediate vectors for use in MatrixSolve. */
if (Matrix->Intermediate == NULL) {
if ((Matrix->Intermediate = ALLOC(RealNumber,2*(Size+1))) == NULL)
if ((Matrix->Intermediate = SP_MALLOC(RealNumber,2*(Size+1))) == NULL)
Matrix->Error = spNO_MEMORY;
}

View File

@ -148,11 +148,11 @@ spPrint(MatrixPtr eMatrix, int PrintReordered, int Data, int Header)
/* Begin `spPrint'. */
assert( IS_SPARSE( Matrix ) );
Size = Matrix->Size;
CALLOC(pImagElements, ElementPtr, Printer_Width / 10 + 1);
SP_CALLOC(pImagElements, ElementPtr, Printer_Width / 10 + 1);
if ( pImagElements == NULL)
{
Matrix->Error = spNO_MEMORY;
FREE(pImagElements);
SP_FREE(pImagElements);
return;
}
@ -163,19 +163,19 @@ spPrint(MatrixPtr eMatrix, int PrintReordered, int Data, int Header)
#else
Top = Matrix->AllocatedSize;
#endif
CALLOC( PrintOrdToIntRowMap, int, Top + 1 );
SP_CALLOC( PrintOrdToIntRowMap, int, Top + 1 );
if ( PrintOrdToIntRowMap == NULL)
{
Matrix->Error = spNO_MEMORY;
FREE(pImagElements);
SP_FREE(pImagElements);
return;
}
CALLOC( PrintOrdToIntColMap, int, Top + 1 );
SP_CALLOC( PrintOrdToIntColMap, int, Top + 1 );
if (PrintOrdToIntColMap == NULL)
{
Matrix->Error = spNO_MEMORY;
FREE(pImagElements);
FREE(PrintOrdToIntRowMap);
SP_FREE(pImagElements);
SP_FREE(PrintOrdToIntRowMap);
return;
}
for (I = 1; I <= Size; I++)
@ -377,8 +377,8 @@ spPrint(MatrixPtr eMatrix, int PrintReordered, int Data, int Header)
putchar('\n');
(void)fflush(stdout);
FREE(PrintOrdToIntColMap);
FREE(PrintOrdToIntRowMap);
SP_FREE(PrintOrdToIntColMap);
SP_FREE(PrintOrdToIntRowMap);
return;
}

View File

@ -1634,7 +1634,7 @@ int *pError;
Size = Matrix->Size;
T = (ComplexVector)Matrix->Intermediate;
Tm = ALLOC( ComplexNumber, Size+1 );
Tm = SP_MALLOC( ComplexNumber, Size+1 );
if (Tm == NULL)
{
*pError = spNO_MEMORY;
@ -1800,7 +1800,7 @@ int *pError;
/* Compute 1-norm of T, which now contains z. */
for (ASz = 0.0, I = Size; I > 0; I--) ASz += CMPLX_1_NORM(T[I]);
FREE( Tm );
SP_FREE( Tm );
Linpack = ASy / ASz;
OLeary = E / MaxY;