hnswlib 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +2 -2
- data/ext/hnswlib/hnswlibext.hpp +544 -518
- data/ext/hnswlib/src/space_ip.h +61 -23
- data/lib/hnswlib/version.rb +2 -2
- metadata +3 -3
data/ext/hnswlib/src/space_ip.h
CHANGED
@@ -10,10 +10,15 @@ namespace hnswlib {
|
|
10
10
|
for (unsigned i = 0; i < qty; i++) {
|
11
11
|
res += ((float *) pVect1)[i] * ((float *) pVect2)[i];
|
12
12
|
}
|
13
|
-
return
|
13
|
+
return res;
|
14
14
|
|
15
15
|
}
|
16
16
|
|
17
|
+
static float
|
18
|
+
InnerProductDistance(const void *pVect1, const void *pVect2, const void *qty_ptr) {
|
19
|
+
return 1.0f - InnerProduct(pVect1, pVect2, qty_ptr);
|
20
|
+
}
|
21
|
+
|
17
22
|
#if defined(USE_AVX)
|
18
23
|
|
19
24
|
// Favor using AVX if available.
|
@@ -61,8 +66,13 @@ namespace hnswlib {
|
|
61
66
|
|
62
67
|
_mm_store_ps(TmpRes, sum_prod);
|
63
68
|
float sum = TmpRes[0] + TmpRes[1] + TmpRes[2] + TmpRes[3];;
|
64
|
-
return
|
65
|
-
}
|
69
|
+
return sum;
|
70
|
+
}
|
71
|
+
|
72
|
+
static float
|
73
|
+
InnerProductDistanceSIMD4ExtAVX(const void *pVect1v, const void *pVect2v, const void *qty_ptr) {
|
74
|
+
return 1.0f - InnerProductSIMD4ExtAVX(pVect1v, pVect2v, qty_ptr);
|
75
|
+
}
|
66
76
|
|
67
77
|
#endif
|
68
78
|
|
@@ -121,7 +131,12 @@ namespace hnswlib {
|
|
121
131
|
_mm_store_ps(TmpRes, sum_prod);
|
122
132
|
float sum = TmpRes[0] + TmpRes[1] + TmpRes[2] + TmpRes[3];
|
123
133
|
|
124
|
-
return
|
134
|
+
return sum;
|
135
|
+
}
|
136
|
+
|
137
|
+
static float
|
138
|
+
InnerProductDistanceSIMD4ExtSSE(const void *pVect1v, const void *pVect2v, const void *qty_ptr) {
|
139
|
+
return 1.0f - InnerProductSIMD4ExtSSE(pVect1v, pVect2v, qty_ptr);
|
125
140
|
}
|
126
141
|
|
127
142
|
#endif
|
@@ -156,7 +171,12 @@ namespace hnswlib {
|
|
156
171
|
_mm512_store_ps(TmpRes, sum512);
|
157
172
|
float sum = TmpRes[0] + TmpRes[1] + TmpRes[2] + TmpRes[3] + TmpRes[4] + TmpRes[5] + TmpRes[6] + TmpRes[7] + TmpRes[8] + TmpRes[9] + TmpRes[10] + TmpRes[11] + TmpRes[12] + TmpRes[13] + TmpRes[14] + TmpRes[15];
|
158
173
|
|
159
|
-
return
|
174
|
+
return sum;
|
175
|
+
}
|
176
|
+
|
177
|
+
static float
|
178
|
+
InnerProductDistanceSIMD16ExtAVX512(const void *pVect1v, const void *pVect2v, const void *qty_ptr) {
|
179
|
+
return 1.0f - InnerProductSIMD16ExtAVX512(pVect1v, pVect2v, qty_ptr);
|
160
180
|
}
|
161
181
|
|
162
182
|
#endif
|
@@ -196,15 +216,20 @@ namespace hnswlib {
|
|
196
216
|
_mm256_store_ps(TmpRes, sum256);
|
197
217
|
float sum = TmpRes[0] + TmpRes[1] + TmpRes[2] + TmpRes[3] + TmpRes[4] + TmpRes[5] + TmpRes[6] + TmpRes[7];
|
198
218
|
|
199
|
-
return
|
219
|
+
return sum;
|
220
|
+
}
|
221
|
+
|
222
|
+
static float
|
223
|
+
InnerProductDistanceSIMD16ExtAVX(const void *pVect1v, const void *pVect2v, const void *qty_ptr) {
|
224
|
+
return 1.0f - InnerProductSIMD16ExtAVX(pVect1v, pVect2v, qty_ptr);
|
200
225
|
}
|
201
226
|
|
202
227
|
#endif
|
203
228
|
|
204
229
|
#if defined(USE_SSE)
|
205
230
|
|
206
|
-
|
207
|
-
|
231
|
+
static float
|
232
|
+
InnerProductSIMD16ExtSSE(const void *pVect1v, const void *pVect2v, const void *qty_ptr) {
|
208
233
|
float PORTABLE_ALIGN32 TmpRes[8];
|
209
234
|
float *pVect1 = (float *) pVect1v;
|
210
235
|
float *pVect2 = (float *) pVect2v;
|
@@ -245,7 +270,12 @@ namespace hnswlib {
|
|
245
270
|
_mm_store_ps(TmpRes, sum_prod);
|
246
271
|
float sum = TmpRes[0] + TmpRes[1] + TmpRes[2] + TmpRes[3];
|
247
272
|
|
248
|
-
return
|
273
|
+
return sum;
|
274
|
+
}
|
275
|
+
|
276
|
+
static float
|
277
|
+
InnerProductDistanceSIMD16ExtSSE(const void *pVect1v, const void *pVect2v, const void *qty_ptr) {
|
278
|
+
return 1.0f - InnerProductSIMD16ExtSSE(pVect1v, pVect2v, qty_ptr);
|
249
279
|
}
|
250
280
|
|
251
281
|
#endif
|
@@ -253,9 +283,11 @@ namespace hnswlib {
|
|
253
283
|
#if defined(USE_SSE) || defined(USE_AVX) || defined(USE_AVX512)
|
254
284
|
DISTFUNC<float> InnerProductSIMD16Ext = InnerProductSIMD16ExtSSE;
|
255
285
|
DISTFUNC<float> InnerProductSIMD4Ext = InnerProductSIMD4ExtSSE;
|
286
|
+
DISTFUNC<float> InnerProductDistanceSIMD16Ext = InnerProductDistanceSIMD16ExtSSE;
|
287
|
+
DISTFUNC<float> InnerProductDistanceSIMD4Ext = InnerProductDistanceSIMD4ExtSSE;
|
256
288
|
|
257
289
|
static float
|
258
|
-
|
290
|
+
InnerProductDistanceSIMD16ExtResiduals(const void *pVect1v, const void *pVect2v, const void *qty_ptr) {
|
259
291
|
size_t qty = *((size_t *) qty_ptr);
|
260
292
|
size_t qty16 = qty >> 4 << 4;
|
261
293
|
float res = InnerProductSIMD16Ext(pVect1v, pVect2v, &qty16);
|
@@ -264,11 +296,11 @@ namespace hnswlib {
|
|
264
296
|
|
265
297
|
size_t qty_left = qty - qty16;
|
266
298
|
float res_tail = InnerProduct(pVect1, pVect2, &qty_left);
|
267
|
-
return res + res_tail
|
299
|
+
return 1.0f - (res + res_tail);
|
268
300
|
}
|
269
301
|
|
270
302
|
static float
|
271
|
-
|
303
|
+
InnerProductDistanceSIMD4ExtResiduals(const void *pVect1v, const void *pVect2v, const void *qty_ptr) {
|
272
304
|
size_t qty = *((size_t *) qty_ptr);
|
273
305
|
size_t qty4 = qty >> 2 << 2;
|
274
306
|
|
@@ -279,7 +311,7 @@ namespace hnswlib {
|
|
279
311
|
float *pVect2 = (float *) pVect2v + qty4;
|
280
312
|
float res_tail = InnerProduct(pVect1, pVect2, &qty_left);
|
281
313
|
|
282
|
-
return res + res_tail
|
314
|
+
return 1.0f - (res + res_tail);
|
283
315
|
}
|
284
316
|
#endif
|
285
317
|
|
@@ -291,30 +323,37 @@ namespace hnswlib {
|
|
291
323
|
public:
|
292
324
|
InnerProductSpace() : data_size_(0), dim_(0) { }
|
293
325
|
InnerProductSpace(size_t dim) {
|
294
|
-
fstdistfunc_ =
|
326
|
+
fstdistfunc_ = InnerProductDistance;
|
295
327
|
#if defined(USE_AVX) || defined(USE_SSE) || defined(USE_AVX512)
|
296
328
|
#if defined(USE_AVX512)
|
297
|
-
if (AVX512Capable())
|
329
|
+
if (AVX512Capable()) {
|
298
330
|
InnerProductSIMD16Ext = InnerProductSIMD16ExtAVX512;
|
299
|
-
|
331
|
+
InnerProductDistanceSIMD16Ext = InnerProductDistanceSIMD16ExtAVX512;
|
332
|
+
} else if (AVXCapable()) {
|
300
333
|
InnerProductSIMD16Ext = InnerProductSIMD16ExtAVX;
|
334
|
+
InnerProductDistanceSIMD16Ext = InnerProductDistanceSIMD16ExtAVX;
|
335
|
+
}
|
301
336
|
#elif defined(USE_AVX)
|
302
|
-
if (AVXCapable())
|
337
|
+
if (AVXCapable()) {
|
303
338
|
InnerProductSIMD16Ext = InnerProductSIMD16ExtAVX;
|
339
|
+
InnerProductDistanceSIMD16Ext = InnerProductDistanceSIMD16ExtAVX;
|
340
|
+
}
|
304
341
|
#endif
|
305
342
|
#if defined(USE_AVX)
|
306
|
-
if (AVXCapable())
|
343
|
+
if (AVXCapable()) {
|
307
344
|
InnerProductSIMD4Ext = InnerProductSIMD4ExtAVX;
|
345
|
+
InnerProductDistanceSIMD4Ext = InnerProductDistanceSIMD4ExtAVX;
|
346
|
+
}
|
308
347
|
#endif
|
309
348
|
|
310
349
|
if (dim % 16 == 0)
|
311
|
-
fstdistfunc_ =
|
350
|
+
fstdistfunc_ = InnerProductDistanceSIMD16Ext;
|
312
351
|
else if (dim % 4 == 0)
|
313
|
-
fstdistfunc_ =
|
352
|
+
fstdistfunc_ = InnerProductDistanceSIMD4Ext;
|
314
353
|
else if (dim > 16)
|
315
|
-
fstdistfunc_ =
|
354
|
+
fstdistfunc_ = InnerProductDistanceSIMD16ExtResiduals;
|
316
355
|
else if (dim > 4)
|
317
|
-
fstdistfunc_ =
|
356
|
+
fstdistfunc_ = InnerProductDistanceSIMD4ExtResiduals;
|
318
357
|
#endif
|
319
358
|
dim_ = dim;
|
320
359
|
data_size_ = dim * sizeof(float);
|
@@ -335,5 +374,4 @@ namespace hnswlib {
|
|
335
374
|
~InnerProductSpace() {}
|
336
375
|
};
|
337
376
|
|
338
|
-
|
339
377
|
}
|
data/lib/hnswlib/version.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
# Hnswlib.rb provides Ruby bindings for the Hnswlib.
|
4
4
|
module Hnswlib
|
5
5
|
# The version of Hnswlib.rb you install.
|
6
|
-
VERSION = '0.
|
6
|
+
VERSION = '0.6.0'
|
7
7
|
|
8
8
|
# The version of Hnswlib included with gem.
|
9
|
-
HSWLIB_VERSION = '0.6.
|
9
|
+
HSWLIB_VERSION = '0.6.2'
|
10
10
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hnswlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yoshoku
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Hnswlib.rb provides Ruby bindings for the Hnswlib.
|
14
14
|
email:
|
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '0'
|
58
58
|
requirements: []
|
59
|
-
rubygems_version: 3.3.
|
59
|
+
rubygems_version: 3.3.7
|
60
60
|
signing_key:
|
61
61
|
specification_version: 4
|
62
62
|
summary: Ruby bindings for the Hnswlib.
|