SWZ: replace malloc with swzMalloc
parent
a7f5b6f557
commit
08f2b2b5c4
|
@ -25,12 +25,11 @@ extern int constant_seed;
|
|||
|
||||
#define swz_fprintf_stdout mexPrintf
|
||||
|
||||
#undef malloc
|
||||
#undef calloc
|
||||
#undef realloc
|
||||
#undef free
|
||||
|
||||
#define malloc mxMalloc
|
||||
#define swzMalloc mxMalloc
|
||||
#define calloc mxCalloc
|
||||
#define realloc mxRealloc
|
||||
#define free mxFree
|
||||
|
@ -38,4 +37,5 @@ extern int constant_seed;
|
|||
|
||||
#else
|
||||
#define swz_fprintf_stdout printf
|
||||
#define swzMalloc malloc
|
||||
#endif
|
||||
|
|
|
@ -141,7 +141,7 @@ TMarkovStateVariable* CreateMarkovStateVariable_Single(int nstates, int nobs, TM
|
|||
exit(0);
|
||||
}
|
||||
|
||||
if (!(sv=(TMarkovStateVariable*)malloc(sizeof(TMarkovStateVariable))))
|
||||
if (!(sv=(TMarkovStateVariable*)swzMalloc(sizeof(TMarkovStateVariable))))
|
||||
{
|
||||
swz_fprintf_err("CreateMarkovStateVariable(): out of memory\n");
|
||||
exit(0);
|
||||
|
@ -266,7 +266,7 @@ TMarkovStateVariable* CreateMarkovStateVariable_Multiple(int nobs, int n_state_v
|
|||
exit(0);
|
||||
}
|
||||
|
||||
if (!(sv=(TMarkovStateVariable*)malloc(sizeof(TMarkovStateVariable))))
|
||||
if (!(sv=(TMarkovStateVariable*)swzMalloc(sizeof(TMarkovStateVariable))))
|
||||
{
|
||||
printf("CreateMarkovStateVariable_Multiple(): out of memory\n");
|
||||
exit(0);
|
||||
|
@ -527,7 +527,7 @@ TMarkovStateVariable* RestrictMarkovStateVariable(TMarkovStateVariable *sv, int
|
|||
|
||||
if (nstates == sv->nstates) return DuplicateMarkovStateVariable(sv);
|
||||
|
||||
free_translation=(int*)malloc(DimV(sv->B)*sizeof(int));
|
||||
free_translation=(int*)swzMalloc(DimV(sv->B)*sizeof(int));
|
||||
|
||||
/* // free_translation[i] = 1 if B[i] is accessed ansi-c*/
|
||||
for (i=DimV(sv->B)-1; i >= 0; i--) free_translation[i]=0;
|
||||
|
@ -1353,7 +1353,7 @@ int** CreateTranslationMatrix_Flat(int **states, TMarkovStateVariable *sv)
|
|||
/*******************************************************************************/
|
||||
ThetaRoutines* CreateThetaRoutines_empty(void)
|
||||
{
|
||||
ThetaRoutines* pRoutines=(ThetaRoutines*)malloc(sizeof(ThetaRoutines));
|
||||
ThetaRoutines* pRoutines=(ThetaRoutines*)swzMalloc(sizeof(ThetaRoutines));
|
||||
|
||||
if (pRoutines)
|
||||
{
|
||||
|
@ -1415,7 +1415,7 @@ TStateModel* CreateStateModel_new(TMarkovStateVariable *sv, ThetaRoutines *routi
|
|||
int t;
|
||||
TStateModel *model;
|
||||
|
||||
if (!(model=(TStateModel*)malloc(sizeof(TStateModel))))
|
||||
if (!(model=(TStateModel*)swzMalloc(sizeof(TStateModel))))
|
||||
{
|
||||
swz_fprintf_err("CreateStateModel(): Out of memory\n");
|
||||
exit(0);
|
||||
|
@ -1444,7 +1444,7 @@ TStateModel* CreateStateModel_new(TMarkovStateVariable *sv, ThetaRoutines *routi
|
|||
|
||||
/* //=== Obsolete fields === ansi-c*/
|
||||
model->parameters=theta;
|
||||
model->p=(TParameters*)malloc(sizeof(TParameters));
|
||||
model->p=(TParameters*)swzMalloc(sizeof(TParameters));
|
||||
model->p->pLogConditionalLikelihood=model->routines->pLogConditionalLikelihood;
|
||||
model->p->pParameterDestructor=model->routines->pDestructor;
|
||||
model->p->pLogPrior=model->routines->pLogPrior;
|
||||
|
@ -1726,7 +1726,7 @@ int NormalizeStates(TStateModel *model)
|
|||
|
||||
/* if (!(model->NormalizeStates)) return 1; */
|
||||
|
||||
/* if (p=(int*)malloc(model->sv->nstates)) */
|
||||
/* if (p=(int*)swzMalloc(model->sv->nstates)) */
|
||||
/* { */
|
||||
/* if (model->routines->pGetNormalization(p,model)) */
|
||||
/* if (Permute_SV(p,model->sv)) */
|
||||
|
@ -2994,7 +2994,7 @@ TParameters* CreateParameters(PRECISION (*pLogConditionalLikelihood)(int,int,str
|
|||
void (*pDrawParameters)(struct TStateModel_tag*),
|
||||
void *parameters)
|
||||
{
|
||||
TParameters* p=(TParameters*)malloc(sizeof(TParameters));
|
||||
TParameters* p=(TParameters*)swzMalloc(sizeof(TParameters));
|
||||
if (p)
|
||||
{
|
||||
p->pLogConditionalLikelihood=pLogConditionalLikelihood;
|
||||
|
|
|
@ -568,7 +568,7 @@ TStateModel* CreateStateModel(TMarkovStateVariable *sv, TParameters *p);
|
|||
techniques are used and the following must be true.
|
||||
|
||||
All of pElementV(BA[i]), pElementM(QA[i]), and pElementIV(SA[i]) were
|
||||
allocated with malloc(), can be freed with free(), and none of
|
||||
allocated with swzMalloc(), can be freed with free(), and none of
|
||||
FreeVector(BA[i]), FreeMatrix(QA[i]), or FreeIntMatrix(SA[i]) attempt
|
||||
to free pElemementV(BA[i]), pElementM(QA[i]), or pElementIV(SA[i]) if
|
||||
these are null pointers.
|
||||
|
|
|
@ -34,7 +34,7 @@ void SetupObjectiveFunction_new(TStateModel *model, int FreeTheta_Idx, int FreeQ
|
|||
Model=model;
|
||||
NumberFreeParameters_Q=NumberFreeParametersQ(model);
|
||||
NumberFreeParameters_Theta=model->routines->pNumberFreeParametersTheta(model);
|
||||
buffer=(PRECISION*)malloc((NumberFreeParameters_Q + NumberFreeParameters_Theta)*sizeof(PRECISION));
|
||||
buffer=(PRECISION*)swzMalloc((NumberFreeParameters_Q + NumberFreeParameters_Theta)*sizeof(PRECISION));
|
||||
|
||||
FreeParameters_Q=buffer+FreeQ_Idx;
|
||||
FreeParameters_Theta=buffer+FreeTheta_Idx;
|
||||
|
|
|
@ -41,10 +41,10 @@ static void ReadError(char *idformat, char *trailer, int error)
|
|||
return;
|
||||
}
|
||||
if (trailer)
|
||||
sprintf(idbuffer=(char*)malloc(strlen(idformat)+strlen(trailer)-1),idformat,trailer);
|
||||
sprintf(idbuffer=(char*)swzMalloc(strlen(idformat)+strlen(trailer)-1),idformat,trailer);
|
||||
else
|
||||
idbuffer=idformat;
|
||||
sprintf(errmsg=(char*)malloc(strlen(format)+strlen(idbuffer)-1),format,idbuffer);
|
||||
sprintf(errmsg=(char*)swzMalloc(strlen(format)+strlen(idbuffer)-1),format,idbuffer);
|
||||
dw_UserError(errmsg);
|
||||
free(errmsg);
|
||||
if (idbuffer != idformat) free(idbuffer);
|
||||
|
@ -66,7 +66,7 @@ static int SetFilePosition(FILE *f_in, char *format, char *str)
|
|||
char *buffer;
|
||||
int rtrn;
|
||||
if (str)
|
||||
sprintf(buffer=(char*)malloc(strlen(format)+strlen(str)-1),format,str);
|
||||
sprintf(buffer=(char*)swzMalloc(strlen(format)+strlen(str)-1),format,str);
|
||||
else
|
||||
buffer=format;
|
||||
rtrn=dw_SetFilePosition(f_in,buffer);
|
||||
|
@ -151,9 +151,9 @@ TMarkovStateVariable* ReadMarkovSpecification_SV(FILE *f_in, char *idstring, int
|
|||
{
|
||||
/* // Construct trailer ansi-c*/
|
||||
if (idstring[0])
|
||||
sprintf(trailer=(char*)malloc(24+strlen(idstring)),"for state_variable%s ==//",idstring);
|
||||
sprintf(trailer=(char*)swzMalloc(24+strlen(idstring)),"for state_variable%s ==//",idstring);
|
||||
else
|
||||
strcpy(trailer=(char*)malloc(5),"==//");
|
||||
strcpy(trailer=(char*)swzMalloc(5),"==//");
|
||||
|
||||
/* // Read number of state variables ansi-c*/
|
||||
if (!(err=ReadInteger(f_in,idformat="//== Number independent state variables %s",trailer,&n_state_variables)))
|
||||
|
@ -162,7 +162,7 @@ TMarkovStateVariable* ReadMarkovSpecification_SV(FILE *f_in, char *idstring, int
|
|||
{
|
||||
sv_array=(TMarkovStateVariable**)dw_CreateArray_pointer(n_state_variables,(void (*)(void*))FreeMarkovStateVariable);
|
||||
for (j=10, i=1; n_state_variables/j > 0; j*=10, i++);
|
||||
strcpy(idstring_new=(char*)malloc((j=(int)strlen(idstring))+i+3),idstring);
|
||||
strcpy(idstring_new=(char*)swzMalloc((j=(int)strlen(idstring))+i+3),idstring);
|
||||
for (i=0; i < n_state_variables; i++)
|
||||
{
|
||||
sprintf(idstring_new+j,"[%d]",i+1);
|
||||
|
@ -259,14 +259,14 @@ int WriteMarkovSpecification_SV(FILE *f_out, TMarkovStateVariable *sv, char *ids
|
|||
if (idstring[0])
|
||||
{
|
||||
/* // 24 characters in "for state_variable ==//" plus null character ansi-c*/
|
||||
trailer=(char*)malloc(24+strlen(idstring));
|
||||
trailer=(char*)swzMalloc(24+strlen(idstring));
|
||||
sprintf(trailer,"for state_variable%s ==//",idstring);
|
||||
|
||||
fprintf(f_out,"//****** Specification %s ******//\n\n",trailer);
|
||||
}
|
||||
else
|
||||
{
|
||||
trailer=(char*)malloc(5);
|
||||
trailer=(char*)swzMalloc(5);
|
||||
strcpy(trailer,"==//");
|
||||
|
||||
fprintf(f_out,"//== Number observations ==//\n%d\n\n",sv->nobs);
|
||||
|
@ -279,7 +279,7 @@ int WriteMarkovSpecification_SV(FILE *f_out, TMarkovStateVariable *sv, char *ids
|
|||
{
|
||||
fprintf(f_out,"//******************************************//\n\n");
|
||||
for (j=10, i=1; sv->n_state_variables >= j; j*=10, i++);
|
||||
strcpy(idbuffer=(char*)malloc((j=(int)strlen(idstring))+i+3),idstring);
|
||||
strcpy(idbuffer=(char*)swzMalloc((j=(int)strlen(idstring))+i+3),idstring);
|
||||
for (i=0; i < sv->n_state_variables; i++)
|
||||
{
|
||||
sprintf(idbuffer+j,"[%d]",i+1);
|
||||
|
@ -381,7 +381,7 @@ int ReadTransitionMatrices_SV(FILE *f_in, TMarkovStateVariable* sv, char *header
|
|||
if (sv->n_state_variables > 1)
|
||||
{
|
||||
for (j=10, i=1; sv->n_state_variables >= j; j*=10, i++);
|
||||
strcpy(idbuffer=(char*)malloc((j=(int)strlen(idstring))+i+3),idstring);
|
||||
strcpy(idbuffer=(char*)swzMalloc((j=(int)strlen(idstring))+i+3),idstring);
|
||||
for (i=sv->n_state_variables-1; i >= 0; i--)
|
||||
{
|
||||
sprintf(idbuffer+j,"[%d]",i+1);
|
||||
|
@ -400,13 +400,13 @@ int ReadTransitionMatrices_SV(FILE *f_in, TMarkovStateVariable* sv, char *header
|
|||
/* // Read transition matrix ansi-c*/
|
||||
if (!header) header="";
|
||||
format="//== %sTransition matrix%s ==//";
|
||||
sprintf(idbuffer=(char*)malloc(strlen(header) + strlen(format) + strlen(idstring) - 3),format,header,idstring);
|
||||
sprintf(idbuffer=(char*)swzMalloc(strlen(header) + strlen(format) + strlen(idstring) - 3),format,header,idstring);
|
||||
if (err=ReadMatrix(f_in,idbuffer,(char*)NULL,sv->Q))
|
||||
if (!idstring[0])
|
||||
{
|
||||
free(idbuffer);
|
||||
idstring="[1]";
|
||||
sprintf(idbuffer=(char*)malloc(strlen(header) + strlen(format) + strlen(idstring) - 3),format,header,idstring);
|
||||
sprintf(idbuffer=(char*)swzMalloc(strlen(header) + strlen(format) + strlen(idstring) - 3),format,header,idstring);
|
||||
err=ReadMatrix(f_in,idbuffer,(char*)NULL,sv->Q);
|
||||
}
|
||||
free(idbuffer);
|
||||
|
@ -504,7 +504,7 @@ int ReadBaseTransitionMatrices_SV(FILE *f_in, TMarkovStateVariable* sv, char *he
|
|||
if (sv->n_state_variables > 1)
|
||||
{
|
||||
for (j=10, i=1; sv->n_state_variables >= j; j*=10, i++);
|
||||
strcpy(idbuffer=(char*)malloc((j=(int)strlen(idstring))+i+3),idstring);
|
||||
strcpy(idbuffer=(char*)swzMalloc((j=(int)strlen(idstring))+i+3),idstring);
|
||||
for (i=sv->n_state_variables-1; i >= 0; i--)
|
||||
{
|
||||
sprintf(idbuffer+j,"[%d]",i+1);
|
||||
|
@ -524,13 +524,13 @@ int ReadBaseTransitionMatrices_SV(FILE *f_in, TMarkovStateVariable* sv, char *he
|
|||
Q=CreateMatrix(sv->nbasestates,sv->nbasestates);
|
||||
if (!header) header="";
|
||||
format="//== %sBase transition matrix%s ==//";
|
||||
sprintf(idbuffer=(char*)malloc(strlen(header) + strlen(format) + strlen(idstring) - 3),format,header,idstring);
|
||||
sprintf(idbuffer=(char*)swzMalloc(strlen(header) + strlen(format) + strlen(idstring) - 3),format,header,idstring);
|
||||
if (err=ReadMatrix(f_in,idbuffer,(char*)NULL,Q))
|
||||
if (!idstring[0])
|
||||
{
|
||||
free(idbuffer);
|
||||
idstring="[1]";
|
||||
sprintf(idbuffer=(char*)malloc(strlen(header) + strlen(format) + strlen(idstring) - 3),format,header,idstring);
|
||||
sprintf(idbuffer=(char*)swzMalloc(strlen(header) + strlen(format) + strlen(idstring) - 3),format,header,idstring);
|
||||
err=ReadMatrix(f_in,idbuffer,(char*)NULL,Q);
|
||||
}
|
||||
free(idbuffer);
|
||||
|
@ -606,7 +606,7 @@ int WriteTransitionMatrices_SV(FILE *f_out, TMarkovStateVariable* sv, char *head
|
|||
if (sv->n_state_variables > 1)
|
||||
{
|
||||
for (j=10, i=1; sv->n_state_variables >= j; j*=10, i++);
|
||||
strcpy(idbuffer=(char*)malloc((j=(int)strlen(idstring))+i+3),idstring);
|
||||
strcpy(idbuffer=(char*)swzMalloc((j=(int)strlen(idstring))+i+3),idstring);
|
||||
for (i=0; i < sv->n_state_variables; i++)
|
||||
{
|
||||
sprintf(idbuffer+j,"[%d]",i+1);
|
||||
|
@ -657,7 +657,7 @@ int WriteBaseTransitionMatrices_SV(FILE *f_out, TMarkovStateVariable* sv, char *
|
|||
if (sv->n_state_variables > 1)
|
||||
{
|
||||
for (j=10, i=1; sv->n_state_variables >= j; j*=10, i++);
|
||||
strcpy(idbuffer=(char*)malloc((j=(int)strlen(idstring))+i+3),idstring);
|
||||
strcpy(idbuffer=(char*)swzMalloc((j=(int)strlen(idstring))+i+3),idstring);
|
||||
for (i=0; i < sv->n_state_variables; i++)
|
||||
{
|
||||
sprintf(idbuffer+j,"[%d]",i+1);
|
||||
|
@ -696,7 +696,7 @@ void WriteBaseTransitionMatricesFlat_Headers_SV(FILE *f_out, TMarkovStateVariabl
|
|||
if (sv->n_state_variables > 1)
|
||||
{
|
||||
for (j=10, i=1; sv->n_state_variables >= j; j*=10, i++);
|
||||
strcpy(idbuffer=(char*)malloc((j=(int)strlen(idstring))+i+3),idstring);
|
||||
strcpy(idbuffer=(char*)swzMalloc((j=(int)strlen(idstring))+i+3),idstring);
|
||||
for (i=0; i < sv->n_state_variables; i++)
|
||||
{
|
||||
sprintf(idbuffer+j,"[%d]",i+1);
|
||||
|
|
|
@ -191,7 +191,7 @@ T_VAR_Parameters* CreateTheta_VAR(int flag, int nvars, int nlags, int nexg, int
|
|||
}
|
||||
|
||||
/* //=== Allocate memory for T_VAR_Parameters === ansi-c*/
|
||||
if (!(p=(T_VAR_Parameters*)malloc(sizeof(T_VAR_Parameters))))
|
||||
if (!(p=(T_VAR_Parameters*)swzMalloc(sizeof(T_VAR_Parameters))))
|
||||
{
|
||||
swz_fprintf_err("Out of memory\n");
|
||||
exit(0);
|
||||
|
@ -611,8 +611,8 @@ int **ExpandTranslationTable(int **table, TMarkovStateVariable *sv, TMarkovState
|
|||
dw_InitializeArray_int(rtable=dw_CreateRectangularArray_int(dw_DimA(table),nstates),0);
|
||||
|
||||
/* // Fill table ansi-c*/
|
||||
idx=(int*)malloc(sv->nstates*sizeof(int));
|
||||
master=(int*)malloc(nstates*sizeof(int));
|
||||
idx=(int*)swzMalloc(sv->nstates*sizeof(int));
|
||||
master=(int*)swzMalloc(nstates*sizeof(int));
|
||||
for (k=i=0; k < sv->nstates; k++)
|
||||
{
|
||||
for (j=sv->n_state_variables-1; j >= 0; j--)
|
||||
|
@ -1314,7 +1314,7 @@ void AdaptiveMetropolisScale(TStateModel *model, int iterations, int period, int
|
|||
Adaptive[j]=(struct TAdaptive**)dw_CreateArray_pointer(p->n_coef_states[j],free);
|
||||
for (k=p->n_coef_states[j]-1; k >= 0; k--)
|
||||
{
|
||||
Adaptive[j][k]=((struct TAdaptive*)malloc(sizeof(struct TAdaptive)));
|
||||
Adaptive[j][k]=((struct TAdaptive*)swzMalloc(sizeof(struct TAdaptive)));
|
||||
Adaptive[j][k]->begin_jump_ratio=p->A0_Metropolis_Jumps[j][k];
|
||||
Adaptive[j][k]->iterations=period;
|
||||
Adaptive[j][k]->end_iteration_count=period;
|
||||
|
|
|
@ -20,7 +20,7 @@ static int strlen_int(int n)
|
|||
static void ReadError_VARio(char *id)
|
||||
{
|
||||
char *errmsg, *fmt="Error after line identifier ""%s""";
|
||||
sprintf(errmsg=(char*)malloc(strlen(fmt) + strlen(id) - 1),fmt,id);
|
||||
sprintf(errmsg=(char*)swzMalloc(strlen(fmt) + strlen(id) - 1),fmt,id);
|
||||
dw_UserError(errmsg);
|
||||
free(errmsg);
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ static FILE* OpenFile_VARio(FILE *f, char *filename)
|
|||
else
|
||||
if (!(f=fopen(filename,"rt")))
|
||||
{
|
||||
sprintf(errmsg=(char*)malloc(strlen(fmt) + strlen(filename) - 1),fmt,filename);
|
||||
sprintf(errmsg=(char*)swzMalloc(strlen(fmt) + strlen(filename) - 1),fmt,filename);
|
||||
dw_UserError(errmsg);
|
||||
free(errmsg);
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ TStateModel* Read_VAR_Specification(FILE *f, char *filename)
|
|||
for (j=0; j < nvars; j++)
|
||||
{
|
||||
fmt="//== U[%d] ==//";
|
||||
sprintf(id=(char*)malloc(strlen(fmt) + strlen_int(j+1) - 1),fmt,j+1);
|
||||
sprintf(id=(char*)swzMalloc(strlen(fmt) + strlen_int(j+1) - 1),fmt,j+1);
|
||||
ReadMatrix_VARio(f_in,id,U[j]=CreateMatrix(nvars,IV[j]));
|
||||
free(id);
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ TStateModel* Read_VAR_Specification(FILE *f, char *filename)
|
|||
if (IV[j] > 0)
|
||||
{
|
||||
fmt="//== V[%d] ==//";
|
||||
sprintf(id=(char*)malloc(strlen(fmt) + strlen_int(j+1) - 1),fmt,j+1);
|
||||
sprintf(id=(char*)swzMalloc(strlen(fmt) + strlen_int(j+1) - 1),fmt,j+1);
|
||||
ReadMatrix_VARio(f_in,id,V[j]=CreateMatrix(npre,IV[j]));
|
||||
free(id);
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ TStateModel* Read_VAR_Specification(FILE *f, char *filename)
|
|||
if (IV[j])
|
||||
{
|
||||
fmt="//== W[%d] ==//";
|
||||
sprintf(id=(char*)malloc(strlen(fmt) + strlen_int(j+1) - 1),fmt,j+1);
|
||||
sprintf(id=(char*)swzMalloc(strlen(fmt) + strlen_int(j+1) - 1),fmt,j+1);
|
||||
ReadMatrix_VARio(f_in,id,W[j]=CreateMatrix(npre,nvars));
|
||||
free(id);
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ TStateModel* Read_VAR_Specification(FILE *f, char *filename)
|
|||
for (j=0; j < nvars; j++)
|
||||
{
|
||||
fmt="//== Variance of Gaussian prior on column %d of A0 ==//";
|
||||
sprintf(id=(char*)malloc(strlen(fmt) + strlen_int(j+1) - 1),fmt,j+1);
|
||||
sprintf(id=(char*)swzMalloc(strlen(fmt) + strlen_int(j+1) - 1),fmt,j+1);
|
||||
ReadMatrix_VARio(f_in,id,A0_prior[j]=CreateMatrix(nvars,nvars));
|
||||
free(id);
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ TStateModel* Read_VAR_Specification(FILE *f, char *filename)
|
|||
for (j=0; j < nvars; j++)
|
||||
{
|
||||
fmt="//== Variance of Gaussian prior on column %d of Aplus ==//";
|
||||
sprintf(id=(char*)malloc(strlen(fmt) + strlen_int(j+1) - 1),fmt,j+1);
|
||||
sprintf(id=(char*)swzMalloc(strlen(fmt) + strlen_int(j+1) - 1),fmt,j+1);
|
||||
ReadMatrix_VARio(f_in,id,Aplus_prior[j]=CreateMatrix(npre,npre));
|
||||
free(id);
|
||||
}
|
||||
|
@ -419,7 +419,7 @@ int Read_VAR_Parameters(FILE *f, char *filename, char *header, TStateModel *mode
|
|||
for (s=0; s < p->nstates; s++)
|
||||
{
|
||||
fmt="//== %sA0[%d] ==//";
|
||||
sprintf(idbuffer=(char*)malloc(strlen(fmt)+strlen(header)+strlen_int(s+1)-3),fmt,header,s+1);
|
||||
sprintf(idbuffer=(char*)swzMalloc(strlen(fmt)+strlen(header)+strlen_int(s+1)-3),fmt,header,s+1);
|
||||
if (!dw_SetFilePosition(f_in,idbuffer) || !dw_ReadMatrix(f_in,A0[s]=CreateMatrix(p->nvars,p->nvars)))
|
||||
{
|
||||
ReadError_VARio(idbuffer);
|
||||
|
@ -429,7 +429,7 @@ int Read_VAR_Parameters(FILE *f, char *filename, char *header, TStateModel *mode
|
|||
free(idbuffer);
|
||||
|
||||
fmt="//== %sAplus[%d] ==//";
|
||||
sprintf(idbuffer=(char*)malloc(strlen(fmt)+strlen(header)+strlen_int(s+1)-3),fmt,header,s+1);
|
||||
sprintf(idbuffer=(char*)swzMalloc(strlen(fmt)+strlen(header)+strlen_int(s+1)-3),fmt,header,s+1);
|
||||
if (!dw_SetFilePosition(f_in,idbuffer) || !dw_ReadMatrix(f_in,Aplus[s]=CreateMatrix(p->npre,p->nvars)))
|
||||
{
|
||||
ReadError_VARio(idbuffer);
|
||||
|
@ -439,7 +439,7 @@ int Read_VAR_Parameters(FILE *f, char *filename, char *header, TStateModel *mode
|
|||
free(idbuffer);
|
||||
|
||||
fmt="//== %sZeta[%d] ==//";
|
||||
sprintf(idbuffer=(char*)malloc(strlen(fmt)+strlen(header)+strlen_int(s+1)-3),fmt,header,s+1);
|
||||
sprintf(idbuffer=(char*)swzMalloc(strlen(fmt)+strlen(header)+strlen_int(s+1)-3),fmt,header,s+1);
|
||||
if (!dw_SetFilePosition(f_in,idbuffer) || !dw_ReadMatrix(f_in,Zeta[s]=CreateMatrix(p->nvars,p->nvars)))
|
||||
{
|
||||
ReadError_VARio(idbuffer);
|
||||
|
@ -677,7 +677,7 @@ void ReadAllParameters(FILE *f, char *filename, char *id, TStateModel *model)
|
|||
|
||||
if (!id) id="";
|
||||
|
||||
sprintf(buffer=(char*)malloc(strlen(fmt) + strlen(id) - 1),fmt,id);
|
||||
sprintf(buffer=(char*)swzMalloc(strlen(fmt) + strlen(id) - 1),fmt,id);
|
||||
ReadArray_VARio(f_in,buffer,model->sv->S);
|
||||
free(buffer);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
static int ReadError_VARio_matlab(char *id)
|
||||
{
|
||||
char *errmsg, *fmt="Error after line identifier ""%s""";
|
||||
sprintf(errmsg=(char*)malloc(strlen(fmt) + strlen(id) - 1),fmt,id);
|
||||
sprintf(errmsg=(char*)swzMalloc(strlen(fmt) + strlen(id) - 1),fmt,id);
|
||||
dw_UserError(errmsg);
|
||||
free(errmsg);
|
||||
return 1;
|
||||
|
|
|
@ -26,7 +26,7 @@ char* CreateFilenameFromTag(char *fmt, char *tag, char *dir)
|
|||
char *filename;
|
||||
if (!tag) tag="";
|
||||
if (!dir) dir="";
|
||||
sprintf(filename=(char*)malloc(strlen(dir) + strlen(fmt) + strlen(tag) - 3),fmt,dir,tag);
|
||||
sprintf(filename=(char*)swzMalloc(strlen(dir) + strlen(fmt) + strlen(tag) - 3),fmt,dir,tag);
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ char* CreatePath(char *path)
|
|||
n=(int)strlen(path);
|
||||
if (path[0] && path[n-1] != DIR_DELIMITER)
|
||||
{
|
||||
memcpy(fullpath=(char*)malloc(n+2),path,n);
|
||||
memcpy(fullpath=(char*)swzMalloc(n+2),path,n);
|
||||
fullpath[n]=DIR_DELIMITER;
|
||||
fullpath[n+1]='\0';
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ void PrintHelpMessages(FILE *f, char **include, char **additional)
|
|||
|
||||
TVARCommandLine* Create_VARCommandLine(void)
|
||||
{
|
||||
TVARCommandLine *cmd=(TVARCommandLine*)malloc(sizeof(TVARCommandLine));
|
||||
TVARCommandLine *cmd=(TVARCommandLine*)swzMalloc(sizeof(TVARCommandLine));
|
||||
if (cmd)
|
||||
{
|
||||
cmd->out_directory=(char*)NULL;
|
||||
|
@ -367,7 +367,7 @@ int GetLastIteration(TStateModel *model, TVARCommandLine *cmd)
|
|||
do
|
||||
{
|
||||
for (j=10, i=1; k >= j; j*=10, i++);
|
||||
sprintf(header=(char*)malloc(strlen(fmt) + i - 1),fmt,k);
|
||||
sprintf(header=(char*)swzMalloc(strlen(fmt) + i - 1),fmt,k);
|
||||
if (ReadTransitionMatrices(f_in,(char*)NULL,header,model)
|
||||
&& Read_VAR_Parameters(f_in,(char*)NULL,header,model))
|
||||
{
|
||||
|
@ -384,7 +384,7 @@ int GetLastIteration(TStateModel *model, TVARCommandLine *cmd)
|
|||
{
|
||||
k--;
|
||||
for (j=10, i=1; k >= j; j*=10, i++);
|
||||
sprintf(header=(char*)malloc(strlen(fmt) + i - 1),fmt,k);
|
||||
sprintf(header=(char*)swzMalloc(strlen(fmt) + i - 1),fmt,k);
|
||||
if (ReadTransitionMatrices(f_in,(char*)NULL,header,model) && Read_VAR_Parameters(f_in,(char*)NULL,header,model))
|
||||
{
|
||||
if (cmd->parameters_filename_actual) free(cmd->parameters_filename_actual);
|
||||
|
|
|
@ -32,7 +32,7 @@ int main(int nargs, char **args)
|
|||
|
||||
model=Combine_matlab_standard(args[1],args[2]);
|
||||
ReadConstantParameters(args[1],model);
|
||||
sprintf(filename=(char*)malloc(strlen(fmt) + strlen(args[3]) - 1),fmt,args[3]);
|
||||
sprintf(filename=(char*)swzMalloc(strlen(fmt) + strlen(args[3]) - 1),fmt,args[3]);
|
||||
f_out=dw_CreateTextFile(filename);
|
||||
Write_VAR_Specification(f_out,(char*)NULL,model);
|
||||
WriteTransitionMatrices(f_out,(char*)NULL,header,model);
|
||||
|
|
|
@ -66,7 +66,7 @@ void FindMode_VAR_csminwel(TStateModel *model, TEstimateInfo *estimate)
|
|||
size_Q=NumberFreeParametersQ(model);
|
||||
pos_VAR=0;
|
||||
pos_Q=size_VAR;
|
||||
x=(double*)malloc((size_VAR + size_Q)*sizeof(double));
|
||||
x=(double*)swzMalloc((size_VAR + size_Q)*sizeof(double));
|
||||
|
||||
/* //=== Set starting value === ansi-c*/
|
||||
ConvertQToFreeParameters(model,x+pos_Q);
|
||||
|
@ -142,7 +142,7 @@ void FindMode_VAR_csminwel(TStateModel *model, TEstimateInfo *estimate)
|
|||
}
|
||||
|
||||
for (j=10, i=1; total_iteration >= j; j*=10, i++);
|
||||
sprintf(header=(char*)malloc(strlen(fmt) + i - 1),fmt,total_iteration);
|
||||
sprintf(header=(char*)swzMalloc(strlen(fmt) + i - 1),fmt,total_iteration);
|
||||
WriteTransitionMatrices(f_out,(char*)NULL,header,model);
|
||||
Write_VAR_Parameters(f_out,(char*)NULL,header,model);
|
||||
free(header);
|
||||
|
@ -191,7 +191,7 @@ void FindMode_VAR_csminwel(TStateModel *model, TEstimateInfo *estimate)
|
|||
fflush(f_out);
|
||||
|
||||
for (j=10, i=1; total_iteration >= j; j*=10, i++);
|
||||
sprintf(header=(char*)malloc(strlen(fmt) + i - 1),fmt,total_iteration);
|
||||
sprintf(header=(char*)swzMalloc(strlen(fmt) + i - 1),fmt,total_iteration);
|
||||
WriteTransitionMatrices(f_out,(char*)NULL,header,model);
|
||||
Write_VAR_Parameters(f_out,(char*)NULL,header,model);
|
||||
free(header);
|
||||
|
@ -275,7 +275,7 @@ int GetLastIteration(FILE *f_in, TStateModel *model, TEstimateInfo *estimate)
|
|||
while (1)
|
||||
{
|
||||
for (j=10, i=1; k+1 >= j; j*=10, i++);
|
||||
sprintf(id=(char*)malloc(strlen(fmt) + i - 1),fmt,k+1);
|
||||
sprintf(id=(char*)swzMalloc(strlen(fmt) + i - 1),fmt,k+1);
|
||||
|
||||
if (!dw_SetFilePosition(f_in,id))
|
||||
{
|
||||
|
@ -286,7 +286,7 @@ int GetLastIteration(FILE *f_in, TStateModel *model, TEstimateInfo *estimate)
|
|||
while (k > 0)
|
||||
{
|
||||
for (j=10, i=1; k >= j; j*=10, i++);
|
||||
sprintf(header=(char*)malloc(strlen(fmt) + i - 1),fmt,k);
|
||||
sprintf(header=(char*)swzMalloc(strlen(fmt) + i - 1),fmt,k);
|
||||
if (ReadTransitionMatrices(f_in,(char*)NULL,header,model) && Read_VAR_Parameters(f_in,(char*)NULL,header,model))
|
||||
{
|
||||
printf("Using intermediate output - %s\n",header);
|
||||
|
@ -357,7 +357,7 @@ TStateModel* GetModelFromCommandLine(int nargs, char **args, TEstimateInfo *esti
|
|||
d1=dw_ParseString_String(nargs,args,"di","");
|
||||
if (d1[0] && d1[strlen(d1)-1] != '/')
|
||||
{
|
||||
d2=(char*)malloc(strlen(d1)+2);
|
||||
d2=(char*)swzMalloc(strlen(d1)+2);
|
||||
strcat(strcpy(d2,d1),"/");
|
||||
d1=d2;
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ TStateModel* GetModelFromCommandLine(int nargs, char **args, TEstimateInfo *esti
|
|||
if (tag=dw_ParseString_String(nargs,args,"ft",(char*)NULL))
|
||||
{
|
||||
fmt="%sest_final_%s.dat";
|
||||
sprintf(filename=(char*)malloc(strlen(d1) + strlen(fmt) + strlen(tag) - 3),fmt,d1,tag);
|
||||
sprintf(filename=(char*)swzMalloc(strlen(d1) + strlen(fmt) + strlen(tag) - 3),fmt,d1,tag);
|
||||
if (f_in=fopen(filename,"rt"))
|
||||
{
|
||||
model=Read_VAR_Specification(f_in,(char*)NULL);
|
||||
|
@ -385,7 +385,7 @@ TStateModel* GetModelFromCommandLine(int nargs, char **args, TEstimateInfo *esti
|
|||
free(filename);
|
||||
|
||||
fmt="%sinit_%s.dat";
|
||||
sprintf(filename=(char*)malloc(strlen(d1) + strlen(fmt) + strlen(tag) - 3),fmt,d1,tag);
|
||||
sprintf(filename=(char*)swzMalloc(strlen(d1) + strlen(fmt) + strlen(tag) - 3),fmt,d1,tag);
|
||||
if (f_in=fopen(filename,"rt"))
|
||||
{
|
||||
model=Read_VAR_Specification(f_in,(char*)NULL);
|
||||
|
@ -393,7 +393,7 @@ TStateModel* GetModelFromCommandLine(int nargs, char **args, TEstimateInfo *esti
|
|||
fclose(f_in);
|
||||
|
||||
fmt="%sest_intermediate_%s.dat";
|
||||
sprintf(filename=(char*)malloc(strlen(d1) + strlen(fmt) + strlen(tag) - 3),fmt,d1,tag);
|
||||
sprintf(filename=(char*)swzMalloc(strlen(d1) + strlen(fmt) + strlen(tag) - 3),fmt,d1,tag);
|
||||
if (f_in=fopen(filename,"rt"))
|
||||
{
|
||||
if (GetLastIteration(f_in,model,estimate))
|
||||
|
@ -408,7 +408,7 @@ TStateModel* GetModelFromCommandLine(int nargs, char **args, TEstimateInfo *esti
|
|||
free(filename);
|
||||
|
||||
fmt="%sinit_%s.dat";
|
||||
sprintf(filename=(char*)malloc(strlen(d1) + strlen(fmt) + strlen(tag) - 3),fmt,d1,tag);
|
||||
sprintf(filename=(char*)swzMalloc(strlen(d1) + strlen(fmt) + strlen(tag) - 3),fmt,d1,tag);
|
||||
if (f_in=fopen(filename,"rt"))
|
||||
{
|
||||
header=dw_ParseString_String(nargs,args,"rh","Initial: ");
|
||||
|
@ -433,13 +433,13 @@ TStateModel* GetModelFromCommandLine(int nargs, char **args, TEstimateInfo *esti
|
|||
|
||||
if (tag=dw_ParseString_String(nargs,args,"fs",(char*)NULL))
|
||||
{
|
||||
sprintf(filename=(char*)malloc(strlen(d1) + strlen(tag) + 1),"%s%s",d1,tag);
|
||||
sprintf(filename=(char*)swzMalloc(strlen(d1) + strlen(tag) + 1),"%s%s",d1,tag);
|
||||
model=Read_VAR_Specification((FILE*)NULL,filename);
|
||||
estimate->specification_filename=filename;
|
||||
|
||||
if (!(tag=dw_ParseString_String(nargs,args,"fr",(char*)NULL)))
|
||||
tag=dw_ParseString_String(nargs,args,"fs",(char*)NULL);
|
||||
sprintf(filename=(char*)malloc(strlen(d1) + strlen(tag) + 1),"%s%s",d1,tag);
|
||||
sprintf(filename=(char*)swzMalloc(strlen(d1) + strlen(tag) + 1),"%s%s",d1,tag);
|
||||
header=dw_ParseString_String(nargs,args,"rh","");
|
||||
ReadTransitionMatrices((FILE*)NULL,filename,header,model);
|
||||
Read_VAR_Parameters((FILE*)NULL,filename,header,model);
|
||||
|
@ -506,13 +506,13 @@ TEstimateInfo* GetEstimateInfoFromCommandLine(int nargs, char **args) //, TState
|
|||
TEstimateInfo *estimate;
|
||||
char *d1, *d2, *tag, *fmt;
|
||||
|
||||
estimate=(TEstimateInfo*)malloc(sizeof(TEstimateInfo));
|
||||
estimate=(TEstimateInfo*)swzMalloc(sizeof(TEstimateInfo));
|
||||
|
||||
// Output directory
|
||||
d1=dw_ParseString_String(nargs,args,"di","");
|
||||
if (d1[0] && d1[strlen(d1)-1] != '/')
|
||||
{
|
||||
d2=(char*)malloc(strlen(d1)+2);
|
||||
d2=(char*)swzMalloc(strlen(d1)+2);
|
||||
strcat(strcpy(d2,d1),"/");
|
||||
d1=d2;
|
||||
}
|
||||
|
@ -523,13 +523,13 @@ TEstimateInfo* GetEstimateInfoFromCommandLine(int nargs, char **args) //, TState
|
|||
if (!(tag=dw_ParseString_String(nargs,args,"fo",(char*)NULL)))
|
||||
tag=dw_ParseString_String(nargs,args,"ft","default");
|
||||
fmt="%sest_csminwel_%s.dat";
|
||||
sprintf(estimate->csminwel_output_filename=(char*)malloc(strlen(d1) + strlen(fmt) + strlen(tag) - 3),fmt,d1,tag);
|
||||
sprintf(estimate->csminwel_output_filename=(char*)swzMalloc(strlen(d1) + strlen(fmt) + strlen(tag) - 3),fmt,d1,tag);
|
||||
fmt="%sest_intermediate_%s.dat";
|
||||
sprintf(estimate->intermediate_output_filename=(char*)malloc(strlen(d1) + strlen(fmt) + strlen(tag) - 3),fmt,d1,tag);
|
||||
sprintf(estimate->intermediate_output_filename=(char*)swzMalloc(strlen(d1) + strlen(fmt) + strlen(tag) - 3),fmt,d1,tag);
|
||||
fmt="%sest_final_%s.dat";
|
||||
sprintf(estimate->final_output_filename=(char*)malloc(strlen(d1) + strlen(fmt) + strlen(tag) - 3),fmt,d1,tag);
|
||||
sprintf(estimate->final_output_filename=(char*)swzMalloc(strlen(d1) + strlen(fmt) + strlen(tag) - 3),fmt,d1,tag);
|
||||
fmt="%sest_aux_%s.dat";
|
||||
sprintf(estimate->aux_output_filename=(char*)malloc(strlen(d1) + strlen(fmt) + strlen(tag) - 3),fmt,d1,tag);
|
||||
sprintf(estimate->aux_output_filename=(char*)swzMalloc(strlen(d1) + strlen(fmt) + strlen(tag) - 3),fmt,d1,tag);
|
||||
if (d2) free(d2);
|
||||
|
||||
// Posterior mode or MLE
|
||||
|
@ -555,7 +555,7 @@ static TStateModel* SetupFromCommandLine(int nargs, char **args, TEstimateInfo *
|
|||
{
|
||||
TEstimateInfo *info;
|
||||
|
||||
if (!(*p_info)) *p_info=(TEstimateInfo*)malloc(sizeof(TEstimateInfo));
|
||||
if (!(*p_info)) *p_info=(TEstimateInfo*)swzMalloc(sizeof(TEstimateInfo));
|
||||
info=*p_info;
|
||||
|
||||
info->cmd=Base_VARCommandLine(nargs,args,(TVARCommandLine*)NULL);
|
||||
|
|
|
@ -116,7 +116,7 @@ T_MHM* CreateMHM(void)
|
|||
T_MHM* mhm;
|
||||
|
||||
/* // Allocate structure ansi-c*/
|
||||
mhm=(T_MHM*)malloc(sizeof(T_MHM));
|
||||
mhm=(T_MHM*)swzMalloc(sizeof(T_MHM));
|
||||
|
||||
mhm->alpha_scales=(TVector)NULL;
|
||||
|
||||
|
@ -425,7 +425,7 @@ void ComputeModifiedHarmonicMean(T_MHM *mhm, int period)
|
|||
static int ReadError_MHMio(char *id)
|
||||
{
|
||||
char *errmsg, *fmt="Error involving line identifier \"%s\"";
|
||||
sprintf(errmsg=(char*)malloc(strlen(fmt) + strlen(id) - 1),fmt,id);
|
||||
sprintf(errmsg=(char*)swzMalloc(strlen(fmt) + strlen(id) - 1),fmt,id);
|
||||
dw_UserError(errmsg);
|
||||
free(errmsg);
|
||||
return 0;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
static void ReadError_MHMio(char *id)
|
||||
{
|
||||
char *errmsg, *fmt="Error after line identifier ""%s""";
|
||||
sprintf(errmsg=(char*)malloc(strlen(fmt) + strlen(id) - 1),fmt,id);
|
||||
sprintf(errmsg=(char*)swzMalloc(strlen(fmt) + strlen(id) - 1),fmt,id);
|
||||
dw_UserError(errmsg);
|
||||
free(errmsg);
|
||||
}
|
||||
|
@ -34,12 +34,12 @@ static char* AddSlash(char *d)
|
|||
int k=strlen(d);
|
||||
if (d[0] && d[k-1] != '/')
|
||||
{
|
||||
d_out=(char*)malloc(k+2);
|
||||
d_out=(char*)swzMalloc(k+2);
|
||||
strcat(strcpy(d_out,d),"/");
|
||||
}
|
||||
else
|
||||
{
|
||||
d_out=(char*)malloc(k+2);
|
||||
d_out=(char*)swzMalloc(k+2);
|
||||
strcpy(d_out,d);
|
||||
}
|
||||
return d_out;
|
||||
|
@ -246,7 +246,7 @@ T_MHM* CreateMHM_CommandLine(int nargs, char **args)
|
|||
if (filename=dw_ParseString_String(nargs,args,"fi",(char*)NULL))
|
||||
{
|
||||
fmt="%s%s";
|
||||
sprintf(mhm_filename=(char*)malloc(strlen(d_in) + strlen(fmt) + strlen(filename) - 3),fmt,d_in,filename);
|
||||
sprintf(mhm_filename=(char*)swzMalloc(strlen(d_in) + strlen(fmt) + strlen(filename) - 3),fmt,d_in,filename);
|
||||
mhm=ReadMHM_Input((FILE*)NULL,mhm_filename,(T_MHM*)NULL);
|
||||
mhm->mhm_filename=mhm_filename;
|
||||
}
|
||||
|
@ -254,21 +254,21 @@ T_MHM* CreateMHM_CommandLine(int nargs, char **args)
|
|||
if (tag=dw_ParseString_String(nargs,args,"ft",(char*)NULL))
|
||||
{
|
||||
fmt="%smhm_final_%s.dat";
|
||||
sprintf(spec_filename=(char*)malloc(strlen(d_in) + strlen(fmt) + strlen(tag) - 3),fmt,d_in,tag);
|
||||
sprintf(spec_filename=(char*)swzMalloc(strlen(d_in) + strlen(fmt) + strlen(tag) - 3),fmt,d_in,tag);
|
||||
if (rtrn=RestartFromFinalFile(spec_filename,mhm))
|
||||
mhm=rtrn;
|
||||
else
|
||||
{
|
||||
free(spec_filename);
|
||||
fmt="%smhm_intermediate_%s.dat";
|
||||
sprintf(spec_filename=(char*)malloc(strlen(d_in) + strlen(fmt) + strlen(tag) - 3),fmt,d_in,tag);
|
||||
sprintf(spec_filename=(char*)swzMalloc(strlen(d_in) + strlen(fmt) + strlen(tag) - 3),fmt,d_in,tag);
|
||||
if (rtrn=RestartFromIntermediateFile(spec_filename,mhm))
|
||||
mhm=rtrn;
|
||||
else
|
||||
{
|
||||
free(spec_filename);
|
||||
fmt="%sest_final_%s.dat";
|
||||
sprintf(spec_filename=(char*)malloc(strlen(d_in) + strlen(fmt) + strlen(tag) - 3),fmt,d_in,tag);
|
||||
sprintf(spec_filename=(char*)swzMalloc(strlen(d_in) + strlen(fmt) + strlen(tag) - 3),fmt,d_in,tag);
|
||||
if (!(f_in=fopen(spec_filename,"rt")))
|
||||
{
|
||||
swz_fprintf_err("CreateMHM_CommandLine: Unable to create model from %s tag.\n",tag);
|
||||
|
@ -294,11 +294,11 @@ T_MHM* CreateMHM_CommandLine(int nargs, char **args)
|
|||
if (mhm)
|
||||
{
|
||||
fmt="%s%s";
|
||||
sprintf(mhm->spec_filename=(char*)malloc(strlen(d_in) + strlen(fmt) + strlen(filename) - 3),fmt,d_in,filename);
|
||||
sprintf(mhm->spec_filename=(char*)swzMalloc(strlen(d_in) + strlen(fmt) + strlen(filename) - 3),fmt,d_in,filename);
|
||||
model=Read_VAR_Specification((FILE*)NULL,mhm->spec_filename);
|
||||
if (!(filename=dw_ParseString_String(nargs,args,"fp",(char*)NULL)))
|
||||
filename=dw_ParseString_String(nargs,args,"fs",(char*)NULL);
|
||||
sprintf(mhm->parameter_filename=(char*)malloc(strlen(d_in) + strlen(fmt) + strlen(filename) - 3),fmt,d_in,filename);
|
||||
sprintf(mhm->parameter_filename=(char*)swzMalloc(strlen(d_in) + strlen(fmt) + strlen(filename) - 3),fmt,d_in,filename);
|
||||
mhm->parameter_header=dw_ParseString_String(nargs,args,"ph","Posterior mode: ");
|
||||
ReadTransitionMatrices((FILE*)NULL,mhm->parameter_filename,mhm->parameter_header,model);
|
||||
Read_VAR_Parameters((FILE*)NULL,mhm->parameter_filename,mhm->parameter_header,model);
|
||||
|
@ -322,17 +322,17 @@ T_MHM* CreateMHM_CommandLine(int nargs, char **args)
|
|||
if (!(tag=dw_ParseString_String(nargs,args,"fo",(char*)NULL)))
|
||||
tag=dw_ParseString_String(nargs,args,"ft","default");
|
||||
fmt="%smhm_intermediate_%s.dat";
|
||||
sprintf(mhm->intermediate_output_filename=(char*)malloc(strlen(d_out) + strlen(fmt) + strlen(tag) - 3),fmt,d_out,tag);
|
||||
sprintf(mhm->intermediate_output_filename=(char*)swzMalloc(strlen(d_out) + strlen(fmt) + strlen(tag) - 3),fmt,d_out,tag);
|
||||
fmt="%smhm_final_%s.dat";
|
||||
sprintf(mhm->final_output_filename=(char*)malloc(strlen(d_out) + strlen(fmt) + strlen(tag) - 3),fmt,d_out,tag);
|
||||
sprintf(mhm->final_output_filename=(char*)swzMalloc(strlen(d_out) + strlen(fmt) + strlen(tag) - 3),fmt,d_out,tag);
|
||||
fmt="%smhm_intermediate_draws_%s.dat";
|
||||
sprintf(mhm->intermediate_draws_output_filename=(char*)malloc(strlen(d_out) + strlen(fmt) + strlen(tag) - 3),fmt,d_out,tag);
|
||||
sprintf(mhm->intermediate_draws_output_filename=(char*)swzMalloc(strlen(d_out) + strlen(fmt) + strlen(tag) - 3),fmt,d_out,tag);
|
||||
fmt="%smhm_draws_%s.dat";
|
||||
sprintf(mhm->draws_output_filename=(char*)malloc(strlen(d_out) + strlen(fmt) + strlen(tag) - 3),fmt,d_out,tag);
|
||||
sprintf(mhm->draws_output_filename=(char*)swzMalloc(strlen(d_out) + strlen(fmt) + strlen(tag) - 3),fmt,d_out,tag);
|
||||
fmt="%smhm_regime_counts_%s.dat";
|
||||
sprintf(mhm->regime_counts_filename=(char*)malloc(strlen(d_out) + strlen(fmt) + strlen(tag) - 3),fmt,d_out,tag);
|
||||
sprintf(mhm->regime_counts_filename=(char*)swzMalloc(strlen(d_out) + strlen(fmt) + strlen(tag) - 3),fmt,d_out,tag);
|
||||
/* //fmt="%smhm_draws_states_not_integrated_%s.dat"; ansi-c*/
|
||||
/* //sprintf(mhm->states_not_integrated_out_filename=(char*)malloc(strlen(d_out) + strlen(fmt) + strlen(tag) - 3),fmt,d_out,tag); ansi-c*/
|
||||
/* //sprintf(mhm->states_not_integrated_out_filename=(char*)swzMalloc(strlen(d_out) + strlen(fmt) + strlen(tag) - 3),fmt,d_out,tag); ansi-c*/
|
||||
|
||||
free(d_in);
|
||||
free(d_out);
|
||||
|
|
|
@ -1947,9 +1947,9 @@ int main(int nargs, char **args)
|
|||
}
|
||||
|
||||
fmt="mhm_draws_%s.dat";
|
||||
sprintf(mhm_filename=(char*)malloc(strlen(tag)+strlen(fmt)-1),fmt,tag);
|
||||
sprintf(mhm_filename=(char*)swzMalloc(strlen(tag)+strlen(fmt)-1),fmt,tag);
|
||||
fmt="est_final_%s.dat";
|
||||
sprintf(spec_filename=(char*)malloc(strlen(tag)+strlen(fmt)-1),fmt,tag);
|
||||
sprintf(spec_filename=(char*)swzMalloc(strlen(tag)+strlen(fmt)-1),fmt,tag);
|
||||
|
||||
/* // get number of proposal draws - default 100000 ansi-c*/
|
||||
ndraws_proposal=dw_ParseInteger_String(nargs,args,"d",100000);
|
||||
|
|
|
@ -51,19 +51,19 @@ int main(int nargs, char **args)
|
|||
|
||||
/* // specification filename ansi-c*/
|
||||
if (buffer=dw_ParseString_String(nargs,args,"fs",(char*)NULL))
|
||||
strcpy(spec=(char*)malloc(strlen(buffer)+1),buffer);
|
||||
strcpy(spec=(char*)swzMalloc(strlen(buffer)+1),buffer);
|
||||
|
||||
/* // output filename ansi-c*/
|
||||
if (buffer=dw_ParseString_String(nargs,args,"fo",(char*)NULL))
|
||||
strcpy(out=(char*)malloc(strlen(buffer)+1),buffer);
|
||||
strcpy(out=(char*)swzMalloc(strlen(buffer)+1),buffer);
|
||||
|
||||
/* // parameter filename ansi-c*/
|
||||
if (buffer=dw_ParseString_String(nargs,args,"fp",(char*)NULL))
|
||||
strcpy(parm=(char*)malloc(strlen(buffer)+1),buffer);
|
||||
strcpy(parm=(char*)swzMalloc(strlen(buffer)+1),buffer);
|
||||
|
||||
/* // header ansi-c*/
|
||||
if (buffer=dw_ParseString_String(nargs,args,"ph",(char*)NULL))
|
||||
strcpy(head=(char*)malloc(strlen(buffer)+1),buffer);
|
||||
strcpy(head=(char*)swzMalloc(strlen(buffer)+1),buffer);
|
||||
|
||||
/* // file tag ansi-c*/
|
||||
if (buffer=dw_ParseString_String(nargs,args,"ft",(char*)NULL))
|
||||
|
@ -72,17 +72,17 @@ int main(int nargs, char **args)
|
|||
|
||||
/* // specification filename ansi-c*/
|
||||
if (!spec)
|
||||
sprintf(spec=(char*)malloc(strlen(fmt) + strlen(buffer) - 1),fmt,buffer);
|
||||
sprintf(spec=(char*)swzMalloc(strlen(fmt) + strlen(buffer) - 1),fmt,buffer);
|
||||
|
||||
/* // parameter filename ansi-c*/
|
||||
if (!parm)
|
||||
sprintf(parm=(char*)malloc(strlen(fmt) + strlen(buffer) - 1),fmt,buffer);
|
||||
sprintf(parm=(char*)swzMalloc(strlen(fmt) + strlen(buffer) - 1),fmt,buffer);
|
||||
|
||||
/* // output filename ansi-c*/
|
||||
if (!out)
|
||||
{
|
||||
fmt="probabilities_%s.dat";
|
||||
sprintf(out=(char*)malloc(strlen(fmt) + strlen(buffer) - 1),fmt,buffer);
|
||||
sprintf(out=(char*)swzMalloc(strlen(fmt) + strlen(buffer) - 1),fmt,buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,18 +100,18 @@ int main(int nargs, char **args)
|
|||
}
|
||||
|
||||
if (!parm)
|
||||
strcpy(parm=(char*)malloc(strlen(spec)+1),spec);
|
||||
strcpy(parm=(char*)swzMalloc(strlen(spec)+1),spec);
|
||||
|
||||
if (!head)
|
||||
{
|
||||
buffer="Posterior mode: ";
|
||||
strcpy(head=(char*)malloc(strlen(buffer)+1),buffer);
|
||||
strcpy(head=(char*)swzMalloc(strlen(buffer)+1),buffer);
|
||||
}
|
||||
|
||||
if (!out)
|
||||
{
|
||||
buffer="probabilities.dat";
|
||||
strcpy(out=(char*)malloc(strlen(buffer)+1),buffer);
|
||||
strcpy(out=(char*)swzMalloc(strlen(buffer)+1),buffer);
|
||||
}
|
||||
|
||||
model=Read_VAR_Specification((FILE*)NULL,spec);
|
||||
|
|
|
@ -74,7 +74,7 @@ void* dw_CreateArray(TElementSpecification *specs, int dim)
|
|||
if (dim <= 0)
|
||||
dw_Error(ARG_ERR);
|
||||
else
|
||||
if (!(a=malloc(dim*specs->size + specs->offset)))
|
||||
if (!(a=swzMalloc(dim*specs->size + specs->offset)))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
|
@ -349,7 +349,7 @@ void* dw_CopyArray(void* d, void* s)
|
|||
Assumes
|
||||
Both d and s are valid pointers and both *d and *s are either null or a
|
||||
null terminated string. If *d is a null terminated string, then it must
|
||||
have been created via a call to malloc(), calloc() or realloc().
|
||||
have been created via a call to swzMalloc(), calloc() or realloc().
|
||||
|
||||
Returns
|
||||
Returns one upon success and zero upon failure.
|
||||
|
@ -361,7 +361,7 @@ void* dw_CopyArray(void* d, void* s)
|
|||
|
||||
Notes
|
||||
It is critical that this function be called only if the destination string
|
||||
was dynamically created via a call to malloc(), calloc() or realloc(). If
|
||||
was dynamically created via a call to swzMalloc(), calloc() or realloc(). If
|
||||
this is not the case, then servere memory problems can result.
|
||||
*/
|
||||
static int dw_CopyString(void *d, void *s)
|
||||
|
@ -406,7 +406,7 @@ void* dw_CreateMultidimensionalArrayList(TElementSpecification *specs, int depth
|
|||
va_list ap;
|
||||
int i, *dim;
|
||||
void *a=(void*)NULL;
|
||||
if (dim=(int*)malloc(depth*sizeof(int)))
|
||||
if (dim=(int*)swzMalloc(depth*sizeof(int)))
|
||||
{
|
||||
va_start(ap,depth);
|
||||
for (i=0; i < depth; i++) dim[i]=va_arg(ap,int);
|
||||
|
@ -422,7 +422,7 @@ void* dw_CreateMultidimensionalArrayList_string(int depth, ...)
|
|||
va_list ap;
|
||||
int i, *dim;
|
||||
void *a=(void*)NULL;
|
||||
if (dim=(int*)malloc(depth*sizeof(int)))
|
||||
if (dim=(int*)swzMalloc(depth*sizeof(int)))
|
||||
{
|
||||
va_start(ap,depth);
|
||||
for (i=0; i < depth; i++) dim[i]=va_arg(ap,int);
|
||||
|
@ -438,7 +438,7 @@ void* dw_CreateMultidimensionalArrayList_int(int depth, ...)
|
|||
va_list ap;
|
||||
int i, *dim;
|
||||
void *a=(void*)NULL;
|
||||
if (dim=(int*)malloc(depth*sizeof(int)))
|
||||
if (dim=(int*)swzMalloc(depth*sizeof(int)))
|
||||
{
|
||||
va_start(ap,depth);
|
||||
for (i=0; i < depth; i++) dim[i]=va_arg(ap,int);
|
||||
|
@ -454,7 +454,7 @@ void* dw_CreateMultidimensionalArrayList_double(int depth, ...)
|
|||
va_list ap;
|
||||
int i, *dim;
|
||||
void *a=(void*)NULL;
|
||||
if (dim=(int*)malloc(depth*sizeof(int)))
|
||||
if (dim=(int*)swzMalloc(depth*sizeof(int)))
|
||||
{
|
||||
va_start(ap,depth);
|
||||
for (i=0; i < depth; i++) dim[i]=va_arg(ap,int);
|
||||
|
@ -470,7 +470,7 @@ void* dw_CreateMultidimensionalArrayList_float(int depth, ...)
|
|||
va_list ap;
|
||||
int i, *dim;
|
||||
void *a=(void*)NULL;
|
||||
if (dim=(int*)malloc(depth*sizeof(int)))
|
||||
if (dim=(int*)swzMalloc(depth*sizeof(int)))
|
||||
{
|
||||
va_start(ap,depth);
|
||||
for (i=0; i < depth; i++) dim[i]=va_arg(ap,int);
|
||||
|
@ -486,7 +486,7 @@ void* dw_CreateMultidimensionalArrayList_char(int depth, ...)
|
|||
va_list ap;
|
||||
int i, *dim;
|
||||
void *a=(void*)NULL;
|
||||
if (dim=(int*)malloc(depth*sizeof(int)))
|
||||
if (dim=(int*)swzMalloc(depth*sizeof(int)))
|
||||
{
|
||||
va_start(ap,depth);
|
||||
for (i=0; i < depth; i++) dim[i]=va_arg(ap,int);
|
||||
|
@ -553,7 +553,7 @@ int dw_InitializeArray_char(void *a, char x) { return dw_InitializeArray(a,&x);
|
|||
TElementSpecification* CreateArraySpecification_pointer(void (*destructor)(void *))
|
||||
{
|
||||
TElementSpecification *specs;
|
||||
if (specs=(TElementSpecification*)malloc(sizeof(TElementSpecification)))
|
||||
if (specs=(TElementSpecification*)swzMalloc(sizeof(TElementSpecification)))
|
||||
{
|
||||
specs->flag=dw_ARRAY_POINTER | dw_ARRAY_DELETE_SPECS;
|
||||
specs->size=sizeof(void*);
|
||||
|
|
|
@ -120,7 +120,7 @@ TMatrix MatrixTensor(TMatrix X, TMatrix* Y)
|
|||
rtrn=X;
|
||||
if (dw_DimA(Y) > 2)
|
||||
{
|
||||
if (!(Z=(PRECISION*)malloc(r*c*sizeof(PRECISION))))
|
||||
if (!(Z=(PRECISION*)swzMalloc(r*c*sizeof(PRECISION))))
|
||||
{
|
||||
if (!X) FreeMatrix(rtrn);
|
||||
return (TMatrix)NULL;
|
||||
|
@ -211,7 +211,7 @@ TVector VectorTensor(TVector x, TVector* y)
|
|||
rtrn=x;
|
||||
if (dw_DimA(y) > 2)
|
||||
{
|
||||
if (!(z=(PRECISION*)malloc(d*sizeof(PRECISION))))
|
||||
if (!(z=(PRECISION*)swzMalloc(d*sizeof(PRECISION))))
|
||||
{
|
||||
if (!x) FreeVector(rtrn);
|
||||
return (TVector)NULL;
|
||||
|
|
|
@ -74,7 +74,7 @@ FILE *dw_AppendTextFile(char *filename)
|
|||
the buffer containing the file and resets *n if necessary. The if the
|
||||
passed buffer is null or is not large enough to contain the line, buffer is
|
||||
freed and a new buffer is allocated. Because of this, the passed buffer
|
||||
must either null or allocated with malloc(), realloc(), or calloc() and the
|
||||
must either null or allocated with swzMalloc(), realloc(), or calloc() and the
|
||||
calling routine is responsible for eventually freeing the memory if the
|
||||
return value is not null.
|
||||
|
||||
|
@ -86,7 +86,7 @@ char* dw_ReadLine(FILE *f, char *buffer, int *n)
|
|||
{
|
||||
char *ptr, *nbuffer;
|
||||
int i, k=0;
|
||||
if (!buffer && !(buffer=(char*)malloc(*n=SIZE_INCREMENT)))
|
||||
if (!buffer && !(buffer=(char*)swzMalloc(*n=SIZE_INCREMENT)))
|
||||
{
|
||||
*n=0;
|
||||
return (char*)NULL;
|
||||
|
@ -138,7 +138,7 @@ char** dw_ParseDelimitedString(char *buffer, char delimiter, int flag)
|
|||
m=n-1;
|
||||
if ((m >= 0) || !(flag & REMOVE_EMPTY_FIELDS))
|
||||
{
|
||||
ptr=(struct StringList*)malloc(sizeof(struct StringList));
|
||||
ptr=(struct StringList*)swzMalloc(sizeof(struct StringList));
|
||||
ptr->string=buffer;
|
||||
ptr->length=m+1;
|
||||
ptr->next=head;
|
||||
|
@ -149,7 +149,7 @@ char** dw_ParseDelimitedString(char *buffer, char delimiter, int flag)
|
|||
v=dw_CreateArray_string(k);
|
||||
while (--k >= 0)
|
||||
{
|
||||
v[k]=(char*)malloc(head->length+1);
|
||||
v[k]=(char*)swzMalloc(head->length+1);
|
||||
if (head->length > 0) memcpy(v[k],head->string,head->length);
|
||||
v[k][head->length]='\0';
|
||||
ptr=head;
|
||||
|
@ -222,7 +222,7 @@ char*** dw_ReadDelimitedFile(FILE *f, char* filename, char delimiter, int flag)
|
|||
while (buffer=dw_ReadLine(f_in,buffer,&n))
|
||||
if (v=dw_ParseDelimitedString(buffer,delimiter,flag))
|
||||
{
|
||||
ptr=(struct LineList*)malloc(sizeof(struct LineList));
|
||||
ptr=(struct LineList*)swzMalloc(sizeof(struct LineList));
|
||||
ptr->line=v;
|
||||
ptr->next=head;
|
||||
head=ptr;
|
||||
|
@ -443,6 +443,6 @@ int dw_SetFilePositionBySection(FILE *f, int n, ...)
|
|||
char* dw_DuplicateString(char *buffer)
|
||||
{
|
||||
char *rtrn=(char*)NULL;
|
||||
if (buffer && (rtrn=(char*)malloc(strlen(buffer)+1))) strcpy(rtrn,buffer);
|
||||
if (buffer && (rtrn=(char*)swzMalloc(strlen(buffer)+1))) strcpy(rtrn,buffer);
|
||||
return rtrn;
|
||||
}
|
||||
|
|
|
@ -526,7 +526,7 @@ int bLU(int *p, PRECISION *x, int m, int n, int xt)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (!( y=(PRECISION*)malloc(m*n*sizeof(PRECISION)))) return MEM_ERR;
|
||||
if (!( y=(PRECISION*)swzMalloc(m*n*sizeof(PRECISION)))) return MEM_ERR;
|
||||
bTranspose(y,x,m,n,0);
|
||||
|
||||
getrf(&m2,&n2,y,&m2,p2,&info);
|
||||
|
@ -960,7 +960,7 @@ int bSVD_new(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int
|
|||
|
||||
lapack_int k, m2, n2, qv2, info;
|
||||
|
||||
if (!(A_=(PRECISION*)malloc(m*n*sizeof(PRECISION)))) return MEM_ERR;
|
||||
if (!(A_=(PRECISION*)swzMalloc(m*n*sizeof(PRECISION)))) return MEM_ERR;
|
||||
if (at)
|
||||
memcpy(A_,A,m*n*sizeof(PRECISION));
|
||||
else
|
||||
|
@ -987,7 +987,7 @@ int bSVD_new(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int
|
|||
if (ut)
|
||||
U_=U;
|
||||
else
|
||||
if (!(U_=(PRECISION*)malloc(m*qu*sizeof(PRECISION))))
|
||||
if (!(U_=(PRECISION*)swzMalloc(m*qu*sizeof(PRECISION))))
|
||||
{
|
||||
free(A_);
|
||||
return MEM_ERR;
|
||||
|
@ -1015,7 +1015,7 @@ int bSVD_new(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int
|
|||
if (!vt)
|
||||
V_=V;
|
||||
else
|
||||
if (!(V_=(PRECISION*)malloc(n*qv*sizeof(PRECISION))))
|
||||
if (!(V_=(PRECISION*)swzMalloc(n*qv*sizeof(PRECISION))))
|
||||
{
|
||||
free(A_);
|
||||
if (U_ && (U_ != U)) free(U_);
|
||||
|
@ -1032,7 +1032,7 @@ int bSVD_new(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int
|
|||
if (info)
|
||||
err=BLAS_LAPACK_ERR;
|
||||
else
|
||||
if (!(work=(PRECISION*)malloc((k=(int)opt_size)*sizeof(PRECISION))))
|
||||
if (!(work=(PRECISION*)swzMalloc((k=(int)opt_size)*sizeof(PRECISION))))
|
||||
err=MEM_ERR;
|
||||
else
|
||||
{
|
||||
|
@ -1058,7 +1058,7 @@ int bSVD_new(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int
|
|||
/* int k=-1, info, err, m_, n_, qu_, qv_, transpose; */
|
||||
/* PRECISION *A_, *U_, *V_, *work, opt_size; */
|
||||
|
||||
/* A_=(PRECISION*)malloc(m*n*sizeof(PRECISION)); */
|
||||
/* A_=(PRECISION*)swzMalloc(m*n*sizeof(PRECISION)); */
|
||||
|
||||
/* jobu=jobv=compact ? 'S' : 'A'; */
|
||||
|
||||
|
@ -1108,8 +1108,8 @@ int bSVD_new(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int
|
|||
/* qu_=m_=n; */
|
||||
/* qv_=n_=m; */
|
||||
/* } */
|
||||
/* U_=vt ? V : (PRECISION*)malloc(m_*qu_*sizeof(PRECISION)); */
|
||||
/* V_=ut ? (PRECISION*)malloc(qv_*n_*sizeof(PRECISION)) : U; */
|
||||
/* U_=vt ? V : (PRECISION*)swzMalloc(m_*qu_*sizeof(PRECISION)); */
|
||||
/* V_=ut ? (PRECISION*)swzMalloc(qv_*n_*sizeof(PRECISION)) : U; */
|
||||
/* } */
|
||||
/* else */
|
||||
/* { */
|
||||
|
@ -1128,13 +1128,13 @@ int bSVD_new(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int
|
|||
/* qu_=m_=m; */
|
||||
/* qv_=n_=n; */
|
||||
/* } */
|
||||
/* U_=ut ? U : (PRECISION*)malloc(m_*qu_*sizeof(PRECISION)); */
|
||||
/* V_=vt ? (PRECISION*)malloc(qv_*n_*sizeof(PRECISION)) : V; */
|
||||
/* U_=ut ? U : (PRECISION*)swzMalloc(m_*qu_*sizeof(PRECISION)); */
|
||||
/* V_=vt ? (PRECISION*)swzMalloc(qv_*n_*sizeof(PRECISION)) : V; */
|
||||
/* } */
|
||||
|
||||
/* // compute singular value decomposition */
|
||||
/* gesvd(&jobu,&jobv,&m_,&n_,A_,&m_,d,U_,&m_,V_,&qv_,&opt_size,&k,&info); */
|
||||
/* if (info || !(work=(PRECISION*)malloc((k=(int)opt_size)*sizeof(PRECISION)))) */
|
||||
/* if (info || !(work=(PRECISION*)swzMalloc((k=(int)opt_size)*sizeof(PRECISION)))) */
|
||||
/* err=info ? BLAS_LAPACK_ERR : MEM_ERR; */
|
||||
/* else */
|
||||
/* { */
|
||||
|
@ -1266,9 +1266,9 @@ int bSVD(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int n, i
|
|||
|
||||
lapack_int m2, n2, k, info;
|
||||
|
||||
if (!(X=(PRECISION*)malloc(m*n*sizeof(PRECISION)))) return MEM_ERR;
|
||||
if (!(X=(PRECISION*)swzMalloc(m*n*sizeof(PRECISION)))) return MEM_ERR;
|
||||
memcpy(X,A,m*n*sizeof(PRECISION));
|
||||
if (!(iwork=(int*)malloc(8*((m < n) ? m : n)*sizeof(int))))
|
||||
if (!(iwork=(int*)swzMalloc(8*((m < n) ? m : n)*sizeof(int))))
|
||||
{
|
||||
free(X);
|
||||
return MEM_ERR;
|
||||
|
@ -1281,7 +1281,7 @@ int bSVD(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int n, i
|
|||
memcpy(X,A,m*n*sizeof(PRECISION));
|
||||
k=-1;
|
||||
gesvd(&jobz,&jobz,&m2,&n2,X,&m2,d,U,&m2,V,&n2,&opt_size,&k,&info);
|
||||
if (info || !(work=(PRECISION*)malloc((k=(int)opt_size)*sizeof(PRECISION))))
|
||||
if (info || !(work=(PRECISION*)swzMalloc((k=(int)opt_size)*sizeof(PRECISION))))
|
||||
{
|
||||
free(iwork);
|
||||
free(X);
|
||||
|
@ -1305,7 +1305,7 @@ int bSVD(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int n, i
|
|||
memcpy(X,A,m*n*sizeof(PRECISION));
|
||||
k=-1;
|
||||
gesvd(&jobz,&jobz,&n2,&m2,X,&n2,d,V,&n2,U,&m2,&opt_size,&k,&info);
|
||||
if (info || !(work=(PRECISION*)malloc((k=(int)opt_size)*sizeof(PRECISION))))
|
||||
if (info || !(work=(PRECISION*)swzMalloc((k=(int)opt_size)*sizeof(PRECISION))))
|
||||
{
|
||||
free(iwork);
|
||||
free(X);
|
||||
|
@ -1339,9 +1339,9 @@ int bSVD(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int n, i
|
|||
/* #endif */
|
||||
/* int jobz='A', k, *iwork, info; */
|
||||
/* PRECISION *X, *work, opt_size; */
|
||||
/* if (!(X=(PRECISION*)malloc(m*n*sizeof(PRECISION)))) return MEM_ERR; */
|
||||
/* if (!(X=(PRECISION*)swzMalloc(m*n*sizeof(PRECISION)))) return MEM_ERR; */
|
||||
/* memcpy(X,A,m*n*sizeof(PRECISION)); */
|
||||
/* if (!(iwork=(int*)malloc(8*((m < n) ? m : n)*sizeof(int)))) */
|
||||
/* if (!(iwork=(int*)swzMalloc(8*((m < n) ? m : n)*sizeof(int)))) */
|
||||
/* { */
|
||||
/* free(X); */
|
||||
/* return MEM_ERR; */
|
||||
|
@ -1350,7 +1350,7 @@ int bSVD(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int n, i
|
|||
/* if (at) */
|
||||
/* { */
|
||||
/* gesdd(&jobz,&m,&n,X,&m,d,U,&m,V,&n,&opt_size,&k,iwork,&info); */
|
||||
/* if (info || !(work=(PRECISION*)malloc((k=(int)opt_size)*sizeof(PRECISION)))) */
|
||||
/* if (info || !(work=(PRECISION*)swzMalloc((k=(int)opt_size)*sizeof(PRECISION)))) */
|
||||
/* { */
|
||||
/* free(iwork); */
|
||||
/* free(X); */
|
||||
|
@ -1372,7 +1372,7 @@ int bSVD(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int n, i
|
|||
/* else */
|
||||
/* { */
|
||||
/* gesdd(&jobz,&n,&m,X,&n,d,V,&n,U,&m,&opt_size,&k,iwork,&info); */
|
||||
/* if (!(work=(PRECISION*)malloc((k=(int)opt_size)*sizeof(PRECISION)))) */
|
||||
/* if (!(work=(PRECISION*)swzMalloc((k=(int)opt_size)*sizeof(PRECISION)))) */
|
||||
/* { */
|
||||
/* free(iwork); */
|
||||
/* free(X); */
|
||||
|
@ -1483,7 +1483,7 @@ int bQR(PRECISION *Q, PRECISION *R, PRECISION *X, int m, int n, int q, int qt, i
|
|||
|
||||
lapack_int m2, n2, p2, q2, lwork, info;
|
||||
|
||||
if (!(tau=(PRECISION*)malloc(p*sizeof(PRECISION)))) return MEM_ERR;
|
||||
if (!(tau=(PRECISION*)swzMalloc(p*sizeof(PRECISION)))) return MEM_ERR;
|
||||
if (xt)
|
||||
{
|
||||
lwork=-1;
|
||||
|
@ -1491,7 +1491,7 @@ int bQR(PRECISION *Q, PRECISION *R, PRECISION *X, int m, int n, int q, int qt, i
|
|||
n2 = n;
|
||||
geqrf(&m2,&n2,X,&m2,tau,&opt_size,&lwork,&info);
|
||||
|
||||
if (!(work=(PRECISION*)malloc((lwork=(int)opt_size)*sizeof(PRECISION))))
|
||||
if (!(work=(PRECISION*)swzMalloc((lwork=(int)opt_size)*sizeof(PRECISION))))
|
||||
{
|
||||
free(tau);
|
||||
return MEM_ERR;
|
||||
|
@ -1510,7 +1510,7 @@ int bQR(PRECISION *Q, PRECISION *R, PRECISION *X, int m, int n, int q, int qt, i
|
|||
if (qt)
|
||||
ptr=Q;
|
||||
else
|
||||
if (!(ptr=(PRECISION*)malloc(m*q*sizeof(PRECISION))))
|
||||
if (!(ptr=(PRECISION*)swzMalloc(m*q*sizeof(PRECISION))))
|
||||
{
|
||||
free(tau);
|
||||
return MEM_ERR;
|
||||
|
@ -1522,7 +1522,7 @@ int bQR(PRECISION *Q, PRECISION *R, PRECISION *X, int m, int n, int q, int qt, i
|
|||
q2 = q;
|
||||
orgqr(&m2,&q2,&p2,ptr,&m2,tau,&opt_size,&lwork,&info);
|
||||
|
||||
if (!(work=(PRECISION*)malloc((lwork=(int)opt_size)*sizeof(PRECISION))))
|
||||
if (!(work=(PRECISION*)swzMalloc((lwork=(int)opt_size)*sizeof(PRECISION))))
|
||||
{
|
||||
if (!qt) free(ptr);
|
||||
free(tau);
|
||||
|
@ -1568,7 +1568,7 @@ int bQR(PRECISION *Q, PRECISION *R, PRECISION *X, int m, int n, int q, int qt, i
|
|||
n2 = n;
|
||||
gelqf(&n2,&m2,X,&n2,tau,&opt_size,&lwork,&info);
|
||||
|
||||
if (!(work=(PRECISION*)malloc((lwork=(int)opt_size)*sizeof(PRECISION))))
|
||||
if (!(work=(PRECISION*)swzMalloc((lwork=(int)opt_size)*sizeof(PRECISION))))
|
||||
{
|
||||
free(tau);
|
||||
return MEM_ERR;
|
||||
|
@ -1587,7 +1587,7 @@ int bQR(PRECISION *Q, PRECISION *R, PRECISION *X, int m, int n, int q, int qt, i
|
|||
if (!qt)
|
||||
ptr=Q;
|
||||
else
|
||||
if (!(ptr=(PRECISION*)malloc(m*q*sizeof(PRECISION))))
|
||||
if (!(ptr=(PRECISION*)swzMalloc(m*q*sizeof(PRECISION))))
|
||||
{
|
||||
free(tau);
|
||||
return MEM_ERR;
|
||||
|
@ -1610,7 +1610,7 @@ int bQR(PRECISION *Q, PRECISION *R, PRECISION *X, int m, int n, int q, int qt, i
|
|||
q2 = q;
|
||||
orglq(&q2,&m2,&p2,ptr,&q2,tau,&opt_size,&lwork,&info);
|
||||
|
||||
if (!(work=(PRECISION*)malloc((lwork=(int)opt_size)*sizeof(PRECISION))))
|
||||
if (!(work=(PRECISION*)swzMalloc((lwork=(int)opt_size)*sizeof(PRECISION))))
|
||||
{
|
||||
if (!qt) free(ptr);
|
||||
free(tau);
|
||||
|
@ -1718,9 +1718,9 @@ int bQZ_real(PRECISION *Q, PRECISION *Z, PRECISION *S, PRECISION *T, PRECISION *
|
|||
|
||||
jobvsl=Q ? 'V' : 'N';
|
||||
jobvsr=Z ? 'V' : 'N';
|
||||
palpha_r=alpha_r ? alpha_r : (PRECISION*)malloc(n*sizeof(PRECISION));
|
||||
palpha_i=alpha_i ? alpha_i : (PRECISION*)malloc(n*sizeof(PRECISION));
|
||||
pbeta=beta ? beta : (PRECISION*)malloc(n*sizeof(PRECISION));
|
||||
palpha_r=alpha_r ? alpha_r : (PRECISION*)swzMalloc(n*sizeof(PRECISION));
|
||||
palpha_i=alpha_i ? alpha_i : (PRECISION*)swzMalloc(n*sizeof(PRECISION));
|
||||
pbeta=beta ? beta : (PRECISION*)swzMalloc(n*sizeof(PRECISION));
|
||||
|
||||
if (palpha_r && palpha_i && pbeta)
|
||||
{
|
||||
|
@ -1744,7 +1744,7 @@ int bQZ_real(PRECISION *Q, PRECISION *Z, PRECISION *S, PRECISION *T, PRECISION *
|
|||
n2 = n;
|
||||
gges(&jobvsl,&jobvsr,&sort,(void*)NULL,&n2,S,&n2,T,&n2,&simd,palpha_r,palpha_i,pbeta,Q,&n2,Z,&n2,&size,&lwork,(void*)NULL,&info);
|
||||
if (!info)
|
||||
if (!(work=malloc((lwork=(int)size)*sizeof(PRECISION))))
|
||||
if (!(work=swzMalloc((lwork=(int)size)*sizeof(PRECISION))))
|
||||
rtrn=MEM_ERR;
|
||||
else
|
||||
{
|
||||
|
@ -1848,9 +1848,9 @@ int bReorderQZ_real(int *select, PRECISION *QQ, PRECISION *ZZ, PRECISION *SS, PR
|
|||
wantq=(QQ && Q) ? 1 : 0;
|
||||
wantz=(ZZ && Z) ? 1 : 0;
|
||||
|
||||
palpha_r=alpha_r ? alpha_r : (PRECISION*)malloc(n*sizeof(PRECISION));
|
||||
palpha_i=alpha_i ? alpha_i : (PRECISION*)malloc(n*sizeof(PRECISION));
|
||||
pbeta=beta ? beta : (PRECISION*)malloc(n*sizeof(PRECISION));
|
||||
palpha_r=alpha_r ? alpha_r : (PRECISION*)swzMalloc(n*sizeof(PRECISION));
|
||||
palpha_i=alpha_i ? alpha_i : (PRECISION*)swzMalloc(n*sizeof(PRECISION));
|
||||
pbeta=beta ? beta : (PRECISION*)swzMalloc(n*sizeof(PRECISION));
|
||||
|
||||
if (palpha_r && palpha_i && pbeta)
|
||||
{
|
||||
|
@ -1897,7 +1897,7 @@ int bReorderQZ_real(int *select, PRECISION *QQ, PRECISION *ZZ, PRECISION *SS, PR
|
|||
(PRECISION*)NULL,(PRECISION*)NULL,(PRECISION*)NULL,&size,&lwork,&iwork,&liwork,&info);
|
||||
m = m2;
|
||||
if (!info)
|
||||
if (!(work=malloc((lwork=(int)size)*sizeof(PRECISION))))
|
||||
if (!(work=swzMalloc((lwork=(int)size)*sizeof(PRECISION))))
|
||||
rtrn=MEM_ERR;
|
||||
else
|
||||
{
|
||||
|
@ -1998,8 +1998,8 @@ int bSortQZ_real(int *select, PRECISION *QQ, PRECISION *ZZ, PRECISION *SS, PRECI
|
|||
wantq=(QQ && Q) ? 1 : 0;
|
||||
wantz=(ZZ && Z) ? 1 : 0;
|
||||
|
||||
pairs=(int*)malloc(n*sizeof(int));
|
||||
gev=(PRECISION*)malloc(n*sizeof(PRECISION));
|
||||
pairs=(int*)swzMalloc(n*sizeof(int));
|
||||
gev=(PRECISION*)swzMalloc(n*sizeof(PRECISION));
|
||||
small=SQRT_MACHINE_EPSILON;
|
||||
|
||||
if (pairs && gev)
|
||||
|
@ -2049,7 +2049,7 @@ int bSortQZ_real(int *select, PRECISION *QQ, PRECISION *ZZ, PRECISION *SS, PRECI
|
|||
i = i2;
|
||||
j = j2;
|
||||
if (!info)
|
||||
if (!(work=malloc((lwork=(int)size)*sizeof(PRECISION))))
|
||||
if (!(work=swzMalloc((lwork=(int)size)*sizeof(PRECISION))))
|
||||
rtrn=MEM_ERR;
|
||||
else
|
||||
{
|
||||
|
|
|
@ -805,7 +805,7 @@ int bLU(int *p, PRECISION *x, int m, int n, int xt)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (!( y=(PRECISION*)malloc(m*n*sizeof(PRECISION)))) return MEM_ERR;
|
||||
if (!( y=(PRECISION*)swzMalloc(m*n*sizeof(PRECISION)))) return MEM_ERR;
|
||||
bTranspose(y,x,m,n,0);
|
||||
|
||||
#if PRECISION_SIZE == 4
|
||||
|
@ -1529,7 +1529,7 @@ static int bSVD_NumericalRecipes(PRECISION *U, PRECISION *d, PRECISION *V, int m
|
|||
int flag, i, its, j, jj, k, l, nm;
|
||||
PRECISION anorm, c, f, g, h, s, scale, x, y, z, *rv1, tmp;
|
||||
|
||||
rv1=(PRECISION*)malloc(n*sizeof(PRECISION));
|
||||
rv1=(PRECISION*)swzMalloc(n*sizeof(PRECISION));
|
||||
if (!rv1) return MEM_ERR;
|
||||
g=scale=anorm=0.0;
|
||||
|
||||
|
@ -1829,7 +1829,7 @@ int bSVD_new(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int
|
|||
int jobu, jobv, jobt, k=-1, info, err, m_, n_, qu_, qv_, transpose;
|
||||
PRECISION *A_, *U_, *V_, *work, opt_size;
|
||||
|
||||
A_=(PRECISION*)malloc(m*n*sizeof(PRECISION));
|
||||
A_=(PRECISION*)swzMalloc(m*n*sizeof(PRECISION));
|
||||
|
||||
jobu=jobv=compact ? 'S' : 'A';
|
||||
|
||||
|
@ -1879,8 +1879,8 @@ int bSVD_new(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int
|
|||
qu_=m_=n;
|
||||
qv_=n_=m;
|
||||
}
|
||||
U_=vt ? V : (PRECISION*)malloc(m_*qu_*sizeof(PRECISION));
|
||||
V_=ut ? (PRECISION*)malloc(qv_*n_*sizeof(PRECISION)) : U;
|
||||
U_=vt ? V : (PRECISION*)swzMalloc(m_*qu_*sizeof(PRECISION));
|
||||
V_=ut ? (PRECISION*)swzMalloc(qv_*n_*sizeof(PRECISION)) : U;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1899,13 +1899,13 @@ int bSVD_new(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int
|
|||
qu_=m_=m;
|
||||
qv_=n_=n;
|
||||
}
|
||||
U_=ut ? U : (PRECISION*)malloc(m_*qu_*sizeof(PRECISION));
|
||||
V_=vt ? (PRECISION*)malloc(qv_*n_*sizeof(PRECISION)) : V;
|
||||
U_=ut ? U : (PRECISION*)swzMalloc(m_*qu_*sizeof(PRECISION));
|
||||
V_=vt ? (PRECISION*)swzMalloc(qv_*n_*sizeof(PRECISION)) : V;
|
||||
}
|
||||
|
||||
/* // compute singular value decomposition ansi-c*/
|
||||
gesvd(&jobu,&jobv,&m_,&n_,A_,&m_,d,U_,&m_,V_,&qv_,&opt_size,&k,&info);
|
||||
if (info || !(work=(PRECISION*)malloc((k=(int)opt_size)*sizeof(PRECISION))))
|
||||
if (info || !(work=(PRECISION*)swzMalloc((k=(int)opt_size)*sizeof(PRECISION))))
|
||||
err=info ? BLAS_LAPACK_ERR : MEM_ERR;
|
||||
else
|
||||
{
|
||||
|
@ -1977,7 +1977,7 @@ int bSVD_new(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int
|
|||
}
|
||||
else
|
||||
if (m < n)
|
||||
if (!(NU=(PRECISION*)malloc(m*n*sizeof(PRECISION))))
|
||||
if (!(NU=(PRECISION*)swzMalloc(m*n*sizeof(PRECISION))))
|
||||
rtrn=MEM_ERR;
|
||||
else
|
||||
{
|
||||
|
@ -1991,7 +1991,7 @@ int bSVD_new(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int
|
|||
if (NU[i*m+i] < 0)
|
||||
for (j=(n-1)*n+i; j >= 0; j-=n) V[j]=-V[j];
|
||||
rtrn=NO_ERR;
|
||||
/* if (!(nd=(PRECISION*)malloc(n*sizeof(PRECISION)))) */
|
||||
/* if (!(nd=(PRECISION*)swzMalloc(n*sizeof(PRECISION)))) */
|
||||
/* rtrn=MEM_ERR; */
|
||||
/* else */
|
||||
/* { */
|
||||
|
@ -2008,7 +2008,7 @@ int bSVD_new(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int
|
|||
free(NU);
|
||||
}
|
||||
else
|
||||
if (!(NU=(PRECISION*)malloc(m*n*sizeof(PRECISION))))
|
||||
if (!(NU=(PRECISION*)swzMalloc(m*n*sizeof(PRECISION))))
|
||||
rtrn=MEM_ERR;
|
||||
else
|
||||
{
|
||||
|
@ -2105,9 +2105,9 @@ int bSVD(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int n, i
|
|||
#endif
|
||||
int jobz='A', k, *iwork, info;
|
||||
PRECISION *X, *work, opt_size;
|
||||
if (!(X=(PRECISION*)malloc(m*n*sizeof(PRECISION)))) return MEM_ERR;
|
||||
if (!(X=(PRECISION*)swzMalloc(m*n*sizeof(PRECISION)))) return MEM_ERR;
|
||||
memcpy(X,A,m*n*sizeof(PRECISION));
|
||||
if (!(iwork=(int*)malloc(8*((m < n) ? m : n)*sizeof(int))))
|
||||
if (!(iwork=(int*)swzMalloc(8*((m < n) ? m : n)*sizeof(int))))
|
||||
{
|
||||
free(X);
|
||||
return MEM_ERR;
|
||||
|
@ -2116,7 +2116,7 @@ int bSVD(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int n, i
|
|||
if (at)
|
||||
{
|
||||
/* gesdd(&jobz,&m,&n,X,&m,d,U,&m,V,&n,&opt_size,&k,iwork,&info); */
|
||||
/* if (info || !(work=(PRECISION*)malloc((k=(int)opt_size)*sizeof(PRECISION)))) */
|
||||
/* if (info || !(work=(PRECISION*)swzMalloc((k=(int)opt_size)*sizeof(PRECISION)))) */
|
||||
/* { */
|
||||
/* free(iwork); */
|
||||
/* free(X); */
|
||||
|
@ -2129,7 +2129,7 @@ int bSVD(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int n, i
|
|||
memcpy(X,A,m*n*sizeof(PRECISION));
|
||||
k=-1;
|
||||
gesvd(&jobz,&jobz,&m,&n,X,&m,d,U,&m,V,&n,&opt_size,&k,&info);
|
||||
if (info || !(work=(PRECISION*)malloc((k=(int)opt_size)*sizeof(PRECISION))))
|
||||
if (info || !(work=(PRECISION*)swzMalloc((k=(int)opt_size)*sizeof(PRECISION))))
|
||||
{
|
||||
free(iwork);
|
||||
free(X);
|
||||
|
@ -2151,7 +2151,7 @@ int bSVD(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int n, i
|
|||
else
|
||||
{
|
||||
/* gesdd(&jobz,&n,&m,X,&n,d,V,&n,U,&m,&opt_size,&k,iwork,&info); */
|
||||
/* if (!(work=(PRECISION*)malloc((k=(int)opt_size)*sizeof(PRECISION)))) */
|
||||
/* if (!(work=(PRECISION*)swzMalloc((k=(int)opt_size)*sizeof(PRECISION)))) */
|
||||
/* { */
|
||||
/* free(iwork); */
|
||||
/* free(X); */
|
||||
|
@ -2164,7 +2164,7 @@ int bSVD(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int n, i
|
|||
memcpy(X,A,m*n*sizeof(PRECISION));
|
||||
k=-1;
|
||||
gesvd(&jobz,&jobz,&n,&m,X,&n,d,V,&n,U,&m,&opt_size,&k,&info);
|
||||
if (info || !(work=(PRECISION*)malloc((k=(int)opt_size)*sizeof(PRECISION))))
|
||||
if (info || !(work=(PRECISION*)swzMalloc((k=(int)opt_size)*sizeof(PRECISION))))
|
||||
{
|
||||
free(iwork);
|
||||
free(X);
|
||||
|
@ -2210,7 +2210,7 @@ int bSVD(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int n, i
|
|||
}
|
||||
else
|
||||
if (m < n)
|
||||
if (!(NU=(PRECISION*)malloc(m*n*sizeof(PRECISION))))
|
||||
if (!(NU=(PRECISION*)swzMalloc(m*n*sizeof(PRECISION))))
|
||||
rtrn=MEM_ERR;
|
||||
else
|
||||
{
|
||||
|
@ -2224,7 +2224,7 @@ int bSVD(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int n, i
|
|||
if (NU[i*m+i] < 0)
|
||||
for (j=(n-1)*n+i; j >= 0; j-=n) V[j]=-V[j];
|
||||
rtrn=NO_ERR;
|
||||
/* if (!(nd=(PRECISION*)malloc(n*sizeof(PRECISION)))) */
|
||||
/* if (!(nd=(PRECISION*)swzMalloc(n*sizeof(PRECISION)))) */
|
||||
/* rtrn=MEM_ERR; */
|
||||
/* else */
|
||||
/* { */
|
||||
|
@ -2241,7 +2241,7 @@ int bSVD(PRECISION *U, PRECISION *d, PRECISION *V, PRECISION *A, int m, int n, i
|
|||
free(NU);
|
||||
}
|
||||
else
|
||||
if (!(NU=(PRECISION*)malloc(m*n*sizeof(PRECISION))))
|
||||
if (!(NU=(PRECISION*)swzMalloc(m*n*sizeof(PRECISION))))
|
||||
rtrn=MEM_ERR;
|
||||
else
|
||||
{
|
||||
|
@ -2304,7 +2304,7 @@ static int bQR_NumericalRecipes(PRECISION *Q, PRECISION *R, int m, int n)
|
|||
|
||||
if (Q)
|
||||
{
|
||||
if (!(diag=(PRECISION*)malloc(2*s*sizeof(PRECISION)))) return MEM_ERR;
|
||||
if (!(diag=(PRECISION*)swzMalloc(2*s*sizeof(PRECISION)))) return MEM_ERR;
|
||||
norm=diag+s;
|
||||
|
||||
for (k=0; k < s; k++)
|
||||
|
@ -2482,7 +2482,7 @@ int bQR(PRECISION *Q, PRECISION *R, PRECISION *X, int m, int n, int q, int qt, i
|
|||
#if defined USE_BLAS_LAPACK
|
||||
int i, j, k, l, lwork, info, p=(m < n) ? m : n;
|
||||
PRECISION *tau, *work, *ptr, opt_size;
|
||||
if (!(tau=(PRECISION*)malloc(p*sizeof(PRECISION)))) return MEM_ERR;
|
||||
if (!(tau=(PRECISION*)swzMalloc(p*sizeof(PRECISION)))) return MEM_ERR;
|
||||
if (xt)
|
||||
{
|
||||
lwork=-1;
|
||||
|
@ -2491,7 +2491,7 @@ int bQR(PRECISION *Q, PRECISION *R, PRECISION *X, int m, int n, int q, int qt, i
|
|||
#else
|
||||
dgeqrf(&m,&n,X,&m,tau,&opt_size,&lwork,&info);
|
||||
#endif
|
||||
if (!(work=(PRECISION*)malloc((lwork=(int)opt_size)*sizeof(PRECISION))))
|
||||
if (!(work=(PRECISION*)swzMalloc((lwork=(int)opt_size)*sizeof(PRECISION))))
|
||||
{
|
||||
free(tau);
|
||||
return MEM_ERR;
|
||||
|
@ -2512,7 +2512,7 @@ int bQR(PRECISION *Q, PRECISION *R, PRECISION *X, int m, int n, int q, int qt, i
|
|||
if (qt)
|
||||
ptr=Q;
|
||||
else
|
||||
if (!(ptr=(PRECISION*)malloc(m*q*sizeof(PRECISION))))
|
||||
if (!(ptr=(PRECISION*)swzMalloc(m*q*sizeof(PRECISION))))
|
||||
{
|
||||
free(tau);
|
||||
return MEM_ERR;
|
||||
|
@ -2524,7 +2524,7 @@ int bQR(PRECISION *Q, PRECISION *R, PRECISION *X, int m, int n, int q, int qt, i
|
|||
#else
|
||||
dorgqr(&m,&q,&p,ptr,&m,tau,&opt_size,&lwork,&info);
|
||||
#endif
|
||||
if (!(work=(PRECISION*)malloc((lwork=(int)opt_size)*sizeof(PRECISION))))
|
||||
if (!(work=(PRECISION*)swzMalloc((lwork=(int)opt_size)*sizeof(PRECISION))))
|
||||
{
|
||||
if (!qt) free(ptr);
|
||||
free(tau);
|
||||
|
@ -2573,7 +2573,7 @@ int bQR(PRECISION *Q, PRECISION *R, PRECISION *X, int m, int n, int q, int qt, i
|
|||
#else
|
||||
dgelqf(&n,&m,X,&n,tau,&opt_size,&lwork,&info);
|
||||
#endif
|
||||
if (!(work=(PRECISION*)malloc((lwork=(int)opt_size)*sizeof(PRECISION))))
|
||||
if (!(work=(PRECISION*)swzMalloc((lwork=(int)opt_size)*sizeof(PRECISION))))
|
||||
{
|
||||
free(tau);
|
||||
return MEM_ERR;
|
||||
|
@ -2594,7 +2594,7 @@ int bQR(PRECISION *Q, PRECISION *R, PRECISION *X, int m, int n, int q, int qt, i
|
|||
if (!qt)
|
||||
ptr=Q;
|
||||
else
|
||||
if (!(ptr=(PRECISION*)malloc(m*q*sizeof(PRECISION))))
|
||||
if (!(ptr=(PRECISION*)swzMalloc(m*q*sizeof(PRECISION))))
|
||||
{
|
||||
free(tau);
|
||||
return MEM_ERR;
|
||||
|
@ -2616,7 +2616,7 @@ int bQR(PRECISION *Q, PRECISION *R, PRECISION *X, int m, int n, int q, int qt, i
|
|||
#else
|
||||
dorglq(&q,&m,&p,ptr,&q,tau,&opt_size,&lwork,&info);
|
||||
#endif
|
||||
if (!(work=(PRECISION*)malloc((lwork=(int)opt_size)*sizeof(PRECISION))))
|
||||
if (!(work=(PRECISION*)swzMalloc((lwork=(int)opt_size)*sizeof(PRECISION))))
|
||||
{
|
||||
if (!qt) free(ptr);
|
||||
free(tau);
|
||||
|
@ -2665,7 +2665,7 @@ int bQR(PRECISION *Q, PRECISION *R, PRECISION *X, int m, int n, int q, int qt, i
|
|||
|
||||
if (Q && (q != m))
|
||||
{
|
||||
if (!(NQ=(PRECISION*)malloc(m*m*sizeof(PRECISION))))
|
||||
if (!(NQ=(PRECISION*)swzMalloc(m*m*sizeof(PRECISION))))
|
||||
return MEM_ERR;
|
||||
}
|
||||
else
|
||||
|
@ -2673,7 +2673,7 @@ int bQR(PRECISION *Q, PRECISION *R, PRECISION *X, int m, int n, int q, int qt, i
|
|||
|
||||
if (rt || (q != m))
|
||||
{
|
||||
if (!(NR=(PRECISION*)malloc(m*n*sizeof(PRECISION))))
|
||||
if (!(NR=(PRECISION*)swzMalloc(m*n*sizeof(PRECISION))))
|
||||
{
|
||||
if (NQ != Q) free(NQ);
|
||||
return MEM_ERR;
|
||||
|
@ -3583,9 +3583,9 @@ dest2: fstp PRECISION_WORD ptr [edx] // pop accumulated v
|
|||
|
||||
/* int jobz='A', k, *iwork, info; */
|
||||
/* PRECISION *X, *work, opt_size; */
|
||||
/* if (!(X=(PRECISION*)malloc(m*n*sizeof(PRECISION)))) return MEM_ERR; */
|
||||
/* if (!(X=(PRECISION*)swzMalloc(m*n*sizeof(PRECISION)))) return MEM_ERR; */
|
||||
/* memcpy(X,A,m*n*sizeof(PRECISION)); */
|
||||
/* if (!(iwork=(int*)malloc(8*((m < n) ? m : n)*sizeof(int)))) */
|
||||
/* if (!(iwork=(int*)swzMalloc(8*((m < n) ? m : n)*sizeof(int)))) */
|
||||
/* { */
|
||||
/* free(X); */
|
||||
/* return MEM_ERR; */
|
||||
|
@ -3598,7 +3598,7 @@ dest2: fstp PRECISION_WORD ptr [edx] // pop accumulated v
|
|||
/* #else */
|
||||
/* dgesdd(&jobz,&m,&n,X,&m,d,U,&m,V,&n,&opt_size,&k,iwork,&info); */
|
||||
/* #endif */
|
||||
/* if (info || !(work=(PRECISION*)malloc((k=(int)opt_size)*sizeof(PRECISION)))) */
|
||||
/* if (info || !(work=(PRECISION*)swzMalloc((k=(int)opt_size)*sizeof(PRECISION)))) */
|
||||
/* { */
|
||||
/* free(iwork); */
|
||||
/* free(X); */
|
||||
|
@ -3619,7 +3619,7 @@ dest2: fstp PRECISION_WORD ptr [edx] // pop accumulated v
|
|||
/* #else */
|
||||
/* dgesvd(&jobz,&jobz,&m,&n,X,&m,d,U,&m,V,&n,&opt_size,&k,&info); */
|
||||
/* #endif */
|
||||
/* if (info || !(work=(PRECISION*)malloc((k=(int)opt_size)*sizeof(PRECISION)))) */
|
||||
/* if (info || !(work=(PRECISION*)swzMalloc((k=(int)opt_size)*sizeof(PRECISION)))) */
|
||||
/* { */
|
||||
/* free(iwork); */
|
||||
/* free(X); */
|
||||
|
@ -3649,7 +3649,7 @@ dest2: fstp PRECISION_WORD ptr [edx] // pop accumulated v
|
|||
/* #else */
|
||||
/* dgesdd(&jobz,&n,&m,X,&n,d,V,&n,U,&m,&opt_size,&k,iwork,&info); */
|
||||
/* #endif */
|
||||
/* if (!(work=(PRECISION*)malloc((k=(int)opt_size)*sizeof(PRECISION)))) */
|
||||
/* if (!(work=(PRECISION*)swzMalloc((k=(int)opt_size)*sizeof(PRECISION)))) */
|
||||
/* { */
|
||||
/* free(iwork); */
|
||||
/* free(X); */
|
||||
|
@ -3670,7 +3670,7 @@ dest2: fstp PRECISION_WORD ptr [edx] // pop accumulated v
|
|||
/* #else */
|
||||
/* dgesvd(&jobz,&jobz,&n,&m,X,&n,d,V,&n,U,&m,&opt_size,&k,&info); */
|
||||
/* #endif */
|
||||
/* if (info || !(work=(PRECISION*)malloc((k=(int)opt_size)*sizeof(PRECISION)))) */
|
||||
/* if (info || !(work=(PRECISION*)swzMalloc((k=(int)opt_size)*sizeof(PRECISION)))) */
|
||||
/* { */
|
||||
/* free(iwork); */
|
||||
/* free(X); */
|
||||
|
|
|
@ -53,7 +53,7 @@ TVector CreateVector(int m)
|
|||
dw_Error(SIZE_ERR);
|
||||
return (TVector)NULL;
|
||||
}
|
||||
if (x=(TVector)malloc(sizeof(TVectorStructure) + (m-1)*sizeof(PRECISION)))
|
||||
if (x=(TVector)swzMalloc(sizeof(TVectorStructure) + (m-1)*sizeof(PRECISION)))
|
||||
DimV(x)=m;
|
||||
else
|
||||
dw_Error(MEM_ERR);
|
||||
|
@ -73,7 +73,7 @@ TMatrix CreateMatrix(int m, int n)
|
|||
dw_Error(SIZE_ERR);
|
||||
return (TMatrix)NULL;
|
||||
}
|
||||
if (X=(TMatrix)malloc(sizeof(TMatrixStructure) + (m*n-1)*sizeof(PRECISION)))
|
||||
if (X=(TMatrix)swzMalloc(sizeof(TMatrixStructure) + (m*n-1)*sizeof(PRECISION)))
|
||||
{
|
||||
RowM(X)=m;
|
||||
ColM(X)=n;
|
||||
|
@ -96,7 +96,7 @@ TPermutation CreatePermutation(int m)
|
|||
dw_Error(SIZE_ERR);
|
||||
return (TPermutation)NULL;
|
||||
}
|
||||
if (X=(TPermutation)malloc(sizeof(TPermutationStructure) + (m-1)*sizeof(int)))
|
||||
if (X=(TPermutation)swzMalloc(sizeof(TPermutationStructure) + (m-1)*sizeof(int)))
|
||||
{
|
||||
X->dim=m;
|
||||
X->use=0;
|
||||
|
@ -122,8 +122,8 @@ TVector CreateVector(int m)
|
|||
dw_Error(SIZE_ERR);
|
||||
return (TVector)NULL;
|
||||
}
|
||||
if (x=(TVector)malloc(sizeof(TVectorStructure)))
|
||||
if (x->x=(PRECISION*)malloc(m*sizeof(PRECISION)))
|
||||
if (x=(TVector)swzMalloc(sizeof(TVectorStructure)))
|
||||
if (x->x=(PRECISION*)swzMalloc(m*sizeof(PRECISION)))
|
||||
DimV(x)=m;
|
||||
else
|
||||
{
|
||||
|
@ -153,8 +153,8 @@ TMatrix CreateMatrix(int m, int n)
|
|||
dw_Error(SIZE_ERR);
|
||||
return (TMatrix)NULL;
|
||||
}
|
||||
if (X=(TMatrix)malloc(sizeof(TMatrixStructure)))
|
||||
if (X->x=(PRECISION*)malloc(m*n*sizeof(PRECISION)))
|
||||
if (X=(TMatrix)swzMalloc(sizeof(TMatrixStructure)))
|
||||
if (X->x=(PRECISION*)swzMalloc(m*n*sizeof(PRECISION)))
|
||||
{
|
||||
RowM(X)=m;
|
||||
ColM(X)=n;
|
||||
|
@ -190,8 +190,8 @@ TPermutation CreatePermutation(int m)
|
|||
dw_Error(SIZE_ERR);
|
||||
return (TPermutation)NULL;
|
||||
}
|
||||
if (X=(TPermutation)malloc(sizeof(TPermutationStructure)))
|
||||
if (X->x=(int*)malloc(m*sizeof(int)))
|
||||
if (X=(TPermutation)swzMalloc(sizeof(TPermutationStructure)))
|
||||
if (X->x=(int*)swzMalloc(m*sizeof(int)))
|
||||
{
|
||||
X->dim=m;
|
||||
X->use=0;
|
||||
|
@ -227,7 +227,7 @@ TVector CreateVector(int m)
|
|||
dw_Error(SIZE_ERR);
|
||||
return (TVector)NULL;
|
||||
}
|
||||
if (x=(TVector)((int *)malloc(m*sizeof(PRECISION)+sizeof(int))+1))
|
||||
if (x=(TVector)((int *)swzMalloc(m*sizeof(PRECISION)+sizeof(int))+1))
|
||||
V_DIM(x)=m;
|
||||
else
|
||||
dw_Error(MEM_ERR);
|
||||
|
@ -248,7 +248,7 @@ TMatrix CreateMatrix(int m, int n)
|
|||
dw_Error(SIZE_ERR);
|
||||
return (TMatrix)NULL;
|
||||
}
|
||||
if (X=(TMatrix)((int *)malloc(m*(sizeof(PRECISION *)+n*sizeof(PRECISION))+2*sizeof(int))+2))
|
||||
if (X=(TMatrix)((int *)swzMalloc(m*(sizeof(PRECISION *)+n*sizeof(PRECISION))+2*sizeof(int))+2))
|
||||
{
|
||||
M_ROW(X)=m;
|
||||
M_COL(X)=n;
|
||||
|
@ -273,7 +273,7 @@ TPermutation CreatePermutation(int m)
|
|||
dw_Error(SIZE_ERR);
|
||||
return (TPermutation)NULL;
|
||||
}
|
||||
if (X=(TPermutation)malloc((m+2)*sizeof(int)))
|
||||
if (X=(TPermutation)swzMalloc((m+2)*sizeof(int)))
|
||||
{
|
||||
X[0]=m;
|
||||
X[1]=0;
|
||||
|
@ -302,8 +302,8 @@ TVector CreateVector(int m)
|
|||
dw_Error(SIZE_ERR);
|
||||
return (TVector)NULL;
|
||||
}
|
||||
if (x=(TVector)malloc(sizeof(TSdvector)))
|
||||
if (!(pElementV(x)=(PRECISION*)malloc(m*sizeof(PRECISION))))
|
||||
if (x=(TVector)swzMalloc(sizeof(TSdvector)))
|
||||
if (!(pElementV(x)=(PRECISION*)swzMalloc(m*sizeof(PRECISION))))
|
||||
{
|
||||
free(x);
|
||||
dw_Error(MEM_ERR);
|
||||
|
@ -336,8 +336,8 @@ TMatrix CreateMatrix(int m, int n)
|
|||
dw_Error(SIZE_ERR);
|
||||
return (TMatrix)NULL;
|
||||
}
|
||||
if (X=(TMatrix)malloc(sizeof(TSdmatrix)))
|
||||
if (!(pElementM(X)=(PRECISION*)malloc(m*n*sizeof(PRECISION))))
|
||||
if (X=(TMatrix)swzMalloc(sizeof(TSdmatrix)))
|
||||
if (!(pElementM(X)=(PRECISION*)swzMalloc(m*n*sizeof(PRECISION))))
|
||||
{
|
||||
free(X);
|
||||
dw_Error(MEM_ERR);
|
||||
|
@ -362,7 +362,7 @@ TPermutation CreatePermutation(int m)
|
|||
dw_Error(SIZE_ERR);
|
||||
return (TPermutation)NULL;
|
||||
}
|
||||
if (X=(TPermutation)malloc(sizeof(TPermutationStructure) + (m-1)*sizeof(int)))
|
||||
if (X=(TPermutation)swzMalloc(sizeof(TPermutationStructure) + (m-1)*sizeof(int)))
|
||||
{
|
||||
X->dim=m;
|
||||
X->use=0;
|
||||
|
@ -1381,7 +1381,7 @@ TMatrix UpdateMS(TMatrix X, TMatrix Y, PRECISION a)
|
|||
bLinearUpdateScalar(pElementM(X),pElementM(Y),a,RowM(Y)*ColM(Y));
|
||||
else
|
||||
{
|
||||
if (!(z=(PRECISION*)malloc(RowM(Y)*ColM(Y)*sizeof(PRECISION))))
|
||||
if (!(z=(PRECISION*)swzMalloc(RowM(Y)*ColM(Y)*sizeof(PRECISION))))
|
||||
{
|
||||
dw_Error(MEM_ERR);
|
||||
return (TMatrix)NULL;
|
||||
|
@ -1489,7 +1489,7 @@ TMatrix LinearCombinationMM(TMatrix X, PRECISION a, TMatrix Y, PRECISION b, TMat
|
|||
else
|
||||
if (X == Z)
|
||||
{
|
||||
if (!(p=(PRECISION*)malloc(RowM(Y)*ColM(Y)*sizeof(PRECISION))))
|
||||
if (!(p=(PRECISION*)swzMalloc(RowM(Y)*ColM(Y)*sizeof(PRECISION))))
|
||||
{
|
||||
dw_Error(MEM_ERR);
|
||||
if (!W) FreeMatrix(X);
|
||||
|
@ -1502,7 +1502,7 @@ TMatrix LinearCombinationMM(TMatrix X, PRECISION a, TMatrix Y, PRECISION b, TMat
|
|||
else
|
||||
if (X == Y)
|
||||
{
|
||||
if (!(p=(PRECISION*)malloc(RowM(Z)*ColM(Z)*sizeof(PRECISION))))
|
||||
if (!(p=(PRECISION*)swzMalloc(RowM(Z)*ColM(Z)*sizeof(PRECISION))))
|
||||
{
|
||||
dw_Error(MEM_ERR);
|
||||
if (!W) FreeMatrix(X);
|
||||
|
@ -1647,7 +1647,7 @@ TVector ProductVM(TVector x, TVector y, TMatrix Z)
|
|||
}
|
||||
if (x == y)
|
||||
{
|
||||
if (!(ptr=(PRECISION*)malloc(DimV(x)*sizeof(PRECISION))))
|
||||
if (!(ptr=(PRECISION*)swzMalloc(DimV(x)*sizeof(PRECISION))))
|
||||
{
|
||||
dw_Error(MEM_ERR);
|
||||
return (TVector)NULL;
|
||||
|
@ -1705,7 +1705,7 @@ TVector ProductMV(TVector x, TMatrix Y, TVector z)
|
|||
}
|
||||
if (x == z)
|
||||
{
|
||||
if (!(ptr=(PRECISION*)malloc(DimV(x)*sizeof(PRECISION))))
|
||||
if (!(ptr=(PRECISION*)swzMalloc(DimV(x)*sizeof(PRECISION))))
|
||||
{
|
||||
dw_Error(MEM_ERR);
|
||||
return (TVector)NULL;
|
||||
|
@ -1765,7 +1765,7 @@ TMatrix ProductMM(TMatrix X, TMatrix Y, TMatrix Z)
|
|||
}
|
||||
if ((X == Y) || (X == Z))
|
||||
{
|
||||
if (!(ptr=(PRECISION*)malloc(RowM(X)*ColM(X)*sizeof(PRECISION))))
|
||||
if (!(ptr=(PRECISION*)swzMalloc(RowM(X)*ColM(X)*sizeof(PRECISION))))
|
||||
{
|
||||
dw_Error(MEM_ERR);
|
||||
return (TMatrix)NULL;
|
||||
|
@ -1831,7 +1831,7 @@ TMatrix TransposeProductMM(TMatrix X, TMatrix Y, TMatrix Z)
|
|||
}
|
||||
if ((X == Y) || (X == Z))
|
||||
{
|
||||
if (!(ptr=(PRECISION*)malloc(RowM(X)*ColM(X)*sizeof(PRECISION))))
|
||||
if (!(ptr=(PRECISION*)swzMalloc(RowM(X)*ColM(X)*sizeof(PRECISION))))
|
||||
{
|
||||
dw_Error(MEM_ERR);
|
||||
return (TMatrix)NULL;
|
||||
|
@ -1891,7 +1891,7 @@ TMatrix ProductTransposeMM(TMatrix X, TMatrix Y, TMatrix Z)
|
|||
}
|
||||
if ((X == Y) || (X == Z))
|
||||
{
|
||||
if (!(ptr=(PRECISION*)malloc(RowM(X)*ColM(X)*sizeof(PRECISION))))
|
||||
if (!(ptr=(PRECISION*)swzMalloc(RowM(X)*ColM(X)*sizeof(PRECISION))))
|
||||
{
|
||||
dw_Error(MEM_ERR);
|
||||
return (TMatrix)NULL;
|
||||
|
@ -1942,11 +1942,11 @@ TVector InverseProductMV(TVector x, TMatrix Y, TVector z)
|
|||
if ((RowM(Y) != ColM(Y)) || (ColM(Y) != DimV(z)))
|
||||
dw_Error(SIZE_ERR);
|
||||
else
|
||||
if (!(p=(int*)malloc(RowM(Y)*sizeof(int))))
|
||||
if (!(p=(int*)swzMalloc(RowM(Y)*sizeof(int))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
if (!(LU=(PRECISION*)malloc(RowM(Y)*RowM(Y)*sizeof(PRECISION))))
|
||||
if (!(LU=(PRECISION*)swzMalloc(RowM(Y)*RowM(Y)*sizeof(PRECISION))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
|
@ -2073,11 +2073,11 @@ TMatrix InverseProductMM(TMatrix X, TMatrix Y, TMatrix Z)
|
|||
if ((RowM(Y) != ColM(Y)) || (ColM(Y) != RowM(Z)))
|
||||
dw_Error(SIZE_ERR);
|
||||
else
|
||||
if (!(p=(int*)malloc((q=(RowM(Y) < ColM(Y)) ? RowM(Y) : ColM(Y))*sizeof(int))))
|
||||
if (!(p=(int*)swzMalloc((q=(RowM(Y) < ColM(Y)) ? RowM(Y) : ColM(Y))*sizeof(int))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
if (!(LU=(PRECISION*)malloc(RowM(Y)*RowM(Y)*sizeof(PRECISION))))
|
||||
if (!(LU=(PRECISION*)swzMalloc(RowM(Y)*RowM(Y)*sizeof(PRECISION))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
|
@ -2129,7 +2129,7 @@ TMatrix InverseProductUM(TMatrix X, TMatrix Y, TMatrix Z)
|
|||
dw_Error(SIZE_ERR);
|
||||
else
|
||||
if (X == Y)
|
||||
if (!(ptr=(PRECISION*)malloc(RowM(Y)*RowM(Y)*sizeof(PRECISION))))
|
||||
if (!(ptr=(PRECISION*)swzMalloc(RowM(Y)*RowM(Y)*sizeof(PRECISION))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
|
@ -2184,7 +2184,7 @@ TMatrix InverseProductLM(TMatrix X, TMatrix Y, TMatrix Z)
|
|||
dw_Error(SIZE_ERR);
|
||||
else
|
||||
if (X == Y)
|
||||
if (!(ptr=(PRECISION*)malloc(RowM(Y)*RowM(Y)*sizeof(PRECISION))))
|
||||
if (!(ptr=(PRECISION*)swzMalloc(RowM(Y)*RowM(Y)*sizeof(PRECISION))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
|
@ -2239,11 +2239,11 @@ TVector ProductInverseVM(TVector x, TVector y, TMatrix Z)
|
|||
if ((RowM(Z) != ColM(Z)) || (DimV(y) != RowM(Z)))
|
||||
dw_Error(SIZE_ERR);
|
||||
else
|
||||
if (!(p=(int*)malloc(RowM(Z)*sizeof(int))))
|
||||
if (!(p=(int*)swzMalloc(RowM(Z)*sizeof(int))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
if (!(LU=(PRECISION*)malloc(RowM(Z)*RowM(Z)*sizeof(PRECISION))))
|
||||
if (!(LU=(PRECISION*)swzMalloc(RowM(Z)*RowM(Z)*sizeof(PRECISION))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
|
@ -2370,11 +2370,11 @@ TMatrix ProductInverseMM(TMatrix X, TMatrix Y, TMatrix Z)
|
|||
if ((RowM(Z) != ColM(Z)) || (ColM(Y) != RowM(Z)))
|
||||
dw_Error(SIZE_ERR);
|
||||
else
|
||||
if (!(p=(int*)malloc(RowM(Z)*sizeof(int))))
|
||||
if (!(p=(int*)swzMalloc(RowM(Z)*sizeof(int))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
if (!(LU=(PRECISION*)malloc(RowM(Z)*RowM(Z)*sizeof(PRECISION))))
|
||||
if (!(LU=(PRECISION*)swzMalloc(RowM(Z)*RowM(Z)*sizeof(PRECISION))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
|
@ -2426,7 +2426,7 @@ TMatrix ProductInverseMU(TMatrix X, TMatrix Y, TMatrix Z)
|
|||
dw_Error(SIZE_ERR);
|
||||
else
|
||||
if (X == Z)
|
||||
if (!(ptr=(PRECISION*)malloc(RowM(Z)*RowM(Z)*sizeof(PRECISION))))
|
||||
if (!(ptr=(PRECISION*)swzMalloc(RowM(Z)*RowM(Z)*sizeof(PRECISION))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
|
@ -2481,7 +2481,7 @@ TMatrix ProductInverseML(TMatrix X, TMatrix Y, TMatrix Z)
|
|||
dw_Error(SIZE_ERR);
|
||||
else
|
||||
if (X == Z)
|
||||
if (!(ptr=(PRECISION*)malloc(RowM(Z)*RowM(Z)*sizeof(PRECISION))))
|
||||
if (!(ptr=(PRECISION*)swzMalloc(RowM(Z)*RowM(Z)*sizeof(PRECISION))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
|
@ -2540,11 +2540,11 @@ TMatrix Inverse_LU(TMatrix X, TMatrix Y)
|
|||
if (RowM(Y) != ColM(Y))
|
||||
dw_Error(SIZE_ERR);
|
||||
else
|
||||
if (!(p=(int*)malloc(RowM(Y)*sizeof(int))))
|
||||
if (!(p=(int*)swzMalloc(RowM(Y)*sizeof(int))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
if (!(LU=(PRECISION*)malloc(RowM(Y)*RowM(Y)*sizeof(PRECISION))))
|
||||
if (!(LU=(PRECISION*)swzMalloc(RowM(Y)*RowM(Y)*sizeof(PRECISION))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
|
@ -2593,15 +2593,15 @@ TMatrix Inverse_SVD(TMatrix X, TMatrix Y)
|
|||
if (RowM(Y) != ColM(Y))
|
||||
dw_Error(SIZE_ERR);
|
||||
else
|
||||
if (!(U=(PRECISION*)malloc(RowM(Y)*RowM(Y)*sizeof(PRECISION))))
|
||||
if (!(U=(PRECISION*)swzMalloc(RowM(Y)*RowM(Y)*sizeof(PRECISION))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
if (!(V=(PRECISION*)malloc(RowM(Y)*RowM(Y)*sizeof(PRECISION))))
|
||||
if (!(V=(PRECISION*)swzMalloc(RowM(Y)*RowM(Y)*sizeof(PRECISION))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
if (!(d=(PRECISION*)malloc(RowM(Y)*sizeof(PRECISION))))
|
||||
if (!(d=(PRECISION*)swzMalloc(RowM(Y)*sizeof(PRECISION))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
|
@ -2674,7 +2674,7 @@ TMatrix Inverse_Cholesky(TMatrix X, TMatrix Y)
|
|||
if (RowM(Y) != ColM(Y))
|
||||
dw_Error(SIZE_ERR);
|
||||
else
|
||||
if (!(ptr=(PRECISION*)malloc(RowM(Y)*RowM(Y)*sizeof(PRECISION))))
|
||||
if (!(ptr=(PRECISION*)swzMalloc(RowM(Y)*RowM(Y)*sizeof(PRECISION))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
|
@ -2739,7 +2739,7 @@ TMatrix Inverse_UT(TMatrix X, TMatrix T)
|
|||
else
|
||||
if (X == T)
|
||||
{
|
||||
if (!(ptr=(PRECISION*)malloc(RowM(T)*RowM(T)*sizeof(PRECISION))))
|
||||
if (!(ptr=(PRECISION*)swzMalloc(RowM(T)*RowM(T)*sizeof(PRECISION))))
|
||||
{
|
||||
dw_Error(MEM_ERR);
|
||||
return (TMatrix)NULL;
|
||||
|
@ -2808,7 +2808,7 @@ TMatrix Inverse_LT(TMatrix X, TMatrix T)
|
|||
else
|
||||
if (X == T)
|
||||
{
|
||||
if (!(ptr=(PRECISION*)malloc(RowM(T)*RowM(T)*sizeof(PRECISION))))
|
||||
if (!(ptr=(PRECISION*)swzMalloc(RowM(T)*RowM(T)*sizeof(PRECISION))))
|
||||
{
|
||||
dw_Error(MEM_ERR);
|
||||
return (TMatrix)NULL;
|
||||
|
@ -2906,7 +2906,7 @@ PRECISION MatrixNorm(TMatrix X)
|
|||
dw_Error(NULL_ERR);
|
||||
return 0.0;
|
||||
}
|
||||
if (!(d=(PRECISION*)malloc(((RowM(X) < ColM(X)) ? RowM(X) : ColM(X))*sizeof(PRECISION))))
|
||||
if (!(d=(PRECISION*)swzMalloc(((RowM(X) < ColM(X)) ? RowM(X) : ColM(X))*sizeof(PRECISION))))
|
||||
{
|
||||
dw_Error(MEM_ERR);
|
||||
return 0.0;
|
||||
|
@ -3043,11 +3043,11 @@ PRECISION Determinant_LU(TMatrix X)
|
|||
if (RowM(X) != ColM(X))
|
||||
dw_Error(SIZE_ERR);
|
||||
else
|
||||
if (!(p=(int*)malloc(RowM(X)*sizeof(int))))
|
||||
if (!(p=(int*)swzMalloc(RowM(X)*sizeof(int))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
if (!(LU=(PRECISION*)malloc(RowM(X)*RowM(X)*sizeof(PRECISION))))
|
||||
if (!(LU=(PRECISION*)swzMalloc(RowM(X)*RowM(X)*sizeof(PRECISION))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
|
@ -3099,11 +3099,11 @@ PRECISION LogAbsDeterminant_LU(TMatrix X)
|
|||
if (RowM(X) != ColM(X))
|
||||
dw_Error(SIZE_ERR);
|
||||
else
|
||||
if (!(p=(int*)malloc(RowM(X)*sizeof(int))))
|
||||
if (!(p=(int*)swzMalloc(RowM(X)*sizeof(int))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
if (!(LU=(PRECISION*)malloc(RowM(X)*RowM(X)*sizeof(PRECISION))))
|
||||
if (!(LU=(PRECISION*)swzMalloc(RowM(X)*RowM(X)*sizeof(PRECISION))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
|
@ -3151,7 +3151,7 @@ PRECISION Determinant_QR(TMatrix X)
|
|||
if (RowM(X) != ColM(X))
|
||||
dw_Error(SIZE_ERR);
|
||||
else
|
||||
if (!(R=(PRECISION*)malloc(RowM(X)*RowM(X)*sizeof(PRECISION))))
|
||||
if (!(R=(PRECISION*)swzMalloc(RowM(X)*RowM(X)*sizeof(PRECISION))))
|
||||
dw_Error(MEM_ERR);
|
||||
else
|
||||
{
|
||||
|
@ -3463,7 +3463,7 @@ TMatrix NullSpace(TMatrix Y)
|
|||
return (TMatrix)NULL;
|
||||
}
|
||||
q=(RowM(Y) < ColM(Y)) ? RowM(Y) : ColM(Y);
|
||||
d=(PRECISION*)malloc(q*sizeof(PRECISION));
|
||||
d=(PRECISION*)swzMalloc(q*sizeof(PRECISION));
|
||||
v=CreateMatrix(ColM(Y),ColM(Y));
|
||||
if (d && v)
|
||||
{
|
||||
|
@ -3537,7 +3537,7 @@ TMatrix GeneralizedInverse(TMatrix X, TMatrix Y)
|
|||
return (TMatrix)NULL;
|
||||
}
|
||||
q=(RowM(Y) < ColM(Y)) ? RowM(Y) : ColM(Y);
|
||||
d=(PRECISION*)malloc(q*sizeof(PRECISION));
|
||||
d=(PRECISION*)swzMalloc(q*sizeof(PRECISION));
|
||||
u=CreateMatrix(RowM(Y),q);
|
||||
v=CreateMatrix(ColM(Y),q);
|
||||
if (d && u && v)
|
||||
|
@ -3966,7 +3966,7 @@ TVector InVector(FILE *f, TVector x)
|
|||
|
||||
if (precision != sizeof(PRECISION))
|
||||
{
|
||||
if (!(y=malloc(i*precision))) dw_Error(MEM_ERR);
|
||||
if (!(y=swzMalloc(i*precision))) dw_Error(MEM_ERR);
|
||||
if (fread(y,i*precision,1,f) != 1) goto EXIT_ERROR;
|
||||
if (precision == sizeof(float))
|
||||
while (--i >= 0) ElementV(x,i)=((float*)y)[i];
|
||||
|
@ -4032,7 +4032,7 @@ TMatrix InMatrix(FILE *f, TMatrix X)
|
|||
|
||||
if (precision != sizeof(PRECISION))
|
||||
{
|
||||
if (!(Y=malloc(i*precision))) dw_Error(MEM_ERR);
|
||||
if (!(Y=swzMalloc(i*precision))) dw_Error(MEM_ERR);
|
||||
if (fread(Y,i*precision,1,f) != 1) goto EXIT_ERROR;
|
||||
if (precision == sizeof(float))
|
||||
while (--i >= 0) pElementM(X)[i]=((float*)Y)[i];
|
||||
|
@ -4545,7 +4545,7 @@ int QR(TMatrix Q, TMatrix R, TMatrix X)
|
|||
}
|
||||
else
|
||||
if ((RowM(R) == ColM(X)) && (ColM(X) < RowM(X)))
|
||||
if (!(ptr=(PRECISION*)malloc(RowM(X)*ColM(X)*sizeof(PRECISION))))
|
||||
if (!(ptr=(PRECISION*)swzMalloc(RowM(X)*ColM(X)*sizeof(PRECISION))))
|
||||
{
|
||||
dw_Error(MEM_ERR);
|
||||
return 0;
|
||||
|
@ -4730,7 +4730,7 @@ TVector LU_SolveRowM(TVector x, TVector y, TMatrix LU, TPermutation P)
|
|||
if ((DimV(x) != DimV(y)) || (RowM(LU) != DimV(y)) || (ColM(LU) != DimV(y)) || (DimP(P) != DimV(y)))
|
||||
{ dw_Error(SIZE_ERR); return (TVector)NULL; }
|
||||
|
||||
if (!(z=(PRECISION*)malloc(sizeof(PRECISION)*DimV(y)))) { dw_Error(SIZE_ERR); return (TVector)NULL; }
|
||||
if (!(z=(PRECISION*)swzMalloc(sizeof(PRECISION)*DimV(y)))) { dw_Error(SIZE_ERR); return (TVector)NULL; }
|
||||
|
||||
for (j=0; j < DimV(y); j++)
|
||||
{
|
||||
|
|
|
@ -36,7 +36,7 @@ typedef struct
|
|||
|
||||
|
||||
/* // memory management ansi-c*/
|
||||
#define tzMalloc(elt_count,type) (type *)malloc((elt_count)*sizeof(type))
|
||||
#define tzMalloc(elt_count,type) (type *)swzMalloc((elt_count)*sizeof(type))
|
||||
#define tzDestroy(x) {if (x) { free((x)); (x) = NULL; }}
|
||||
|
||||
/* // i/o ansi-c*/
|
||||
|
|
|
@ -342,7 +342,7 @@ static void b_qsort_matrix_columns_ascending_real(PRECISION *x, int m, int n, in
|
|||
{
|
||||
PRECISION *y, c;
|
||||
int j, k, p, s;
|
||||
y=(PRECISION*)malloc(s=m*sizeof(PRECISION));
|
||||
y=(PRECISION*)swzMalloc(s=m*sizeof(PRECISION));
|
||||
if (n > 10)
|
||||
{
|
||||
/* // quick sort ansi-c*/
|
||||
|
@ -410,7 +410,7 @@ static void b_qsort_matrix_columns_descending_real(PRECISION *x, int m, int n, i
|
|||
{
|
||||
PRECISION *y, c;
|
||||
int j, k, p, s;
|
||||
y=(PRECISION*)malloc(s=m*sizeof(PRECISION));
|
||||
y=(PRECISION*)swzMalloc(s=m*sizeof(PRECISION));
|
||||
if (n > 10)
|
||||
{
|
||||
/* // quick sort ansi-c*/
|
||||
|
|
|
@ -119,7 +119,7 @@ void SetupSpherical_Table(int n, PRECISION *table, int m)
|
|||
SPHERICAL_DIM=n;
|
||||
SPHERICAL_CONSTANT=log(0.5) + dw_log_gamma(0.5*n) - 0.5*n*log(PI);
|
||||
if (SPHERICAL_TABLE_VALUES) free(SPHERICAL_TABLE_VALUES);
|
||||
SPHERICAL_TABLE_VALUES=(PRECISION*)malloc((m+1)*sizeof(PRECISION));
|
||||
SPHERICAL_TABLE_VALUES=(PRECISION*)swzMalloc((m+1)*sizeof(PRECISION));
|
||||
SPHERICAL_TABLE_LENGTH=m;
|
||||
memcpy(SPHERICAL_TABLE_VALUES,table,(m+1)*sizeof(PRECISION));
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ void* dw_get_generator_state(void)
|
|||
{
|
||||
#if defined(USE_IMSL_RNG)
|
||||
int *state=(int*)NULL;
|
||||
if (state=(int*)malloc(1566*sizeof(int)))
|
||||
if (state=(int*)swzMalloc(1566*sizeof(int)))
|
||||
{
|
||||
imsls_random_GFSR_table_get(&state,IMSLS_RETURN_USER,state,0);
|
||||
state[1565]=imsls_random_seed_get();
|
||||
|
@ -77,7 +77,7 @@ void* dw_get_generator_state(void)
|
|||
return state;
|
||||
#elif defined (USE_NR1_RNG)
|
||||
int *state=(int*)NULL;
|
||||
if (state=(int*)malloc((NTAB+2)*sizeof(int)))
|
||||
if (state=(int*)swzMalloc((NTAB+2)*sizeof(int)))
|
||||
{
|
||||
memcpy(state,iv,NTAB*sizeof(int));
|
||||
state[NTAB]=iy;
|
||||
|
@ -86,7 +86,7 @@ void* dw_get_generator_state(void)
|
|||
return state;
|
||||
#elif defined (USE_NR2_RNG)
|
||||
int *state=(int*)NULL;
|
||||
if (state=(int*)malloc((NTAB+3)*sizeof(int)))
|
||||
if (state=(int*)swzMalloc((NTAB+3)*sizeof(int)))
|
||||
{
|
||||
memcpy(state,iv,NTAB*sizeof(int));
|
||||
state[NTAB]=iy;
|
||||
|
@ -170,7 +170,7 @@ void dw_read_generator_state(FILE *f)
|
|||
{
|
||||
#if defined(USE_IMSL_RNG)
|
||||
int i, *state;
|
||||
if (state=(int*)malloc(1566*sizeof(int)))
|
||||
if (state=(int*)swzMalloc(1566*sizeof(int)))
|
||||
{
|
||||
for (i=0; i < 1566; i++) fscanf(f," %d ",state+i);
|
||||
dw_set_generator_state(state);
|
||||
|
@ -178,7 +178,7 @@ void dw_read_generator_state(FILE *f)
|
|||
}
|
||||
#elif defined (USE_NR1_RNG)
|
||||
int i, *state;
|
||||
if (state=(int*)malloc((NTAB+2)*sizeof(int)))
|
||||
if (state=(int*)swzMalloc((NTAB+2)*sizeof(int)))
|
||||
{
|
||||
for (i=0; i < NTAB+2; i++) fscanf(f," %d ",state+i);
|
||||
dw_set_generator_state(state);
|
||||
|
@ -186,7 +186,7 @@ void dw_read_generator_state(FILE *f)
|
|||
}
|
||||
#elif defined (USE_NR2_RNG)
|
||||
int i, *state;
|
||||
if (state=(int*)malloc((NTAB+3)*sizeof(int)))
|
||||
if (state=(int*)swzMalloc((NTAB+3)*sizeof(int)))
|
||||
{
|
||||
for (i=0; i < NTAB+3; i++) fscanf(f," %d ",state+i);
|
||||
dw_set_generator_state(state);
|
||||
|
|
|
@ -67,7 +67,7 @@ void fn_DisplayError(char *msg_s)
|
|||
/* //----------------- ansi-c*/
|
||||
void *m_alloc(size_t size) {
|
||||
void *new_mem;
|
||||
if ( (new_mem = malloc(size)) == NULL ) fn_DisplayError("Out of Memory!");
|
||||
if ( (new_mem = swzMalloc(size)) == NULL ) fn_DisplayError("Out of Memory!");
|
||||
return(new_mem);
|
||||
}
|
||||
/* //+ ansi-c*/
|
||||
|
|
Loading…
Reference in New Issue