aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGertjan van den Burg <burg@ese.eur.nl>2016-12-07 12:52:46 +0100
committerGertjan van den Burg <burg@ese.eur.nl>2016-12-07 12:52:46 +0100
commitf8979e27e3081b8115f1fe44e318ec6d80bd4f5d (patch)
tree2001f489efb3ccb9fe1f77abc8018cba4c17291b /src
parentswitch some integer variables to long for cross platform size guarantees (diff)
downloadgensvm-f8979e27e3081b8115f1fe44e318ec6d80bd4f5d.tar.gz
gensvm-f8979e27e3081b8115f1fe44e318ec6d80bd4f5d.zip
add ifndef and GENSVM_ before defines
Diffstat (limited to 'src')
-rw-r--r--src/GenSVMgrid.c30
-rw-r--r--src/GenSVMtraintest.c2
-rw-r--r--src/gensvm_gridsearch.c2
-rw-r--r--src/gensvm_io.c18
-rw-r--r--src/gensvm_optimize.c14
-rw-r--r--src/gensvm_strutil.c8
-rw-r--r--src/gensvm_update.c16
7 files changed, 48 insertions, 42 deletions
diff --git a/src/GenSVMgrid.c b/src/GenSVMgrid.c
index 14b7457..9e3586d 100644
--- a/src/GenSVMgrid.c
+++ b/src/GenSVMgrid.c
@@ -59,7 +59,7 @@ void read_grid_from_file(char *input_filename, struct GenGrid *grid);
* @brief Help function
*
* @details
- * Print help for this program and exit. Note that VERSION is provided by the
+ * Print help for this program and exit. Note that VERSION is provided by the
* Makefile.
*
* @param[in] argv command line arguments
@@ -96,7 +96,7 @@ void exit_with_help(char **argv)
*/
int main(int argc, char **argv)
{
- char input_filename[MAX_LINE_LENGTH];
+ char input_filename[GENSVM_MAX_LINE_LENGTH];
struct GenGrid *grid = gensvm_init_grid();
struct GenData *train_data = gensvm_init_data();
@@ -189,10 +189,10 @@ void parse_command_line(int argc, char **argv, char *input_filename)
* @brief Parse the kernel string from the training file
*
* @details
- * This is a utility function for the read_grid_from_file() function, to keep
- * the main code a bit shorter. It reads the line from the given buffer and
+ * This is a utility function for the read_grid_from_file() function, to keep
+ * the main code a bit shorter. It reads the line from the given buffer and
* returns the corresponding KernelType.
- *
+ *
* @param[in] kernel_line line from the file with the kernel
* specification
* @return the corresponding kerneltype
@@ -233,11 +233,11 @@ void read_grid_from_file(char *input_filename, struct GenGrid *grid)
{
long i, nr = 0;
FILE *fid;
- char buffer[MAX_LINE_LENGTH];
- char train_filename[MAX_LINE_LENGTH];
- char test_filename[MAX_LINE_LENGTH];
- double *params = Calloc(double, MAX_LINE_LENGTH);
- long *lparams = Calloc(long, MAX_LINE_LENGTH);
+ char buffer[GENSVM_MAX_LINE_LENGTH];
+ char train_filename[GENSVM_MAX_LINE_LENGTH];
+ char test_filename[GENSVM_MAX_LINE_LENGTH];
+ double *params = Calloc(double, GENSVM_MAX_LINE_LENGTH);
+ long *lparams = Calloc(long, GENSVM_MAX_LINE_LENGTH);
fid = fopen(input_filename, "r");
if (fid == NULL) {
@@ -246,18 +246,18 @@ void read_grid_from_file(char *input_filename, struct GenGrid *grid)
exit(1);
}
grid->traintype = CV;
- while ( fgets(buffer, MAX_LINE_LENGTH, fid) != NULL ) {
- Memset(params, double, MAX_LINE_LENGTH);
- Memset(lparams, long, MAX_LINE_LENGTH);
+ while ( fgets(buffer, GENSVM_MAX_LINE_LENGTH, fid) != NULL ) {
+ Memset(params, double, GENSVM_MAX_LINE_LENGTH);
+ Memset(lparams, long, GENSVM_MAX_LINE_LENGTH);
if (str_startswith(buffer, "train:")) {
sscanf(buffer, "train: %s\n", train_filename);
grid->train_data_file = Calloc(char,
- MAX_LINE_LENGTH);
+ GENSVM_MAX_LINE_LENGTH);
strcpy(grid->train_data_file, train_filename);
} else if (str_startswith(buffer, "test:")) {
sscanf(buffer, "test: %s\n", test_filename);
grid->test_data_file = Calloc(char,
- MAX_LINE_LENGTH);
+ GENSVM_MAX_LINE_LENGTH);
strcpy(grid->test_data_file, test_filename);
grid->traintype = TT;
} else if (str_startswith(buffer, "p:")) {
diff --git a/src/GenSVMtraintest.c b/src/GenSVMtraintest.c
index 4f4cabb..40c4321 100644
--- a/src/GenSVMtraintest.c
+++ b/src/GenSVMtraintest.c
@@ -132,7 +132,7 @@ int main(int argc, char **argv)
// read data from files
gensvm_read_data(traindata, training_inputfile);
- model->data_file = Calloc(char, MAX_LINE_LENGTH);
+ model->data_file = Calloc(char, GENSVM_MAX_LINE_LENGTH);
strcpy(model->data_file, training_inputfile);
// seed the random number generator
diff --git a/src/gensvm_gridsearch.c b/src/gensvm_gridsearch.c
index 9c30d3a..d5b1247 100644
--- a/src/gensvm_gridsearch.c
+++ b/src/gensvm_gridsearch.c
@@ -360,7 +360,7 @@ void gensvm_train_queue(struct GenQueue *q)
void gensvm_gridsearch_progress(struct GenTask *task, long N, double perf,
double duration, double current_max)
{
- char buffer[MAX_LINE_LENGTH];
+ char buffer[GENSVM_MAX_LINE_LENGTH];
sprintf(buffer, "(%03li/%03li)\t", task->ID+1, N);
if (task->kerneltype == K_POLY)
sprintf(buffer + strlen(buffer), "d = %2.2f\t",
diff --git a/src/gensvm_io.c b/src/gensvm_io.c
index e77d647..78838b1 100644
--- a/src/gensvm_io.c
+++ b/src/gensvm_io.c
@@ -61,7 +61,7 @@ void gensvm_read_data(struct GenData *dataset, char *data_file)
double value;
long *uniq_y = NULL;
- char buf[MAX_LINE_LENGTH];
+ char buf[GENSVM_MAX_LINE_LENGTH];
if ((fid = fopen(data_file, "r")) == NULL) {
// LCOV_EXCL_START
@@ -84,7 +84,7 @@ void gensvm_read_data(struct GenData *dataset, char *data_file)
matrix_set(dataset->RAW, m+1, 0, j, value);
}
- if (fgets(buf, MAX_LINE_LENGTH, fid) == NULL) {
+ if (fgets(buf, GENSVM_MAX_LINE_LENGTH, fid) == NULL) {
// LCOV_EXCL_START
err("[GenSVM Error]: No label found on first line.\n");
exit(EXIT_FAILURE);
@@ -187,8 +187,8 @@ void gensvm_read_model(struct GenModel *model, char *model_filename)
{
long i, j, nr = 0;
FILE *fid = NULL;
- char buffer[MAX_LINE_LENGTH];
- char data_filename[MAX_LINE_LENGTH];
+ char buffer[GENSVM_MAX_LINE_LENGTH];
+ char data_filename[GENSVM_MAX_LINE_LENGTH];
double value = 0;
fid = fopen(model_filename, "r");
@@ -216,7 +216,7 @@ void gensvm_read_model(struct GenModel *model, char *model_filename)
next_line(fid, model_filename);
// read filename of data file
- if (fgets(buffer, MAX_LINE_LENGTH, fid) == NULL) {
+ if (fgets(buffer, GENSVM_MAX_LINE_LENGTH, fid) == NULL) {
// LCOV_EXCL_START
err("[GenSVM Error]: Error reading from model file %s\n",
model_filename);
@@ -224,7 +224,7 @@ void gensvm_read_model(struct GenModel *model, char *model_filename)
// LCOV_EXCL_STOP
}
sscanf(buffer, "filename = %s\n", data_filename);
- model->data_file = Calloc(char, MAX_LINE_LENGTH);
+ model->data_file = Calloc(char, GENSVM_MAX_LINE_LENGTH);
strcpy(model->data_file, data_filename);
// read all data variables
@@ -271,7 +271,7 @@ void gensvm_write_model(struct GenModel *model, char *output_filename)
{
FILE *fid = NULL;
long i, j;
- char timestr[MAX_LINE_LENGTH];
+ char timestr[GENSVM_MAX_LINE_LENGTH];
// open output file
fid = fopen(output_filename, "w");
@@ -372,7 +372,7 @@ void gensvm_write_predictions(struct GenData *data, long *predy,
void gensvm_time_string(char *buffer)
{
int diff, hours, minutes;
- char timestr[MAX_LINE_LENGTH];
+ char timestr[GENSVM_MAX_LINE_LENGTH];
time_t current_time, lt, gt;
struct tm *lclt = NULL;
@@ -387,7 +387,7 @@ void gensvm_time_string(char *buffer)
// convert time to local time and create a string
lclt = localtime(&current_time);
- strftime(timestr, MAX_LINE_LENGTH, "%c", lclt);
+ strftime(timestr, GENSVM_MAX_LINE_LENGTH, "%c", lclt);
if (timestr == NULL) {
err("[GenSVM Error]: Failed to convert time to string.\n");
return;
diff --git a/src/gensvm_optimize.c b/src/gensvm_optimize.c
index a7172be..95f9df2 100644
--- a/src/gensvm_optimize.c
+++ b/src/gensvm_optimize.c
@@ -33,12 +33,16 @@
/**
* Maximum number of iterations of the algorithm.
*/
-#define MAX_ITER 1000000000
+#ifndef GENSVM_MAX_ITER
+ #define GENSVM_MAX_ITER 1000000000
+#endif
/**
* Iteration frequency with which to print to stdout
*/
-#define PRINT_ITER 100
+#ifndef GENSVM_PRINT_ITER
+ #define GENSVM_PRINT_ITER 100
+#endif
/**
* @brief The main training loop for GenSVM
@@ -90,7 +94,7 @@ void gensvm_optimize(struct GenModel *model, struct GenData *data)
Lbar = L + 2.0*model->epsilon*L;
// run main loop
- while ((it < MAX_ITER) && (Lbar - L)/L > model->epsilon)
+ while ((it < GENSVM_MAX_ITER) && (Lbar - L)/L > model->epsilon)
{
// ensures V contains newest V and Vbar contains V from
// previous
@@ -101,7 +105,7 @@ void gensvm_optimize(struct GenModel *model, struct GenData *data)
Lbar = L;
L = gensvm_get_loss(model, data, work);
- if (it%PRINT_ITER == 0)
+ if (it % GENSVM_PRINT_ITER == 0)
note("iter = %li, L = %15.16f, Lbar = %15.16f, "
"reldiff = %15.16f\n", it, L, Lbar, (Lbar - L)/L);
it++;
@@ -111,7 +115,7 @@ void gensvm_optimize(struct GenModel *model, struct GenData *data)
if (L > Lbar)
err("[GenSVM Warning]: Negative step occurred in "
"majorization.\n");
- if (it >= MAX_ITER)
+ if (it >= GENSVM_MAX_ITER)
err("[GenSVM Warning]: maximum number of iterations "
"reached.\n");
diff --git a/src/gensvm_strutil.c b/src/gensvm_strutil.c
index c18f2d4..f6bb8f7 100644
--- a/src/gensvm_strutil.c
+++ b/src/gensvm_strutil.c
@@ -70,7 +70,7 @@ bool str_endswith(const char *str, const char *suf)
*/
void next_line(FILE *fid, char *filename)
{
- char buffer[MAX_LINE_LENGTH];
+ char buffer[GENSVM_MAX_LINE_LENGTH];
get_line(fid, filename, buffer);
}
@@ -83,7 +83,7 @@ void next_line(FILE *fid, char *filename)
*/
char *get_line(FILE *fid, char *filename, char *buffer)
{
- char *retval = fgets(buffer, MAX_LINE_LENGTH, fid);
+ char *retval = fgets(buffer, GENSVM_MAX_LINE_LENGTH, fid);
if (retval == NULL) {
err("[GenSVM Error]: Error reading from file %s\n", filename);
}
@@ -104,7 +104,7 @@ char *get_line(FILE *fid, char *filename, char *buffer)
*/
double get_fmt_double(FILE *fid, char *filename, const char *fmt)
{
- char buffer[MAX_LINE_LENGTH];
+ char buffer[GENSVM_MAX_LINE_LENGTH];
double value = NAN;
int retval;
@@ -125,7 +125,7 @@ double get_fmt_double(FILE *fid, char *filename, const char *fmt)
*/
long get_fmt_long(FILE *fid, char *filename, const char *fmt)
{
- char buffer[MAX_LINE_LENGTH];
+ char buffer[GENSVM_MAX_LINE_LENGTH];
long value = 0;
int retval;
diff --git a/src/gensvm_update.c b/src/gensvm_update.c
index f81d224..aca586f 100644
--- a/src/gensvm_update.c
+++ b/src/gensvm_update.c
@@ -30,7 +30,9 @@
* Number of rows in a single block for the ZAZ calculation in
* gensvm_get_ZAZ_ZB_sparse().
*/
-#define BLOCK_SIZE 512
+#ifndef GENSVM_BLOCK_SIZE
+ #define GENSVM_BLOCK_SIZE 512
+#endif
/**
* @brief Calculate the value of omega for a single instance
@@ -461,8 +463,8 @@ void gensvm_get_ZAZ_ZB_dense(struct GenModel *model, struct GenData *data,
* daxpy call.
*
* This function calculates the matrix product Z'*A*Z in separate blocks,
- * based on the number of rows defined in the BLOCK_SIZE variable. This is
- * done to improve numerical precision for very large datasets. Due to
+ * based on the number of rows defined in the GENSVM_BLOCK_SIZE variable. This
+ * is done to improve numerical precision for very large datasets. Due to
* rounding errors, precision can become an issue for these large datasets,
* when separate blocks are used and added to the result separately, this can
* be alleviated a little bit. See also: http://stackoverflow.com/q/40286989
@@ -495,13 +497,13 @@ void gensvm_get_ZAZ_ZB_sparse(struct GenModel *model, struct GenData *data,
// rounding errors, which increases precision, and in turn helps
// convergion of the IM algorithm.
// see also: http://stackoverflow.com/q/40286989/
- n_blocks = floor(n_row / BLOCK_SIZE);
- rem_size = n_row % BLOCK_SIZE;
+ n_blocks = floor(n_row / GENSVM_BLOCK_SIZE);
+ rem_size = n_row % GENSVM_BLOCK_SIZE;
for (b=0; b<=n_blocks; b++) {
- blk_start = b * BLOCK_SIZE;
+ blk_start = b * GENSVM_BLOCK_SIZE;
blk_end = blk_start;
- blk_end += (b == n_blocks) ? rem_size : BLOCK_SIZE;
+ blk_end += (b == n_blocks) ? rem_size : GENSVM_BLOCK_SIZE;
Memset(work->tmpZAZ, double, n_col*n_col);
for (i=blk_start; i<blk_end; i++) {