derekovecs: make sure that all variables are initialized
Fixes sometimes wrong heat visualization.
diff --git a/w2v-server.pl b/w2v-server.pl
index b288580..2605db5 100755
--- a/w2v-server.pl
+++ b/w2v-server.pl
@@ -594,7 +594,7 @@
pars->N = (number? number : 20);
pars->from = 0;
pars->upto = window * 2 -1;
- knn *syn_nbs; // = (knn*) getCollocators(pars);
+ knn *syn_nbs = NULL; // = (knn*) getCollocators(pars);
free(pars);
free(window_sums);
free(target_sums);
@@ -610,14 +610,16 @@
long window_layer_size = size * window * 2;
long a, b, c, d, e, window_offset, target, max_target=0, maxmax_target;
float f, max_f, maxmax_f;
- float *target_sums, worstbest, wpos_sum;
+ float *target_sums=NULL, worstbest, wpos_sum;
collocator *best;
if(M2 == NULL || cc == -1)
return NULL;
a = posix_memalign((void **) &target_sums, 128, pars->cutoff * sizeof(float));
- best = malloc(N * sizeof(collocator));
+ memset(target_sums, 0, pars->cutoff * sizeof(float));
+ best = malloc((N>200?N:200) * sizeof(collocator));
+ memset(best, 0, (N>200?N:200) * sizeof(collocator));
worstbest = MIN_RESP;
for (b = 0; b < pars->cutoff; b++)
@@ -905,7 +907,7 @@
SV *get_neighbours(char *st1, int N, int sort_by, int search_backw, long cutoff, int dedupe, int no_similar_profiles) {
HV *result = newHV();
- float *target_sums, vec[max_size];
+ float *target_sums=NULL, vec[max_size];
long long old_words;
long a, b, c, d, slice;
knn *para_nbs[MAX_THREADS];
@@ -916,9 +918,9 @@
int syn_threads = (M2? window * 2 : 0);
int para_threads = (no_similar_profiles? 0 : num_threads - syn_threads);
- collocator *best;
- posix_memalign((void **) &best, 128, 10 * (N>=100? N : 100) * sizeof(collocator));
- memset(best, 0, 10 * N * sizeof(collocator));
+ collocator *best = NULL;
+ posix_memalign((void **) &best, 128, 10 * (N>=200? N : 200) * sizeof(collocator));
+ memset(best, 0, (N>=200? N : 200) * sizeof(collocator));
if(N>MAX_NEIGHBOURS) N=MAX_NEIGHBOURS;
@@ -933,8 +935,7 @@
slice = cutoff / para_threads;
a = posix_memalign((void **) &target_sums, 128, cutoff * sizeof(float));
- for(a = 0; a < cutoff; a++)
- target_sums[a] = 0;
+ memset(target_sums, 0, cutoff * sizeof(float));
printf("Starting %d threads\n", para_threads);
fflush(stdout);
@@ -1033,13 +1034,14 @@
i++;
}
hv_store(result, "paradigmatic", strlen("paradigmatic"), newRV_noinc((SV*)array), 0);
-
+
for(b=0; b < MAX_NEIGHBOURS; b++) {
best[b].wordi = -1L;
best[b].activation = 0;
best[b].probability = 0;
best[b].position = 0;
best[b].activation_sum = 0;
+ memset(best[b].heat, 0, sizeof(float)*16);
}
float total_activation = 0;
@@ -1064,6 +1066,7 @@
best[b].average = 0.0;
best[b].probability = 0.0;
best[b].cprobability = syn_nbs[0]->best[b].cprobability;
+ memset(best[b].heat, 0, sizeof(float)*16);
}
float best_window_sum[MAX_NEIGHBOURS];
@@ -1077,6 +1080,7 @@
best[found_index].max_activation = 0.0;
best[found_index].average = 0.0;
best[found_index].probability = 0.0;
+ memset(best[found_index].heat, 0, sizeof(float)*16);
best[found_index].cprobability = syn_nbs[a]->best[b].cprobability;
best[found_index].activation_sum = target_sums[syn_nbs[a]->best[b].wordi]; // syn_nbs[a]->best[b].activation_sum;
best[found_index++].wordi = syn_nbs[a]->best[b].wordi;
@@ -1281,5 +1285,5 @@
fprintf(f, "%f\n", M[i*size + j]);
}
fclose(f);
- return(0);
+ return(0);
}