Skip to content

Commit

Permalink
Replacing ErrorModel macros with constexpr/enum.
Browse files Browse the repository at this point in the history
  • Loading branch information
jholloc committed Nov 4, 2024
1 parent d6fefc6 commit 1a0c225
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 81 deletions.
52 changes: 26 additions & 26 deletions source/c_api/accAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ void udaPutErrorModel(int handle, int model, int param_n, const float* params)
if (data_block == nullptr) {
return;
}
if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) {
if (model <= (int)ErrorModelType::Unknown || model >= (int)ErrorModelType::Undefined) {
return; // No valid Model
}

Expand All @@ -525,7 +525,7 @@ void udaPutDimErrorModel(int handle, int ndim, int model, int param_n, const flo
if (ndim < 0 || (unsigned int)ndim >= data_block->rank) {
return; // No Dim
}
if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) {
if (model <= (int)ErrorModelType::Unknown || model >= (int)ErrorModelType::Undefined) {
return; // No valid Model
}

Expand Down Expand Up @@ -986,7 +986,7 @@ void udaGetErrorModel(int handle, int* model, int* param_n, float* params)
{
auto data_block = getDataBlock(handle);
if (data_block == nullptr) {
*model = ERROR_MODEL_UNKNOWN;
*model = (int)ErrorModelType::Unknown;
*param_n = 0;
return;
}
Expand All @@ -1010,42 +1010,42 @@ int udaGetErrorAsymmetry(int handle)

int udaGetErrorModelId(const char* model)
{
for (int i = 1; i < ERROR_MODEL_UNDEFINED; i++) {
for (int i = 1; i < (int)ErrorModelType::Undefined; i++) {
switch (i) {
case 1:
if (STR_IEQUALS(model, "default")) {
return ERROR_MODEL_DEFAULT;
return (int)ErrorModelType::Default;
}
break;
case 2:
if (STR_IEQUALS(model, "default_asymmetric")) {
return ERROR_MODEL_DEFAULT_ASYMMETRIC;
return (int)ErrorModelType::DefaultAsymmetric;
}
break;
#ifdef NO_GSL_LIB
case 3:
if (STR_IEQUALS(model, "gaussian")) {
return ERROR_MODEL_GAUSSIAN;
return ErrorModelType::Gaussian;
}
break;
case 4:
if (STR_IEQUALS(model, "reseed")) {
return ERROR_MODEL_RESEED;
return ErrorModelType::Reseed;
}
break;
case 5:
if (STR_IEQUALS(model, "gaussian_shift")) {
return ERROR_MODEL_GAUSSIAN_SHIFT;
return ErrorModelType::GaussianShift;
}
break;
case 6:
if (STR_IEQUALS(model, "poisson")) {
return ERROR_MODEL_POISSON;
return ErrorModelType::Poisson;
}
break;
#endif
default:
return ERROR_MODEL_UNKNOWN;
return (int)ErrorModelType::Unknown;
}
}
return 0;
Expand Down Expand Up @@ -1093,10 +1093,10 @@ char* udaGetSyntheticData(int handle)
if (status != MIN_STATUS && (data_block->client_block.get_bad || client_flags->get_bad)) {
return nullptr;
}
if (!client_flags->get_synthetic || data_block->error_model == ERROR_MODEL_UNKNOWN) {
if (!client_flags->get_synthetic || data_block->error_model == (int)ErrorModelType::Unknown) {
return data_block->data;
}
generateIdamSyntheticData(handle);
generate_synthetic_data(handle);
return data_block->synthetic;
}

Expand Down Expand Up @@ -1253,8 +1253,8 @@ char* udaGetAsymmetricError(int handle, int above)
} // otherwise the data array must have been returned by the server or generated
}
} else {
if (data_block->error_model != ERROR_MODEL_UNKNOWN) {
generateIdamDataError(handle); // Create the errors from a model if the model exits
if (data_block->error_model != (int)ErrorModelType::Unknown) {
generate_data_error(handle); // Create the errors from a model if the model exits
if (above) {
return data_block->errhi;
} else if (!data_block->errasymmetry) {
Expand Down Expand Up @@ -1550,7 +1550,7 @@ void udaGetDoubleData(int handle, double* fp)
if (!client_flags->get_synthetic) {
memcpy((void*)fp, (void*)data_block->data, (size_t)data_block->data_n * sizeof(double));
} else {
generateIdamSyntheticData(handle);
generate_synthetic_data(handle);
if (data_block->synthetic != nullptr) {
memcpy((void*)fp, (void*)data_block->synthetic, (size_t)data_block->data_n * sizeof(double));
} else {
Expand All @@ -1568,7 +1568,7 @@ void udaGetDoubleData(int handle, double* fp)
if (!client_flags->get_synthetic) {
array = data_block->data;
} else {
generateIdamSyntheticData(handle);
generate_synthetic_data(handle);
if (data_block->synthetic != nullptr) {
array = data_block->synthetic;
} else {
Expand Down Expand Up @@ -1717,7 +1717,7 @@ void udaGetFloatData(int handle, float* fp)
if (!client_flags->get_synthetic) {
memcpy((void*)fp, (void*)data_block->data, (size_t)data_block->data_n * sizeof(float));
} else {
generateIdamSyntheticData(handle);
generate_synthetic_data(handle);
if (data_block->synthetic != nullptr) {
memcpy((void*)fp, (void*)data_block->synthetic, (size_t)data_block->data_n * sizeof(float));
} else {
Expand All @@ -1735,7 +1735,7 @@ void udaGetFloatData(int handle, float* fp)
if (!client_flags->get_synthetic) {
array = data_block->data;
} else {
generateIdamSyntheticData(handle);
generate_synthetic_data(handle);
if (data_block->synthetic != nullptr) {
array = data_block->synthetic;
} else {
Expand Down Expand Up @@ -2301,7 +2301,7 @@ void udaGetDimErrorModel(int handle, int ndim, int* model, int* param_n, float*
auto data_block = getDataBlock(handle);
if (data_block == nullptr || ndim < 0 || (unsigned int)ndim >= data_block->rank) {

*model = ERROR_MODEL_UNKNOWN;
*model = (int)ErrorModelType::Unknown;
*param_n = 0;
return;
}
Expand Down Expand Up @@ -2413,7 +2413,7 @@ void udaGetDoubleDimData(int handle, int ndim, double* fp)
if (!client_flags->get_synthetic) {
memcpy((void*)fp, (void*)data_block->dims[ndim].dim, (size_t)data_block->dims[ndim].dim_n * sizeof(double));
} else {
generateIdamSyntheticDimData(handle, ndim);
generate_synthetic_dim_data(handle, ndim);
if (data_block->dims[ndim].synthetic != nullptr) {
memcpy((void*)fp, (void*)data_block->dims[ndim].synthetic,
(size_t)data_block->dims[ndim].dim_n * sizeof(double));
Expand All @@ -2430,7 +2430,7 @@ void udaGetDoubleDimData(int handle, int ndim, double* fp)
if (!client_flags->get_synthetic) {
array = data_block->dims[ndim].dim;
} else {
generateIdamSyntheticDimData(handle, ndim);
generate_synthetic_dim_data(handle, ndim);
if (data_block->dims[ndim].synthetic != nullptr) {
array = data_block->dims[ndim].synthetic;
} else {
Expand Down Expand Up @@ -2569,7 +2569,7 @@ void udaGetFloatDimData(int handle, int ndim, float* fp)
if (!client_flags->get_synthetic) {
memcpy((void*)fp, (void*)data_block->dims[ndim].dim, (size_t)data_block->dims[ndim].dim_n * sizeof(float));
} else {
generateIdamSyntheticDimData(handle, ndim);
generate_synthetic_dim_data(handle, ndim);
if (data_block->dims[ndim].synthetic != nullptr) {
memcpy((void*)fp, (void*)data_block->dims[ndim].synthetic,
(size_t)data_block->dims[ndim].dim_n * sizeof(float));
Expand All @@ -2586,7 +2586,7 @@ void udaGetFloatDimData(int handle, int ndim, float* fp)
if (!client_flags->get_synthetic) {
array = data_block->dims[ndim].dim;
} else {
generateIdamSyntheticDimData(handle, ndim);
generate_synthetic_dim_data(handle, ndim);
if (data_block->dims[ndim].synthetic != nullptr) {
array = data_block->dims[ndim].synthetic;
} else {
Expand Down Expand Up @@ -2797,8 +2797,8 @@ char* udaGetDimAsymmetricError(int handle, int ndim, int above)
} // otherwise the data array must have been returned by the server
} // or generated in a previous call
} else {
if (data_block->dims[ndim].error_model != ERROR_MODEL_UNKNOWN) {
generateIdamDimDataError(handle, ndim);
if (data_block->dims[ndim].error_model != (int)ErrorModelType::Unknown) {
generate_dim_data_error(handle, ndim);
if (above || !data_block->dims[ndim].errasymmetry) {
return data_block->dims[ndim].errhi;
} else {
Expand Down
49 changes: 26 additions & 23 deletions source/client/generateErrors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ using namespace uda::client;
//--------------------------------------------------------------------------------------------------------------
// Generate Error Data

int uda::client::idamErrorModel(int model, int param_n, float* params, int data_n, float* data, int* asymmetry,
int uda::client::error_model(int model, int param_n, float* params, int data_n, float* data, int* asymmetry,
float* errhi, float* errlo)
{
*asymmetry = 0; // No Error Asymmetry for most models

switch (model) {
switch ((ErrorModelType)model) {

case ERROR_MODEL_DEFAULT:
case ErrorModelType::Default:
if (param_n != 2) {
return 1;
}
Expand All @@ -46,7 +46,7 @@ int uda::client::idamErrorModel(int model, int param_n, float* params, int data_
}
break;

case ERROR_MODEL_DEFAULT_ASYMMETRIC:
case ErrorModelType::DefaultAsymmetric:
if (param_n != 4) {
return 1;
}
Expand Down Expand Up @@ -74,7 +74,7 @@ int uda::client::idamErrorModel(int model, int param_n, float* params, int data_
// GSL_RNG_SEED 12345 for the seed value
// GSL_RNG_TYPE mrg for the name of the random number generator

int uda::client::idamSyntheticModel(int model, int param_n, float* params, int data_n, float* data)
int uda::client::synthetic_model(int model, int param_n, float* params, int data_n, float* data)
{

#ifdef NO_GSL_LIB
Expand All @@ -91,12 +91,12 @@ int uda::client::idamSyntheticModel(int model, int param_n, float* params, int d
gsl_rng_env_setup();
random = gsl_rng_alloc(gsl_rng_default);
gsl_rng_set(random,
(unsigned long int)ERROR_MODEL_SEED); // Seed the Random Number generator with the library default
(unsigned long int)ErrorModelSeed); // Seed the Random Number generator with the library default
}

switch (model) {
switch ((ErrorModelType)model) {

case ERROR_MODEL_GAUSSIAN: // Standard normal Distribution
case ErrorModelType::Gaussian: // Standard normal Distribution
if (param_n < 1 || param_n > 2) {
return 1;
}
Expand All @@ -108,13 +108,13 @@ int uda::client::idamSyntheticModel(int model, int param_n, float* params, int d
}
break;

case ERROR_MODEL_RESEED: // Change the Seed
case ErrorModelType::Reseed: // Change the Seed
if (param_n == 1) {
gsl_rng_set(random, (unsigned long int)params[0]);
}
break;

case ERROR_MODEL_GAUSSIAN_SHIFT:
case ErrorModelType::GaussianShift:
if (param_n < 1 || param_n > 2) {
return 1;
}
Expand All @@ -127,7 +127,7 @@ int uda::client::idamSyntheticModel(int model, int param_n, float* params, int d
}
break;

case ERROR_MODEL_POISSON:
case ErrorModelType::Poisson:
if (param_n < 0 || param_n > 1) {
return 1;
}
Expand All @@ -138,13 +138,16 @@ int uda::client::idamSyntheticModel(int model, int param_n, float* params, int d
data[i] = data[i] + (float)gsl_ran_poisson(random, (double)data[i]); // Randomly perturb data array
}
break;

default:
break;
}

return 0;
#endif
}

int uda::client::generateIdamSyntheticData(int handle)
int uda::client::generate_synthetic_data(int handle)
{
int err = 0;

Expand All @@ -163,7 +166,7 @@ int uda::client::generateIdamSyntheticData(int handle)

udaGetErrorModel(handle, &model, &param_n, params);

if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) {
if (model <= (int)ErrorModelType::Unknown || model >= (int)ErrorModelType::Undefined) {
return 0; // No valid Model
}

Expand Down Expand Up @@ -280,7 +283,7 @@ int uda::client::generateIdamSyntheticData(int handle)
//--------------------------------------------------------------------------------------------------------------
// Generate Synthetic Data

err = uda::client::idamSyntheticModel(model, param_n, params, udaGetDataNum(handle), data);
err = uda::client::synthetic_model(model, param_n, params, udaGetDataNum(handle), data);

if (err != 0) {
add_error(ErrorType::Code, "generateIdamSyntheticData", err, "Unable to Generate Synthetic Data");
Expand Down Expand Up @@ -395,7 +398,7 @@ int uda::client::generateIdamSyntheticData(int handle)
return 0;
}

int uda::client::generateIdamSyntheticDimData(int handle, int ndim)
int uda::client::generate_synthetic_dim_data(int handle, int ndim)
{
int err = 0;

Expand All @@ -418,7 +421,7 @@ int uda::client::generateIdamSyntheticDimData(int handle, int ndim)

udaGetErrorModel(handle, &model, &param_n, params);

if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) {
if (model <= (int)ErrorModelType::Unknown || model >= (int)ErrorModelType::Undefined) {
return 0; // No valid Model
}

Expand Down Expand Up @@ -536,7 +539,7 @@ int uda::client::generateIdamSyntheticDimData(int handle, int ndim)
//--------------------------------------------------------------------------------------------------------------
// Generate Model Data

err = uda::client::idamSyntheticModel(model, param_n, params, udaGetDimNum(handle, ndim), data);
err = uda::client::synthetic_model(model, param_n, params, udaGetDimNum(handle, ndim), data);

if (err != 0) {
add_error(ErrorType::Code, "generateIdamSyntheticDimData", err,
Expand Down Expand Up @@ -653,7 +656,7 @@ int uda::client::generateIdamSyntheticDimData(int handle, int ndim)
return 0;
}

int uda::client::generateIdamDataError(int handle)
int uda::client::generate_data_error(int handle)
{
int err = 0, asymmetry = 0;

Expand All @@ -672,7 +675,7 @@ int uda::client::generateIdamDataError(int handle)

udaGetErrorModel(handle, &model, &param_n, params);

if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) {
if (model <= (int)ErrorModelType::Unknown || model >= (int)ErrorModelType::Undefined) {
return 0; // No valid Model
}

Expand Down Expand Up @@ -799,7 +802,7 @@ int uda::client::generateIdamDataError(int handle)
//--------------------------------------------------------------------------------------------------------------
// Generate Error Data

err = idamErrorModel(model, param_n, params, udaGetDataNum(handle), data, &asymmetry, (float*)errhi, (float*)errlo);
err = error_model(model, param_n, params, udaGetDataNum(handle), data, &asymmetry, (float*)errhi, (float*)errlo);

if (err != 0) {
free(data);
Expand Down Expand Up @@ -966,7 +969,7 @@ int uda::client::generateIdamDataError(int handle)
return 0;
}

int uda::client::generateIdamDimDataError(int handle, int ndim)
int uda::client::generate_dim_data_error(int handle, int ndim)
{

int err = 0, asymmetry = 0;
Expand All @@ -990,7 +993,7 @@ int uda::client::generateIdamDimDataError(int handle, int ndim)

udaGetErrorModel(handle, &model, &param_n, params);

if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) {
if (model <= (int)ErrorModelType::Unknown || model >= (int)ErrorModelType::Undefined) {
return 0; // No valid Model
}

Expand Down Expand Up @@ -1117,7 +1120,7 @@ int uda::client::generateIdamDimDataError(int handle, int ndim)
//--------------------------------------------------------------------------------------------------------------
// Generate Model Data

err = idamErrorModel(model, param_n, params, udaGetDimNum(handle, ndim), data, &asymmetry, (float*)errhi,
err = error_model(model, param_n, params, udaGetDimNum(handle, ndim), data, &asymmetry, (float*)errhi,
(float*)errlo);

if (err != 0) {
Expand Down
Loading

0 comments on commit 1a0c225

Please sign in to comment.