usearch 2.8.1 → 2.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/release.yml +1 -1
- package/CITATION.cff +1 -1
- package/Cargo.toml +1 -1
- package/README.md +1 -1
- package/conanfile.py +1 -1
- package/csharp/nuget/nuget-package.props +1 -1
- package/include/usearch/index.hpp +7 -6
- package/javascript/usearch.js +4 -4
- package/javascript/usearch.test.js +22 -0
- package/package-ci.json +10 -0
- package/package.json +1 -5
- package/simsimd/.github/workflows/prerelease.yml +20 -11
- package/simsimd/.github/workflows/release.yml +24 -8
- package/simsimd/CMakeLists.txt +2 -2
- package/simsimd/README.md +1 -1
- package/simsimd/cpp/bench.cxx +11 -6
- package/simsimd/include/simsimd/binary.h +36 -22
- package/simsimd/include/simsimd/probability.h +94 -70
- package/simsimd/include/simsimd/simsimd.h +30 -21
- package/simsimd/include/simsimd/spatial.h +199 -117
- package/simsimd/package-ci.json +10 -0
- package/simsimd/package.json +1 -5
- package/simsimd/python/lib.c +1 -0
- package/simsimd/python/test.py +47 -22
- package/wasmer.toml +1 -1
|
@@ -25,7 +25,7 @@ jobs:
|
|
|
25
25
|
with:
|
|
26
26
|
persist-credentials: false
|
|
27
27
|
- uses: actions/setup-node@v3
|
|
28
|
-
- run: npm install --save-dev @semantic-release/exec @semantic-release/git conventional-changelog-eslint semantic-release && npx semantic-release
|
|
28
|
+
- run: npm install --save-dev --prefix ./package-ci @semantic-release/exec @semantic-release/git conventional-changelog-eslint semantic-release && npx --prefix ./package-ci semantic-release
|
|
29
29
|
|
|
30
30
|
rebase:
|
|
31
31
|
name: Rebase Dev. Branch
|
package/CITATION.cff
CHANGED
package/Cargo.toml
CHANGED
package/README.md
CHANGED
package/conanfile.py
CHANGED
|
@@ -7,7 +7,7 @@ required_conan_version = ">=1.53.0"
|
|
|
7
7
|
class USearchConan(ConanFile):
|
|
8
8
|
|
|
9
9
|
name = "usearch"
|
|
10
|
-
version = '2.8.
|
|
10
|
+
version = '2.8.3'
|
|
11
11
|
license = "Apache-2.0"
|
|
12
12
|
description = "Smaller & Faster Single-File Vector Search Engine from Unum"
|
|
13
13
|
homepage = "https://github.com/unum-cloud/usearch"
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
#define USEARCH_VERSION_MAJOR 2
|
|
13
13
|
#define USEARCH_VERSION_MINOR 8
|
|
14
|
-
#define USEARCH_VERSION_PATCH
|
|
14
|
+
#define USEARCH_VERSION_PATCH 3
|
|
15
15
|
|
|
16
16
|
// Inferring C++ version
|
|
17
17
|
// https://stackoverflow.com/a/61552074
|
|
@@ -547,6 +547,7 @@ class max_heap_gt {
|
|
|
547
547
|
inline bool empty() const noexcept { return !size_; }
|
|
548
548
|
inline std::size_t size() const noexcept { return size_; }
|
|
549
549
|
inline std::size_t capacity() const noexcept { return capacity_; }
|
|
550
|
+
|
|
550
551
|
/// @brief Selects the largest element in the heap.
|
|
551
552
|
/// @return Reference to the stored element.
|
|
552
553
|
inline element_t const& top() const noexcept { return elements_[0]; }
|
|
@@ -2205,7 +2206,7 @@ class index_gt {
|
|
|
2205
2206
|
node_t node = nodes_[candidate.slot];
|
|
2206
2207
|
return {member_cref_t{node.ckey(), candidate.slot}, candidate.distance};
|
|
2207
2208
|
}
|
|
2208
|
-
inline std::size_t merge_into(
|
|
2209
|
+
inline std::size_t merge_into( //
|
|
2209
2210
|
vector_key_t* keys, distance_t* distances, //
|
|
2210
2211
|
std::size_t old_count, std::size_t max_count) const noexcept {
|
|
2211
2212
|
|
|
@@ -2279,10 +2280,10 @@ class index_gt {
|
|
|
2279
2280
|
typename callback_at = dummy_callback_t, //
|
|
2280
2281
|
typename prefetch_at = dummy_prefetch_t //
|
|
2281
2282
|
>
|
|
2282
|
-
add_result_t add(
|
|
2283
|
+
add_result_t add( //
|
|
2283
2284
|
vector_key_t key, value_at&& value, metric_at&& metric, //
|
|
2284
|
-
index_update_config_t config = {},
|
|
2285
|
-
callback_at&& callback = callback_at{},
|
|
2285
|
+
index_update_config_t config = {}, //
|
|
2286
|
+
callback_at&& callback = callback_at{}, //
|
|
2286
2287
|
prefetch_at&& prefetch = prefetch_at{}) usearch_noexcept_m {
|
|
2287
2288
|
|
|
2288
2289
|
add_result_t result;
|
|
@@ -2389,7 +2390,7 @@ class index_gt {
|
|
|
2389
2390
|
>
|
|
2390
2391
|
add_result_t update( //
|
|
2391
2392
|
member_iterator_t iterator, //
|
|
2392
|
-
vector_key_t key,
|
|
2393
|
+
vector_key_t key, //
|
|
2393
2394
|
value_at&& value, //
|
|
2394
2395
|
metric_at&& metric, //
|
|
2395
2396
|
index_update_config_t config = {}, //
|
package/javascript/usearch.js
CHANGED
|
@@ -84,7 +84,7 @@ class BatchMatches {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
function isOneKey(keys) {
|
|
87
|
-
return typeof keys === 'number' || typeof keys === 'bigint';
|
|
87
|
+
return (!Number.isNaN(keys) && typeof keys === 'number') || typeof keys === 'bigint';
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
function normalizeKeys(keys) {
|
|
@@ -92,7 +92,7 @@ function normalizeKeys(keys) {
|
|
|
92
92
|
keys = BigUint64Array.of(BigInt(keys));
|
|
93
93
|
} else if (Array.isArray(keys)) {
|
|
94
94
|
keys = keys.map(key => {
|
|
95
|
-
if (typeof key !== 'bigint' && typeof key !== 'number')
|
|
95
|
+
if ((typeof key !== 'bigint' && typeof key !== 'number') || Number.isNaN(key))
|
|
96
96
|
throw new Error("All keys must be integers or bigints.");
|
|
97
97
|
return BigInt(key);
|
|
98
98
|
});
|
|
@@ -151,7 +151,7 @@ class Index {
|
|
|
151
151
|
if (typeof dimensionsOrConfigs === 'object' && dimensionsOrConfigs !== null) {
|
|
152
152
|
// Parameters are provided as an object
|
|
153
153
|
({ dimensions, metric = MetricKind.Cos, quantization = ScalarKind.F32, connectivity = 0, expansion_add = 0, expansion_search = 0, multi = false } = dimensionsOrConfigs);
|
|
154
|
-
} else if (typeof dimensionsOrConfigs === 'number' || typeof dimensionsOrConfigs === 'bigint') {
|
|
154
|
+
} else if ((typeof dimensionsOrConfigs === 'number' && !Number.isNaN(dimensionsOrConfigs)) || typeof dimensionsOrConfigs === 'bigint') {
|
|
155
155
|
// Parameters are provided as individual arguments
|
|
156
156
|
dimensions = dimensionsOrConfigs;
|
|
157
157
|
} else {
|
|
@@ -238,7 +238,7 @@ class Index {
|
|
|
238
238
|
* @throws Will throw an error if `vectors` is not a valid input type (TypedArray or an array of arrays) or if its flattened size is not a multiple of dimensions.
|
|
239
239
|
*/
|
|
240
240
|
search(vectors, k) {
|
|
241
|
-
if (typeof k !== 'number' || k <= 0) {
|
|
241
|
+
if ((!Number.isNaN(k) && typeof k !== 'number') || k <= 0) {
|
|
242
242
|
throw new Error("`k` must be a positive integer representing the number of nearest neighbors to search for.");
|
|
243
243
|
}
|
|
244
244
|
|
|
@@ -35,3 +35,25 @@ test('Batch operations', () => {
|
|
|
35
35
|
assert.deepEqual(results.keys, new BigUint64Array([15n, 16n]), 'keys should be 15 and 16');
|
|
36
36
|
assert.deepEqual(results.distances, new Float32Array([45, 130]), 'distances should be 45 and 130');
|
|
37
37
|
});
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
test('Operations with invalid values', () => {
|
|
41
|
+
const indexBatch = new usearch.Index(2, 'l2sq');
|
|
42
|
+
|
|
43
|
+
const keys = [NaN, 16n];
|
|
44
|
+
const vectors = [new Float32Array([10, 30]), new Float32Array([1, 5])];
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
indexBatch.add(keys, vectors);
|
|
48
|
+
throw new Error('indexBatch.add should have thrown an error.');
|
|
49
|
+
} catch (err) {
|
|
50
|
+
assert.equal(err.message, 'All keys must be integers or bigints.');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
indexBatch.search(NaN, 2);
|
|
55
|
+
throw new Error('indexBatch.search should have thrown an error.');
|
|
56
|
+
} catch (err) {
|
|
57
|
+
assert.equal(err.message, 'Vectors must be a TypedArray or an array of arrays.');
|
|
58
|
+
}
|
|
59
|
+
});
|
package/package-ci.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "usearch",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.3",
|
|
4
4
|
"description": "Smaller & Faster Single-File Vector Search Engine from Unum",
|
|
5
5
|
"author": "Ash Vardanian (https://ashvardanian.com/)",
|
|
6
6
|
"license": "Apache 2.0",
|
|
@@ -27,10 +27,6 @@
|
|
|
27
27
|
"test": "node --test ./javascript/usearch.test.js"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@semantic-release/exec": "^6.0.3",
|
|
31
|
-
"@semantic-release/git": "^10.0.1",
|
|
32
|
-
"conventional-changelog-eslint": "^3.0.9",
|
|
33
|
-
"semantic-release": "^21.1.2",
|
|
34
30
|
"typescript": "^5.1.6"
|
|
35
31
|
}
|
|
36
32
|
}
|
|
@@ -61,20 +61,29 @@ jobs:
|
|
|
61
61
|
|
|
62
62
|
test_javascript:
|
|
63
63
|
name: Test JavaScript
|
|
64
|
-
runs-on: ubuntu-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
runs-on: ubuntu-22.04
|
|
65
|
+
env:
|
|
66
|
+
CC: gcc-12
|
|
67
|
+
CXX: g++-12
|
|
68
|
+
|
|
69
69
|
steps:
|
|
70
70
|
- uses: actions/checkout@v4
|
|
71
|
+
with:
|
|
72
|
+
ref: "main"
|
|
73
|
+
- run: git submodule update --init --recursive
|
|
74
|
+
|
|
75
|
+
- name: Update compilers
|
|
76
|
+
run: |
|
|
77
|
+
sudo apt update
|
|
78
|
+
sudo apt install -y cmake build-essential libjemalloc-dev libomp-dev gcc-12 g++-12
|
|
79
|
+
|
|
71
80
|
- name: Set up Node.js
|
|
72
81
|
uses: actions/setup-node@v3
|
|
73
82
|
with:
|
|
74
|
-
node-version:
|
|
83
|
+
node-version: 18
|
|
75
84
|
|
|
76
|
-
- name: Build
|
|
77
|
-
run:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
- name: Build and Test
|
|
86
|
+
run: |
|
|
87
|
+
npm install
|
|
88
|
+
npm ci
|
|
89
|
+
npm test
|
|
@@ -18,18 +18,18 @@ permissions:
|
|
|
18
18
|
jobs:
|
|
19
19
|
versioning:
|
|
20
20
|
name: Semantic Release
|
|
21
|
-
runs-on: ubuntu-
|
|
21
|
+
runs-on: ubuntu-22.04
|
|
22
22
|
steps:
|
|
23
23
|
- uses: actions/checkout@v3
|
|
24
24
|
with:
|
|
25
25
|
persist-credentials: false
|
|
26
26
|
- uses: actions/setup-node@v3
|
|
27
|
-
- run: npm install --save-dev @semantic-release/exec @semantic-release/git conventional-changelog-eslint semantic-release && npx semantic-release
|
|
27
|
+
- run: npm install --save-dev --prefix ./package-ci @semantic-release/exec @semantic-release/git conventional-changelog-eslint semantic-release && npx --prefix ./package-ci semantic-release
|
|
28
28
|
|
|
29
29
|
rebase:
|
|
30
30
|
name: Rebase Dev. Branch
|
|
31
31
|
needs: versioning
|
|
32
|
-
runs-on: ubuntu-
|
|
32
|
+
runs-on: ubuntu-22.04
|
|
33
33
|
steps:
|
|
34
34
|
- name: Checkout the latest code
|
|
35
35
|
uses: actions/checkout@v3
|
|
@@ -109,17 +109,33 @@ jobs:
|
|
|
109
109
|
name: Publish JavaScript
|
|
110
110
|
needs: versioning
|
|
111
111
|
runs-on: ubuntu-22.04
|
|
112
|
+
env:
|
|
113
|
+
CC: gcc-12
|
|
114
|
+
CXX: g++-12
|
|
115
|
+
|
|
112
116
|
steps:
|
|
113
117
|
- uses: actions/checkout@v3
|
|
114
118
|
with:
|
|
115
119
|
ref: "main"
|
|
116
120
|
- run: git submodule update --init --recursive
|
|
117
|
-
|
|
121
|
+
|
|
122
|
+
- name: Update compilers
|
|
123
|
+
run: |
|
|
124
|
+
sudo apt update
|
|
125
|
+
sudo apt install -y cmake build-essential libjemalloc-dev libomp-dev gcc-12 g++-12
|
|
126
|
+
|
|
127
|
+
- name: Set up Node.js
|
|
128
|
+
uses: actions/setup-node@v3
|
|
118
129
|
with:
|
|
119
130
|
node-version: 18
|
|
120
|
-
|
|
121
|
-
-
|
|
122
|
-
|
|
123
|
-
|
|
131
|
+
|
|
132
|
+
- name: Build and Test
|
|
133
|
+
run: |
|
|
134
|
+
npm install
|
|
135
|
+
npm ci
|
|
136
|
+
npm test
|
|
137
|
+
|
|
138
|
+
- name: Publish
|
|
139
|
+
uses: JS-DevTools/npm-publish@v2
|
|
124
140
|
with:
|
|
125
141
|
token: ${{ secrets.NPM_TOKEN }}
|
package/simsimd/CMakeLists.txt
CHANGED
|
@@ -46,9 +46,9 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
|
|
|
46
46
|
if(NOT APPLE)
|
|
47
47
|
add_compile_options(-march=native)
|
|
48
48
|
endif()
|
|
49
|
-
add_compile_options(-pedantic -ferror-limit=1
|
|
49
|
+
add_compile_options(-pedantic -ferror-limit=1)
|
|
50
50
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
51
|
-
add_compile_options(-march=native -pedantic -fmax-errors=1
|
|
51
|
+
add_compile_options(-march=native -pedantic -fmax-errors=1)
|
|
52
52
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
|
|
53
53
|
add_compile_options(-w -ferror-limit=1)
|
|
54
54
|
endif()
|
package/simsimd/README.md
CHANGED
|
@@ -34,7 +34,7 @@ Given 1000 embeddings from OpenAI Ada API with 1536 dimensions, running on the A
|
|
|
34
34
|
|
|
35
35
|
### Intel Sapphire Rapids
|
|
36
36
|
|
|
37
|
-
On the Intel Sapphire Rapids platform, SimSIMD was benchmarked against auto-vectorized code using GCC 12. GCC handles single-precision `float
|
|
37
|
+
On the Intel Sapphire Rapids platform, SimSIMD was benchmarked against auto-vectorized code using GCC 12. GCC handles single-precision `float`, but might not be the best choice for `int8` and `_Float16` arrays, which has been part of the C language since 2011.
|
|
38
38
|
|
|
39
39
|
| | GCC 12 `f32` | GCC 12 `f16` | SimSIMD `f16` | `f16` improvement |
|
|
40
40
|
| :-------------- | -----------: | -----------: | ------------: | ----------------: |
|
package/simsimd/cpp/bench.cxx
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
#include <benchmark/benchmark.h>
|
|
5
5
|
|
|
6
|
-
#define SIMSIMD_RSQRT sqrtf
|
|
7
|
-
#define SIMSIMD_LOG logf
|
|
6
|
+
#define SIMSIMD_RSQRT(x) (1 / sqrtf(x))
|
|
7
|
+
#define SIMSIMD_LOG(x) (logf(x))
|
|
8
8
|
#include <simsimd/simsimd.h>
|
|
9
9
|
|
|
10
10
|
namespace bm = benchmark;
|
|
@@ -78,7 +78,7 @@ void register_(std::string name, metric_at* distance_func, metric_at* baseline_f
|
|
|
78
78
|
using pair_bytes_t = vectors_pair_gt<scalar_at, 1536 / sizeof(scalar_at)>;
|
|
79
79
|
|
|
80
80
|
std::size_t seconds = 10;
|
|
81
|
-
std::size_t threads = std::thread::hardware_concurrency(); // 1;
|
|
81
|
+
std::size_t threads = 1; // std::thread::hardware_concurrency(); // 1;
|
|
82
82
|
std::string name_dims = name + "_" + std::to_string(pair_dims_t{}.dimensions()) + "d";
|
|
83
83
|
std::string name_bytes = name + "_" + std::to_string(pair_bytes_t{}.size_bytes()) + "b";
|
|
84
84
|
|
|
@@ -95,7 +95,8 @@ int main(int argc, char** argv) {
|
|
|
95
95
|
bool compiled_with_sve = false;
|
|
96
96
|
bool compiled_with_neon = false;
|
|
97
97
|
bool compiled_with_avx2 = false;
|
|
98
|
-
bool
|
|
98
|
+
bool compiled_with_avx512vpopcntdq = false;
|
|
99
|
+
bool compiled_with_avx512vnni = false;
|
|
99
100
|
|
|
100
101
|
#if defined(__ARM_FEATURE_SVE)
|
|
101
102
|
compiled_with_sve = true;
|
|
@@ -107,7 +108,10 @@ int main(int argc, char** argv) {
|
|
|
107
108
|
compiled_with_avx2 = true;
|
|
108
109
|
#endif
|
|
109
110
|
#if defined(__AVX512VPOPCNTDQ__)
|
|
110
|
-
|
|
111
|
+
compiled_with_avx512vpopcntdq = true;
|
|
112
|
+
#endif
|
|
113
|
+
#if defined(__AVX512VNNI__)
|
|
114
|
+
compiled_with_avx512vnni = true;
|
|
111
115
|
#endif
|
|
112
116
|
|
|
113
117
|
// Log supported functionality
|
|
@@ -117,7 +121,8 @@ int main(int argc, char** argv) {
|
|
|
117
121
|
std::printf("- Arm NEON support enabled: %s\n", flags[compiled_with_neon]);
|
|
118
122
|
std::printf("- Arm SVE support enabled: %s\n", flags[compiled_with_sve]);
|
|
119
123
|
std::printf("- x86 AVX2 support enabled: %s\n", flags[compiled_with_avx2]);
|
|
120
|
-
std::printf("- x86 AVX512VPOPCNTDQ support enabled: %s\n", flags[
|
|
124
|
+
std::printf("- x86 AVX512VPOPCNTDQ support enabled: %s\n", flags[compiled_with_avx512vpopcntdq]);
|
|
125
|
+
std::printf("- x86 AVX512VNNI support enabled: %s\n", flags[compiled_with_avx512vnni]);
|
|
121
126
|
std::printf("\n");
|
|
122
127
|
|
|
123
128
|
// Run the benchmarks
|
|
@@ -133,41 +133,55 @@ simsimd_sve_b8_jaccard(simsimd_b8_t const* a, simsimd_b8_t const* b, simsimd_siz
|
|
|
133
133
|
|
|
134
134
|
#if SIMSIMD_TARGET_X86_AVX512
|
|
135
135
|
|
|
136
|
-
__attribute__((target("avx512vpopcntdq,avx512vl,avx512bw,avx512f"))) //
|
|
136
|
+
__attribute__((target("avx512vpopcntdq,avx512vl,avx512bw,avx512f,bmi2"))) //
|
|
137
137
|
inline static simsimd_f32_t
|
|
138
138
|
simsimd_avx512_b8_hamming(simsimd_b8_t const* a, simsimd_b8_t const* b, simsimd_size_t n_words) {
|
|
139
139
|
__m512i differences_vec = _mm512_setzero_si512();
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
140
|
+
__m512i a_vec, b_vec;
|
|
141
|
+
|
|
142
|
+
simsimd_avx512_b8_hamming_cycle:
|
|
143
|
+
if (n_words < 64) {
|
|
144
|
+
__mmask64 mask = _bzhi_u64(0xFFFFFFFFFFFFFFFF, n_words);
|
|
145
|
+
a_vec = _mm512_maskz_loadu_epi8(mask, a);
|
|
146
|
+
b_vec = _mm512_maskz_loadu_epi8(mask, b);
|
|
147
|
+
n_words = 0;
|
|
148
|
+
} else {
|
|
149
|
+
a_vec = _mm512_loadu_epi8(a);
|
|
150
|
+
b_vec = _mm512_loadu_epi8(b);
|
|
151
|
+
a += 64, b += 64, n_words -= 64;
|
|
149
152
|
}
|
|
153
|
+
__m512i xor_vec = _mm512_xor_si512(a_vec, b_vec);
|
|
154
|
+
differences_vec = _mm512_add_epi64(differences_vec, _mm512_popcnt_epi64(xor_vec));
|
|
155
|
+
if (n_words)
|
|
156
|
+
goto simsimd_avx512_b8_hamming_cycle;
|
|
150
157
|
|
|
151
158
|
simsimd_size_t differences = _mm512_reduce_add_epi64(differences_vec);
|
|
152
159
|
return (simsimd_f32_t)differences;
|
|
153
160
|
}
|
|
154
161
|
|
|
155
|
-
__attribute__((target("avx512vpopcntdq,avx512vl,avx512bw,avx512f"))) //
|
|
162
|
+
__attribute__((target("avx512vpopcntdq,avx512vl,avx512bw,avx512f,bmi2"))) //
|
|
156
163
|
inline static simsimd_f32_t
|
|
157
164
|
simsimd_avx512_b8_jaccard(simsimd_b8_t const* a, simsimd_b8_t const* b, simsimd_size_t n_words) {
|
|
158
165
|
__m512i intersection_vec = _mm512_setzero_si512(), union_vec = _mm512_setzero_si512();
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
166
|
+
__m512i a_vec, b_vec;
|
|
167
|
+
|
|
168
|
+
simsimd_avx512_b8_jaccard_cycle:
|
|
169
|
+
if (n_words < 64) {
|
|
170
|
+
__mmask64 mask = _bzhi_u64(0xFFFFFFFFFFFFFFFF, n_words);
|
|
171
|
+
a_vec = _mm512_maskz_loadu_epi8(mask, a);
|
|
172
|
+
b_vec = _mm512_maskz_loadu_epi8(mask, b);
|
|
173
|
+
n_words = 0;
|
|
174
|
+
} else {
|
|
175
|
+
a_vec = _mm512_loadu_epi8(a);
|
|
176
|
+
b_vec = _mm512_loadu_epi8(b);
|
|
177
|
+
a += 64, b += 64, n_words -= 64;
|
|
170
178
|
}
|
|
179
|
+
__m512i and_vec = _mm512_and_si512(a_vec, b_vec);
|
|
180
|
+
__m512i or_vec = _mm512_or_si512(a_vec, b_vec);
|
|
181
|
+
intersection_vec = _mm512_add_epi64(intersection_vec, _mm512_popcnt_epi64(and_vec));
|
|
182
|
+
union_vec = _mm512_add_epi64(union_vec, _mm512_popcnt_epi64(or_vec));
|
|
183
|
+
if (n_words)
|
|
184
|
+
goto simsimd_avx512_b8_jaccard_cycle;
|
|
171
185
|
|
|
172
186
|
simsimd_size_t intersection = _mm512_reduce_add_epi64(intersection_vec),
|
|
173
187
|
union_ = _mm512_reduce_add_epi64(union_vec);
|