Fix some compiler warnings
diff --git a/derekovecs-server.c b/derekovecs-server.c
index 3791ade..5b8915f 100644
--- a/derekovecs-server.c
+++ b/derekovecs-server.c
@@ -129,7 +129,7 @@
int init_net(char *file_name, char *net_name, int latin, int do_open_cdb) {
FILE *f, *binvecs, *binwords;
int binwords_fd, binvecs_fd, net_fd, i;
- long long a, b, c, d, cn;
+ long long a, b;
float len;
double val;
@@ -264,10 +264,8 @@
}
long mergeVectors(char *file_name) {
- FILE *f, *binvecs, *binwords;
- int binwords_fd, binvecs_fd, net_fd, i;
- long long a, b, c, d, cn;
- float len;
+ FILE *f;
+ int binwords_fd, binvecs_fd;
float *merge_vecs;
char *merge_vocab;
/* long long merge_words, merge_size; */
@@ -284,7 +282,7 @@
f = fopen(file_name, "rb");
if (f == NULL) {
printf("Input file %s not found\n", file_name);
- exit - 1;
+ exit(-1);
}
fscanf(f, "%lld", &merge_words);
fscanf(f, "%lld", &merge_size);
@@ -329,9 +327,9 @@
garbage = malloc(words);
memset(garbage, 0, words);
for (i = 0; i < words; i++) {
- w = vocab + i * max_w;
+ w = (unsigned char *) vocab + i * max_w;
previous = 0;
- if (strncmp("quot", w, 4) == 0) {
+ if (strncmp("quot", (const char *)w, 4) == 0) {
garbage[i] = 1;
// printf("Gargabe: %s\n", vocab + i * max_w);
} else {
@@ -353,20 +351,20 @@
knn *simpleGetCollocators(int word, int number, long cutoff, int *result) {
knnpars *pars = calloc(sizeof(knnpars), 1);
- float *target_sums;
- float *window_sums = malloc(sizeof(float) * (window + 1) * 2);
+ float *target_sums = NULL;
+ float *my_window_sums = malloc(sizeof(float) * (window + 1) * 2);
pars->cutoff = (cutoff ? cutoff : 300000);
- long a = posix_memalign((void **)&target_sums, 128, pars->cutoff * sizeof(float));
+ long a;
for (a = 0; a < cutoff; a++)
target_sums[a] = 0;
pars->target_sums = target_sums;
- pars->window_sums = window_sums;
+ pars->window_sums = my_window_sums;
pars->N = (number ? number : 20);
pars->from = 0;
pars->upto = window * 2 - 1;
knn *syn_nbs = NULL; // = (knn*) getCollocators(pars);
free(pars);
- free(window_sums);
+ free(my_window_sums);
free(target_sums);
return syn_nbs;
}
@@ -378,7 +376,7 @@
int cc = pars->wl->wordi[0];
knn *nbs = NULL;
long window_layer_size = size * window * 2;
- long a, b, c, d, e, window_offset, target, max_target = 0, maxmax_target;
+ long a, b, c, d, window_offset, target, max_target = 0, maxmax_target;
float f, max_f, maxmax_f;
float *target_sums = NULL, worstbest, wpos_sum;
collocator *best;
@@ -444,7 +442,7 @@
worstbest = best[N - 1].activation;
}
}
- printf("%d %.2f\n", max_target, max_f);
+ printf("%ld %.2f\n", max_target, max_f);
printf("%s (%.2f) ", &vocab[max_target * max_w], max_f);
if (max_f > maxmax_f) {
maxmax_f = max_f;
@@ -464,7 +462,7 @@
free(target_sums);
for (b = 0; b < N && best[b].wordi >= 0; b++)
;
- ; // THIS LOOP IS NEEDED (b...)
+ // THIS LOOP IS NEEDED (b...)
// printf("%d: best syn: %s %.2f %.5f\n", b, &vocab[best[b].wordi*max_w], best[b].activation, best[b].probability);
// printf("\n");
nbs = malloc(sizeof(knn));
@@ -483,12 +481,12 @@
}
if (hidden >= size) {
- fprintf(stderr, "hidden: %d - assert: hidden < %d failed.\n", hidden, size);
+ fprintf(stderr, "hidden: %d - assert: hidden < %lld failed.\n", hidden, size);
exit(-1);
}
if (target >= words) {
- fprintf(stderr, "target: %ld - assert: target < %ld failed.\n", target, words);
+ fprintf(stderr, "target: %ld - assert: target < %lld failed.\n", target, words);
exit(-1);
}
@@ -536,7 +534,7 @@
}
buffer[strlen(buffer) - 1] = ']';
strcat(buffer, "\n");
- printf(buffer);
+ printf("%s", buffer);
return (strdup(buffer));
}
@@ -547,9 +545,8 @@
wordlist *getTargetWords(char *st1, int search_backw) {
wordlist *wl = malloc(sizeof(wordlist));
- char st[100][max_size], sep[100];
+ char st[100][max_size];
long a, b = 0, c = 0, cn = 0;
- int unmerged;
while (1) {
st[cn][b] = st1[c];
@@ -558,7 +555,6 @@
st[cn][b] = 0;
if (st1[c] == 0) break;
if (st1[c] == ' ' /*|| st1[c] == '-'*/) {
- sep[cn++] = st1[c];
b = 0;
c++;
}
@@ -601,10 +597,8 @@
char *getBiggestMergedDifferences() {
static char *result = NULL;
- float dist, len, vec[max_size];
- long long a, b, c, d, cn, *bi;
- char ch;
- knn *nbs = NULL;
+ float dist;
+ long long a, c;
int N = 1000;
if (merged_end == 0)
@@ -624,7 +618,6 @@
for (c = 0; c < 500000; c++) {
if (garbage && garbage[c]) continue;
- a = 0;
dist = 0;
for (a = 0; a < size; a++) dist += M[a + c * size] * M[a + (c + merged_end) * size];
if (dist < worstbest) {
@@ -645,7 +638,7 @@
*p++ = '[';
*p = 0;
for (a = 0; a < N; a++) {
- p += sprintf(p, "{\"rank\":%d,\"word\":\"%s\",\"dist\":%.3f},", a, &vocab[best[a].wordi * max_w], 1 - best[a].activation);
+ p += sprintf(p, "{\"rank\":%lld,\"word\":\"%s\",\"dist\":%.3f},", a, &vocab[best[a].wordi * max_w], 1 - best[a].activation);
}
*--p = ']';
return (result);
@@ -675,14 +668,12 @@
void *_get_neighbours(void *arg) {
knnpars *pars = arg;
- char *st1 = pars->token;
int N = pars->N;
long from = pars->from;
unsigned long upto = pars->upto;
- char file_name[max_size], st[100][max_size], *sep;
+ char *sep;
float dist, len, vec[max_size];
- long long a, b, c, d, cn, *bi;
- char ch;
+ long long a, b, c, cn, *bi;
knn *nbs = NULL;
wordlist *wl = pars->wl;
@@ -696,9 +687,7 @@
cn = wl->length;
sep = wl->sep;
b = bi[0];
- c = 0;
if (b == -1) {
- N = 0;
goto end;
}
for (a = 0; a < size; a++) vec[a] = 0;
@@ -753,9 +742,8 @@
char *getPosWiseW2VCollocatorsAsTsv(char *word, long maxPerPos, long cutoff, float threshold) {
HV *result = newHV();
- float *target_sums = NULL, vec[max_size];
- long long old_words;
- long a, b, c, d;
+ float *target_sums = NULL;
+ long a, b;
knn *para_nbs[MAX_THREADS];
knn *syn_nbs[MAX_THREADS];
knnpars pars[MAX_THREADS];
@@ -808,8 +796,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 = NULL, vec[max_size];
- long long old_words;
+ float *target_sums = NULL;
long a, b, c, d, slice;
knn *para_nbs[MAX_THREADS];
knn *syn_nbs[MAX_THREADS];
@@ -832,7 +819,6 @@
if (wl == NULL || wl->length < 1)
goto end;
- old_words = cutoff;
slice = cutoff / para_threads;
a = posix_memalign((void **)&target_sums, 128, cutoff * sizeof(float));
@@ -881,7 +867,7 @@
qsort(best, N * para_threads, sizeof(collocator), cmp_activation);
long long chosen[MAX_NEIGHBOURS];
- printf("N: %ld\n", N);
+ printf("N: %d\n", N);
AV *array = newAV();
int i, j;
@@ -953,7 +939,7 @@
for (a = 0; a <= syn_threads; a++) {
if (a == window) continue;
total_activation += window_sums[a];
- printf("window pos: %d, sum: %f\n", a, window_sums[a]);
+ printf("window pos: %ld, sum: %f\n", a, window_sums[a]);
}
printf("syn threads joint\n");
fflush(stdout);
@@ -970,7 +956,7 @@
}
float best_window_sum[MAX_NEIGHBOURS];
- int found_index = 0, i = 0, j, w;
+ int found_index = 0, i = 0, w;
for (a = 0; a < syn_threads; a++) {
for (b = 0; b < syn_nbs[a]->length; b++) {
for (i = 0; i < found_index; i++)
@@ -1143,7 +1129,6 @@
hv_store(result, "syntagmatic", strlen("syntagmatic"), newRV_noinc((SV *)array), 0);
}
end:
- // words = old_words; // why was this here?
free(best);
return newRV_noinc((SV *)result);
}