File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -204,7 +204,7 @@ namespace hnswlib {
204
204
};
205
205
206
206
static int
207
- L2SqrI (const void *__restrict pVect1, const void *__restrict pVect2, const void *__restrict qty_ptr) {
207
+ L2SqrI4x (const void *__restrict pVect1, const void *__restrict pVect2, const void *__restrict qty_ptr) {
208
208
209
209
size_t qty = *((size_t *) qty_ptr);
210
210
int res = 0 ;
@@ -226,12 +226,23 @@ namespace hnswlib {
226
226
res += ((*a) - (*b)) * ((*a) - (*b));
227
227
a++;
228
228
b++;
229
+ }
230
+ return (res);
231
+ }
229
232
233
+ static int L2SqrI (const void * __restrict pVect1, const void * __restrict pVect2, const void * __restrict qty_ptr) {
234
+ size_t qty = *((size_t *)qty_ptr);
235
+ int res = 0 ;
236
+ unsigned char * a = (unsigned char *)pVect1;
237
+ unsigned char * b = (unsigned char *)pVect2;
230
238
239
+ for (size_t i = 0 ; i < qty; i++)
240
+ {
241
+ res += ((*a) - (*b)) * ((*a) - (*b));
242
+ a++;
243
+ b++;
231
244
}
232
-
233
245
return (res);
234
-
235
246
}
236
247
237
248
class L2SpaceI : public SpaceInterface <int > {
@@ -241,7 +252,12 @@ namespace hnswlib {
241
252
size_t dim_;
242
253
public:
243
254
L2SpaceI (size_t dim) {
244
- fstdistfunc_ = L2SqrI;
255
+ if (dim % 4 == 0 ) {
256
+ fstdistfunc_ = L2SqrI4x;
257
+ }
258
+ else {
259
+ fstdistfunc_ = L2SqrI;
260
+ }
245
261
dim_ = dim;
246
262
data_size_ = dim * sizeof (unsigned char );
247
263
}
You can’t perform that action at this time.
0 commit comments