aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGertjan van den Burg <burg@ese.eur.nl>2016-10-06 17:08:57 +0200
committerGertjan van den Burg <burg@ese.eur.nl>2016-10-06 17:08:57 +0200
commit5c58431646f05637d801c671a5f55a11903b37a5 (patch)
treec4c7f6b2d5b3f9234db580b7d56d8a391d137594
parentSwitch to using dsyrk instead of dsyr for speed. (diff)
downloadgensvm-5c58431646f05637d801c671a5f55a11903b37a5.tar.gz
gensvm-5c58431646f05637d801c671a5f55a11903b37a5.zip
Coding style - set all pointers to NULL initially and after free
-rw-r--r--src/gensvm_base.c3
-rw-r--r--src/gensvm_grid.c1
-rw-r--r--src/gensvm_gridsearch.c30
-rw-r--r--src/gensvm_io.c10
-rw-r--r--src/gensvm_kernel.c19
-rw-r--r--src/gensvm_optimize.c6
-rw-r--r--src/gensvm_pred.c4
-rw-r--r--src/gensvm_queue.c1
-rw-r--r--src/gensvm_strutil.c8
-rw-r--r--src/gensvm_task.c1
10 files changed, 58 insertions, 25 deletions
diff --git a/src/gensvm_base.c b/src/gensvm_base.c
index 0f3ac5d..cef0a3c 100644
--- a/src/gensvm_base.c
+++ b/src/gensvm_base.c
@@ -64,6 +64,7 @@ void gensvm_free_data(struct GenData *data)
free(data->y);
free(data->Sigma);
free(data);
+ data = NULL;
}
/**
@@ -193,6 +194,7 @@ void gensvm_free_model(struct GenModel *model)
free(model->data_file);
free(model);
+ model = NULL;
}
/**
@@ -251,6 +253,7 @@ void gensvm_free_work(struct GenWork *work)
free(work->ZV);
free(work->beta);
free(work);
+ work = NULL;
}
/**
diff --git a/src/gensvm_grid.c b/src/gensvm_grid.c
index f258a93..7e235d0 100644
--- a/src/gensvm_grid.c
+++ b/src/gensvm_grid.c
@@ -59,4 +59,5 @@ void gensvm_free_grid(struct GenGrid *grid)
free(grid->train_data_file);
free(grid->test_data_file);
free(grid);
+ grid = NULL;
}
diff --git a/src/gensvm_gridsearch.c b/src/gensvm_gridsearch.c
index deee033..50b0020 100644
--- a/src/gensvm_gridsearch.c
+++ b/src/gensvm_gridsearch.c
@@ -37,7 +37,7 @@ void gensvm_fill_queue(struct GenGrid *grid, struct GenQueue *queue,
{
long i, j, k;
long N, cnt = 0;
- struct GenTask *task;
+ struct GenTask *task = NULL;
queue->i = 0;
N = grid->Np;
@@ -203,7 +203,7 @@ double prctile(double *values, long N, double p)
struct GenQueue *create_top_queue(struct GenQueue *q)
{
long i, k, N = 0;
- double boundary, *perf;
+ double boundary, *perf = NULL;
struct GenQueue *nq = Malloc(struct GenQueue, 1);
// find the 95th percentile of performance
@@ -271,10 +271,16 @@ struct GenQueue *create_top_queue(struct GenQueue *q)
*/
void consistency_repeats(struct GenQueue *q, long repeats, TrainType traintype)
{
- long i, f, r, N, *cv_idx;
- double p, pi, pr, pt, *time, *std, *mean, *perf;
- struct GenQueue *nq;
- struct GenData **train_folds, **test_folds;
+ bool breakout;
+ long i, f, r, N, *cv_idx = NULL;
+ double p, pi, pr, pt,
+ *time = NULL,
+ *std = NULL,
+ *mean = NULL,
+ *perf = NULL;
+ struct GenQueue *nq = NULL;
+ struct GenData **train_folds = NULL,
+ **test_folds = NULL;
struct GenModel *model = gensvm_init_model();
struct GenTask *task = NULL;
clock_t loop_s, loop_e;
@@ -338,7 +344,10 @@ void consistency_repeats(struct GenQueue *q, long repeats, TrainType traintype)
gensvm_free_data(test_folds[f]);
}
free(train_folds);
+ train_folds = NULL;
+
free(test_folds);
+ test_folds = NULL;
}
for (r=0; r<repeats; r++) {
std[i] += pow(matrix_get(perf, repeats, i, r) - mean[i],
@@ -362,7 +371,7 @@ void consistency_repeats(struct GenQueue *q, long repeats, TrainType traintype)
note("ID\tweights\tepsilon\t\tp\t\tkappa\t\tlambda\t\t"
"mean_perf\tstd_perf\ttime_perf\n");
p = 0.0;
- bool breakout = false;
+ breakout = false;
while (breakout == false) {
pi = prctile(mean, N, (100.0-p));
pr = prctile(std, N, p);
@@ -454,6 +463,9 @@ bool kernel_changed(struct GenTask *newtask, struct GenTask *oldtask)
*
* The performance found by cross validation is stored in the GenTask struct.
*
+ * @todo
+ * Make sure folds can't change between tasks
+ *
* @param[in,out] q GenQueue with GenTask instances to run
*/
@@ -559,10 +571,10 @@ double gensvm_cross_validation(struct GenModel *model,
struct GenData **train_folds, struct GenData **test_folds,
int folds, long n_total)
{
- FILE *fid;
+ FILE *fid = NULL;
int f;
- long *predy;
+ long *predy = NULL;
double performance, total_perf = 0;
for (f=0; f<folds; f++) {
diff --git a/src/gensvm_io.c b/src/gensvm_io.c
index b9b8fdd..a574654 100644
--- a/src/gensvm_io.c
+++ b/src/gensvm_io.c
@@ -33,7 +33,7 @@
*/
void gensvm_read_data(struct GenData *dataset, char *data_file)
{
- FILE *fid;
+ FILE *fid = NULL;
bool in_uniq;
long i, j, n, m,
nr = 0,
@@ -159,7 +159,7 @@ void gensvm_read_data(struct GenData *dataset, char *data_file)
void gensvm_read_model(struct GenModel *model, char *model_filename)
{
long i, j, nr = 0;
- FILE *fid;
+ FILE *fid = NULL;
char buffer[MAX_LINE_LENGTH];
char data_filename[MAX_LINE_LENGTH];
double value = 0;
@@ -242,7 +242,7 @@ void gensvm_read_model(struct GenModel *model, char *model_filename)
*/
void gensvm_write_model(struct GenModel *model, char *output_filename)
{
- FILE *fid;
+ FILE *fid = NULL;
long i, j;
char timestr[MAX_LINE_LENGTH];
@@ -306,7 +306,7 @@ void gensvm_write_predictions(struct GenData *data, long *predy,
char *output_filename)
{
long i, j;
- FILE *fid;
+ FILE *fid = NULL;
fid = fopen(output_filename, "w");
if (fid == NULL) {
@@ -347,7 +347,7 @@ void gensvm_time_string(char *buffer)
int diff, hours, minutes;
char timestr[MAX_LINE_LENGTH];
time_t current_time, lt, gt;
- struct tm *lclt;
+ struct tm *lclt = NULL;
// get current time (in epoch)
current_time = time(NULL);
diff --git a/src/gensvm_kernel.c b/src/gensvm_kernel.c
index 7ca58da..97328d2 100644
--- a/src/gensvm_kernel.c
+++ b/src/gensvm_kernel.c
@@ -46,13 +46,18 @@ void gensvm_kernel_preprocess(struct GenModel *model, struct GenData *data)
gensvm_make_trainfactor(data, P, Sigma, r);
// Set Sigma to data->Sigma (need it again for prediction)
- if (data->Sigma != NULL)
+ if (data->Sigma != NULL) {
free(data->Sigma);
+ data->Sigma = NULL;
+ }
data->Sigma = Sigma;
// write kernel params to data
data->kerneltype = model->kerneltype;
+
free(data->kernelparam);
+ data->kernelparam = NULL;
+
switch (model->kerneltype) {
case K_LINEAR:
break;
@@ -99,7 +104,8 @@ void gensvm_make_kernel(struct GenModel *model, struct GenData *data,
long i, j;
long n = data->n;
double value;
- double *x1, *x2;
+ double *x1 = NULL,
+ *x2 = NULL;
for (i=0; i<n; i++) {
for (j=i; j<n; j++) {
@@ -134,9 +140,11 @@ void gensvm_make_kernel(struct GenModel *model, struct GenData *data,
*/
long gensvm_make_eigen(double *K, long n, double **P, double **Sigma)
{
- int M, status, LWORK, *IWORK, *IFAIL;
+ int M, status, LWORK,
+ *IWORK = NULL,
+ *IFAIL = NULL;
long i, j, num_eigen, cutoff_idx;
- double max_eigen, abstol, *WORK;
+ double max_eigen, abstol, *WORK = NULL;
double *tempSigma = Malloc(double, n);
double *tempP = Malloc(double, n*n);
@@ -210,7 +218,8 @@ void gensvm_make_crosskernel(struct GenModel *model,
long n_test = data_test->n;
long m = data_test->m;
double value;
- double *x1, *x2;
+ double *x1 = NULL,
+ *x2 = NULL;
*K2 = Calloc(double, n_test*n_train);
diff --git a/src/gensvm_optimize.c b/src/gensvm_optimize.c
index 184c45f..60a5682 100644
--- a/src/gensvm_optimize.c
+++ b/src/gensvm_optimize.c
@@ -362,7 +362,7 @@ double gensvm_get_alpha_beta(struct GenModel *model, struct GenData *data,
K = model->K;
double omega, a, b_aq = 0.0,
alpha = 0.0;
- double *uu_row;
+ double *uu_row = NULL;
const double in = 1.0/((double) model->n);
simple = gensvm_majorize_is_simple(model, data, i);
@@ -528,7 +528,9 @@ void gensvm_get_update(struct GenModel *model, struct GenData *data,
err("[GenSVM Warning]: Received nonzero "
"status from dsysv: %i\n", status);
free(WORK);
+ WORK = NULL;
free(IPIV);
+ IPIV = NULL;
}
// the solution is now stored in ZBc, in column-major order. Here we
@@ -634,7 +636,7 @@ void gensvm_calculate_errors(struct GenModel *model, struct GenData *data,
double *ZV)
{
long i, j;
- double q, *uu_row;
+ double q, *uu_row = NULL;
long n = model->n;
long m = model->m;
diff --git a/src/gensvm_pred.c b/src/gensvm_pred.c
index 43b27cc..1feb14a 100644
--- a/src/gensvm_pred.c
+++ b/src/gensvm_pred.c
@@ -31,7 +31,9 @@ void gensvm_predict_labels(struct GenData *testdata, struct GenModel *model,
long *predy)
{
long i, j, k, n, m, K, label;
- double norm, min_dist, *S, *ZV;
+ double norm, min_dist,
+ *S = NULL,
+ *ZV = NULL;
n = testdata->n;
m = testdata->r;
diff --git a/src/gensvm_queue.c b/src/gensvm_queue.c
index bbf57b2..1994a54 100644
--- a/src/gensvm_queue.c
+++ b/src/gensvm_queue.c
@@ -46,6 +46,7 @@ void gensvm_free_queue(struct GenQueue *q)
}
free(q->tasks);
free(q);
+ q = NULL;
}
/**
diff --git a/src/gensvm_strutil.c b/src/gensvm_strutil.c
index 9762e52..a05f320 100644
--- a/src/gensvm_strutil.c
+++ b/src/gensvm_strutil.c
@@ -75,7 +75,7 @@ char *get_line(FILE *fid, char *filename, char *buffer)
* @brief Read a double from file following a format
*
* @details
- * This function reads a double value from a file. If no value can be found, a
+ * This function reads a double value from a file. If no value can be found, a
* warning is printed to stderr, and NAN is returned.
*
* @param[in] fid File opened for reading
@@ -135,7 +135,8 @@ long all_doubles_str(char *buffer, long offset, double *all_doubles)
{
double value;
long i = 0;
- char *start, *end;
+ char *start = NULL,
+ *end = NULL;
start = buffer + offset;
while (true) {
@@ -170,7 +171,8 @@ long all_longs_str(char *buffer, long offset, long *all_longs)
{
long value;
long i = 0;
- char *start, *end;
+ char *start = NULL,
+ *end = NULL;
start = buffer + offset;
while (true) {
diff --git a/src/gensvm_task.c b/src/gensvm_task.c
index 587c4c4..eab7d79 100644
--- a/src/gensvm_task.c
+++ b/src/gensvm_task.c
@@ -52,4 +52,5 @@ void gensvm_free_task(struct GenTask *t)
{
free(t->kernelparam);
free(t);
+ t = NULL;
}