forked from gtolias/hqe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scorc.c
executable file
·112 lines (89 loc) · 2.18 KB
/
scorc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include "scorc.h"
#ifdef _OPENMP
#include <omp.h>
#endif
/* Threaded versions, if OpenMP is available */
#ifdef _OPENMP
float * scor_compute (const int * qids, const int * dbids, const float * w, int n, int m, int burst)
{
int i, k;
float wk = 0.0;
int j = 0;
float * scor = (float *) calloc (m, sizeof (float));
/* use of burstiness normalization */
if (burst)
for (i = 0; i < n; i++) {
/* consecutive elements of the same query feature and database image */
if (dbids[i] == dbids[i+1] && qids[i] == qids[i+1] && i < n-1) {
j++;
wk += w[i];
}
/* end of consecutive elements, update scores */
else if (j > 0) {
wk += w[i];
scor[dbids[i]-1] += wk / sqrt((float)j+1);
wk = 0.0;
j = 0;
}
else
scor[dbids[i]-1] += w[i];
}
/* no burstiness normalization */
else
for (i = 0; i < n; i++)
scor[dbids[i]-1] += w[i];
return scor;
}
int * nc_compute (const int * dbids, int n, int m)
{
int i, k;
int * nc = (int *) calloc (m, sizeof (int));
for (i = 0; i < n; i++)
nc[dbids[i]-1] ++;
return nc;
}
#else /* no OpenMP */
float * scor_compute (const int * qids, const int * dbids, const float * w, int n, int m, int burst)
{
int i, k;
float wk = 0.0;
int j = 0;
float * scor = (float *) calloc (m, sizeof (float));
/* use of burstiness normalization */
if (burst)
for (i = 0; i < n; i++) {
/* consecutive elements of the same query feature and database image */
if (dbids[i] == dbids[i+1] && qids[i] == qids[i+1] && i < n-1) {
j++;
wk += w[i];
}
/* end of consecutive elements, update scores */
else if (j > 0) {
wk += w[i];
scor[dbids[i]-1] += wk / sqrt((float)j+1);
wk = 0.0;
j = 0;
}
else
scor[dbids[i]-1] += w[i];
}
/* no burstiness normalization */
else
for (i = 0; i < n; i++)
scor[dbids[i]-1] += w[i];
return scor;
}
int * nc_compute (const int * dbids, int n, int m)
{
int i, k;
int * nc = (int *) calloc (m, sizeof (int));
for (i = 0; i < n; i++)
nc[dbids[i]-1] ++;
return nc;
}
#endif /* OpenMP */