deglib 0.3.1__tar.gz → 0.3.2__tar.gz
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.
- {deglib-0.3.1/src/deglib.egg-info → deglib-0.3.2}/PKG-INFO +19 -22
- {deglib-0.3.1 → deglib-0.3.2}/README.md +18 -21
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distances.h +13 -1
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/graph/internal_graph.h +114 -80
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/search/searcher.h +1 -2
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/transformation/evp.h +1 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/transformation/mips.h +1 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/transformation/normalize.h +1 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/transformation/rotation.h +1 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/transformation/scalar/fp16.h +1 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/transformation/scalar/int4.h +1 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/transformation/scalar/int8.h +1 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/transformation/scalar/uint4.h +1 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/transformation/scalar/uint7.h +1 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/transformation/scalar/uint8.h +1 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/transformation.h +10 -0
- deglib-0.3.2/lib/deglib/include/deglib/tuning.h +2497 -0
- {deglib-0.3.1 → deglib-0.3.2}/src/deg_cpp/bindings_graph.cpp +1 -1
- {deglib-0.3.1 → deglib-0.3.2}/src/deg_cpp/bindings_transformation.cpp +50 -0
- {deglib-0.3.1 → deglib-0.3.2}/src/deg_cpp/bindings_tuning.cpp +81 -20
- {deglib-0.3.1 → deglib-0.3.2}/src/deglib/__init__.py +2 -2
- {deglib-0.3.1 → deglib-0.3.2}/src/deglib/builder.py +166 -56
- {deglib-0.3.1 → deglib-0.3.2}/src/deglib/graph.py +22 -29
- {deglib-0.3.1 → deglib-0.3.2}/src/deglib/search.py +89 -19
- {deglib-0.3.1 → deglib-0.3.2}/src/deglib/transformation.py +6 -2
- {deglib-0.3.1 → deglib-0.3.2}/src/deglib/tuning.py +52 -14
- {deglib-0.3.1 → deglib-0.3.2/src/deglib.egg-info}/PKG-INFO +19 -22
- {deglib-0.3.1 → deglib-0.3.2}/src/deglib.egg-info/SOURCES.txt +1 -0
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_deglib.py +21 -19
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_graph.py +1 -1
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_l2_normalize.py +30 -2
- deglib-0.3.2/tests/test_quantization_matrix.py +300 -0
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_rotation_transform.py +3 -1
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_searcher.py +32 -4
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_transformation_graph.py +23 -2
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_tuning.py +54 -105
- deglib-0.3.1/lib/deglib/include/deglib/tuning.h +0 -1212
- {deglib-0.3.1 → deglib-0.3.2}/CMakeLists.txt +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/LICENSE +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/MANIFEST.in +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/CMakeLists.txt +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/bench/CMakeLists.txt +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/bench/include/benchmark.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/bench/include/build.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/bench/include/dataset.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/bench/include/file_io.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/bench/include/logging.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/bench/include/repository.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/bench/include/stopwatch.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/cmake_modules/DetectCPUFeatures.cmake +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/CMakeLists.txt +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/analysis.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/builder.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/concurrent.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/config.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/deglib.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/evp_ip.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/fp16.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/fp16_ip.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/fp16_l2.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/fp32.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/fp32_ip.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/fp32_l2.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/int4.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/int4_ip.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/int4_l2.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/int8.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/int8_ip.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/int8_l2.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/residual_mode.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/tail_mask.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/uint4.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/uint4_ip.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/uint4_l2.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/uint7_ip.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/uint7_l2.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/uint8.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/uint8_ip.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/distance/uint8_l2.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/filter.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/graph/dynamic_graph.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/graph/intrusive_list.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/graph/mutable_graph.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/graph/readonly_graph.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/graph/sizebounded_graph.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/graph/visited_list_pool.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/graph.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/optimization/flas/fast_linear_assignment_sorter.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/optimization/flas/fast_linear_assignment_sorter_mt.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/optimization/flas/junker_volgenant_solver.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/optimization/pruning.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/optimization.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/search/kmeans.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/search/pareto_line.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/search/recall_table.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/search/reranker.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/search/result_list.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/search.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/serialization.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/transformation/scalar/common.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/utils/cpu.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/utils/memory.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/deglib/include/deglib/utils/random.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/test/CMakeLists.txt +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/test/src/common/test_helpers.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/lib/test/src/unit/graph/test_dynamic_graph_common.h +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/pyproject.toml +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/setup.cfg +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/setup.py +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/src/deg_cpp/bindings_distances.cpp +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/src/deg_cpp/bindings_optimization.cpp +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/src/deg_cpp/bindings_search.cpp +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/src/deg_cpp/deglib_cpp.cpp +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/src/deglib/analysis.py +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/src/deglib/cpu.py +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/src/deglib/distances.py +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/src/deglib/optimization.py +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/src/deglib/utils.py +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/src/deglib.egg-info/dependency_links.txt +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/src/deglib.egg-info/requires.txt +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/src/deglib.egg-info/top_level.txt +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_analysis.py +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_builder.py +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_cpu.py +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_distances.py +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_evp_quantizer.py +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_filter.py +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_pareto_line.py +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_presort.py +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_recall_table.py +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_rerank.py +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_scalar_quantizer.py +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_scalar_quantizer_int4.py +0 -0
- {deglib-0.3.1 → deglib-0.3.2}/tests/test_transformation.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: deglib
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Python bindings for the Dynamic Exploration Graph library by Nico Hezel
|
|
5
5
|
Author: Nico Hezel
|
|
6
6
|
Author-email: Bruno Schilling <bruno.schilling@htw-berlin.de>
|
|
@@ -102,14 +102,17 @@ num_samples, dims = 10_000, 128
|
|
|
102
102
|
data = np.random.random((num_samples, dims)).astype(np.float32)
|
|
103
103
|
query = np.random.random(dims).astype(np.float32)
|
|
104
104
|
|
|
105
|
-
# 2. Build index directly from data (
|
|
106
|
-
graph = deglib.build(data
|
|
105
|
+
# 2. Build index directly from data (metric="l2" by default)
|
|
106
|
+
graph = deglib.build(data)
|
|
107
107
|
|
|
108
|
-
#
|
|
108
|
+
# 3a. Query directly on the graph
|
|
109
109
|
res = graph.search(query, k=10, eps_or_ef=0.1)
|
|
110
110
|
|
|
111
|
+
# 3b. Or wrap in a Searcher for extra search optimizations (see python/API.md#deglibsearcher)
|
|
112
|
+
searcher = deglib.searcher(graph)
|
|
113
|
+
res = searcher.search(query, k=10, eps_or_ef=0.1)
|
|
114
|
+
|
|
111
115
|
print("Nearest neighbors:", res.indices)
|
|
112
|
-
print("Distances:", res.distances)
|
|
113
116
|
print("Distance evals:", res.graph_distance_count, "| Hops:", res.graph_hop_count)
|
|
114
117
|
```
|
|
115
118
|
|
|
@@ -250,25 +253,13 @@ num_vectors, dims = 10_000, 128
|
|
|
250
253
|
data = np.random.randn(num_vectors, dims).astype(np.float32)
|
|
251
254
|
query = np.random.randn(dims).astype(np.float32)
|
|
252
255
|
|
|
253
|
-
# 1.
|
|
254
|
-
graph = deglib.build(
|
|
255
|
-
data,
|
|
256
|
-
metric="cosine",
|
|
257
|
-
edges_per_vertex=32,
|
|
258
|
-
presort=True,
|
|
259
|
-
optimize=False,
|
|
260
|
-
show_progress=True,
|
|
261
|
-
)
|
|
256
|
+
# 1. Build exploration graph in FP32
|
|
257
|
+
graph = deglib.build(data, metric="cosine")
|
|
262
258
|
|
|
263
|
-
# 2.
|
|
264
|
-
|
|
265
|
-
searcher = deglib.searcher(
|
|
266
|
-
graph,
|
|
267
|
-
compress="8bit",
|
|
268
|
-
reranker=reranker,
|
|
269
|
-
)
|
|
259
|
+
# 2. Compress to 8-bit and auto-extract an FP16 reranker
|
|
260
|
+
searcher = deglib.searcher(graph, compress="8bit", reranker=True)
|
|
270
261
|
|
|
271
|
-
# 3.
|
|
262
|
+
# 3. Fetch 1.5 * k candidates from graph and re-score with reranker
|
|
272
263
|
res = searcher.search(query, k=10, eps_or_ef=0.1, rerank_factor=1.5, return_distances=True)
|
|
273
264
|
print("Top-10 nearest neighbor indices:", res.indices)
|
|
274
265
|
print("Top-10 exact distances:", res.distances)
|
|
@@ -279,6 +270,12 @@ print("Graph dists:", res.graph_distance_count, "| Rerank dists:", res.rerank_di
|
|
|
279
270
|
|
|
280
271
|
## Concepts & Parameters
|
|
281
272
|
|
|
273
|
+
### Choosing `metric` (`"l2"`, `"cosine"`, `"normalized"`, `"ip"`)
|
|
274
|
+
- **`"l2"`** *(default)*: Euclidean distance — works on both unnormalized and normalized vectors.
|
|
275
|
+
- **`"cosine"`** *(unnormalized vectors)*: Direction/angle similarity — automatically normalizes database and query vectors.
|
|
276
|
+
- **`"normalized"`** *(already unit-norm vectors, `||x||_2 == 1`)*: Same similarity as `"cosine"`, without redundant normalization overhead.
|
|
277
|
+
- **`"ip"`** *(unnormalized vectors)*: Norm-sensitive Maximum Inner Product Search (MIPS).
|
|
278
|
+
|
|
282
279
|
### `OptimizationTarget`
|
|
283
280
|
Controls the topology optimization strategy:
|
|
284
281
|
- `OptimizationTarget.LowLID`: Default for datasets with low local intrinsic dimensionality (supports multithreaded building).
|
|
@@ -74,14 +74,17 @@ num_samples, dims = 10_000, 128
|
|
|
74
74
|
data = np.random.random((num_samples, dims)).astype(np.float32)
|
|
75
75
|
query = np.random.random(dims).astype(np.float32)
|
|
76
76
|
|
|
77
|
-
# 2. Build index directly from data (
|
|
78
|
-
graph = deglib.build(data
|
|
77
|
+
# 2. Build index directly from data (metric="l2" by default)
|
|
78
|
+
graph = deglib.build(data)
|
|
79
79
|
|
|
80
|
-
#
|
|
80
|
+
# 3a. Query directly on the graph
|
|
81
81
|
res = graph.search(query, k=10, eps_or_ef=0.1)
|
|
82
82
|
|
|
83
|
+
# 3b. Or wrap in a Searcher for extra search optimizations (see python/API.md#deglibsearcher)
|
|
84
|
+
searcher = deglib.searcher(graph)
|
|
85
|
+
res = searcher.search(query, k=10, eps_or_ef=0.1)
|
|
86
|
+
|
|
83
87
|
print("Nearest neighbors:", res.indices)
|
|
84
|
-
print("Distances:", res.distances)
|
|
85
88
|
print("Distance evals:", res.graph_distance_count, "| Hops:", res.graph_hop_count)
|
|
86
89
|
```
|
|
87
90
|
|
|
@@ -222,25 +225,13 @@ num_vectors, dims = 10_000, 128
|
|
|
222
225
|
data = np.random.randn(num_vectors, dims).astype(np.float32)
|
|
223
226
|
query = np.random.randn(dims).astype(np.float32)
|
|
224
227
|
|
|
225
|
-
# 1.
|
|
226
|
-
graph = deglib.build(
|
|
227
|
-
data,
|
|
228
|
-
metric="cosine",
|
|
229
|
-
edges_per_vertex=32,
|
|
230
|
-
presort=True,
|
|
231
|
-
optimize=False,
|
|
232
|
-
show_progress=True,
|
|
233
|
-
)
|
|
228
|
+
# 1. Build exploration graph in FP32
|
|
229
|
+
graph = deglib.build(data, metric="cosine")
|
|
234
230
|
|
|
235
|
-
# 2.
|
|
236
|
-
|
|
237
|
-
searcher = deglib.searcher(
|
|
238
|
-
graph,
|
|
239
|
-
compress="8bit",
|
|
240
|
-
reranker=reranker,
|
|
241
|
-
)
|
|
231
|
+
# 2. Compress to 8-bit and auto-extract an FP16 reranker
|
|
232
|
+
searcher = deglib.searcher(graph, compress="8bit", reranker=True)
|
|
242
233
|
|
|
243
|
-
# 3.
|
|
234
|
+
# 3. Fetch 1.5 * k candidates from graph and re-score with reranker
|
|
244
235
|
res = searcher.search(query, k=10, eps_or_ef=0.1, rerank_factor=1.5, return_distances=True)
|
|
245
236
|
print("Top-10 nearest neighbor indices:", res.indices)
|
|
246
237
|
print("Top-10 exact distances:", res.distances)
|
|
@@ -251,6 +242,12 @@ print("Graph dists:", res.graph_distance_count, "| Rerank dists:", res.rerank_di
|
|
|
251
242
|
|
|
252
243
|
## Concepts & Parameters
|
|
253
244
|
|
|
245
|
+
### Choosing `metric` (`"l2"`, `"cosine"`, `"normalized"`, `"ip"`)
|
|
246
|
+
- **`"l2"`** *(default)*: Euclidean distance — works on both unnormalized and normalized vectors.
|
|
247
|
+
- **`"cosine"`** *(unnormalized vectors)*: Direction/angle similarity — automatically normalizes database and query vectors.
|
|
248
|
+
- **`"normalized"`** *(already unit-norm vectors, `||x||_2 == 1`)*: Same similarity as `"cosine"`, without redundant normalization overhead.
|
|
249
|
+
- **`"ip"`** *(unnormalized vectors)*: Norm-sensitive Maximum Inner Product Search (MIPS).
|
|
250
|
+
|
|
254
251
|
### `OptimizationTarget`
|
|
255
252
|
Controls the topology optimization strategy:
|
|
256
253
|
- `OptimizationTarget.LowLID`: Default for datasets with low local intrinsic dimensionality (supports multithreaded building).
|
|
@@ -162,6 +162,11 @@ concept DistanceFunction = requires(const void* a, const void* b, const void* pa
|
|
|
162
162
|
{ T::get_instruction() } -> std::convertible_to<const char*>;
|
|
163
163
|
} && std::is_convertible_v<decltype(&T::compare), DISTFUNC>;
|
|
164
164
|
|
|
165
|
+
template <typename Dist>
|
|
166
|
+
concept HasCompareBatch4 = requires(const void* q, const void* t, const void* param, float* out) {
|
|
167
|
+
Dist::compare_batch4(q, t, t, t, t, param, out);
|
|
168
|
+
};
|
|
169
|
+
|
|
165
170
|
namespace detail {
|
|
166
171
|
|
|
167
172
|
template <DistanceFunction Dist>
|
|
@@ -174,7 +179,7 @@ inline void batch_compare_impl(
|
|
|
174
179
|
const int32_t prefetch_offset,
|
|
175
180
|
const size_t prefetch_bytes
|
|
176
181
|
) {
|
|
177
|
-
constexpr bool has_batch4 =
|
|
182
|
+
constexpr bool has_batch4 = HasCompareBatch4<Dist>;
|
|
178
183
|
if (prefetch_offset > 0 && prefetch_bytes > 0) {
|
|
179
184
|
const size_t po = static_cast<size_t>(prefetch_offset);
|
|
180
185
|
const size_t warmup = std::min(po, count);
|
|
@@ -252,6 +257,7 @@ struct DistanceKernel {
|
|
|
252
257
|
BATCH_DISTFUNC compare_batch = nullptr;
|
|
253
258
|
STRIDED_DISTFUNC compare_strided = nullptr;
|
|
254
259
|
const char* instruction = "Unknown";
|
|
260
|
+
bool has_batch4 = false;
|
|
255
261
|
|
|
256
262
|
template <DistanceFunction Dist>
|
|
257
263
|
static consteval DistanceKernel make() noexcept {
|
|
@@ -260,6 +266,7 @@ struct DistanceKernel {
|
|
|
260
266
|
&detail::batch_compare_impl<Dist>,
|
|
261
267
|
&detail::strided_compare_impl<Dist>,
|
|
262
268
|
Dist::get_instruction(),
|
|
269
|
+
HasCompareBatch4<Dist>,
|
|
263
270
|
};
|
|
264
271
|
}
|
|
265
272
|
};
|
|
@@ -394,6 +401,11 @@ class FloatSpace {
|
|
|
394
401
|
*/
|
|
395
402
|
STRIDED_DISTFUNC get_strided_dist_func() const noexcept { return kernel_.compare_strided; }
|
|
396
403
|
|
|
404
|
+
/**
|
|
405
|
+
* Returns true if the selected distance kernel provides a 4-way batch comparison (compare_batch4).
|
|
406
|
+
*/
|
|
407
|
+
bool has_batch4() const noexcept { return kernel_.has_batch4; }
|
|
408
|
+
|
|
397
409
|
/**
|
|
398
410
|
* Returns the instruction set name (e.g. "AVX512", "AVX2", "Scalar") used by the distance function.
|
|
399
411
|
*/
|
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
#include "deglib/search/result_list.h"
|
|
8
8
|
|
|
9
9
|
#include <algorithm>
|
|
10
|
-
#include <chrono>
|
|
11
10
|
#include <array>
|
|
11
|
+
#include <chrono>
|
|
12
|
+
#include <concepts>
|
|
12
13
|
#include <cstddef>
|
|
13
14
|
#include <cstdint>
|
|
14
15
|
#include <limits>
|
|
@@ -733,6 +734,59 @@ class InternalGraph {
|
|
|
733
734
|
return ws;
|
|
734
735
|
}
|
|
735
736
|
|
|
737
|
+
/**
|
|
738
|
+
* Evaluates distances for collected neighbors using either 4-way batching (when supported by
|
|
739
|
+
* the kernel) or interleaved single-target prefetching, invoking `on_neighbor(neighbor_index, dist)`
|
|
740
|
+
* for each neighbor.
|
|
741
|
+
*/
|
|
742
|
+
struct NeighborEvaluator {
|
|
743
|
+
const void* query;
|
|
744
|
+
deglib::distances::DISTFUNC dist_func;
|
|
745
|
+
deglib::distances::BATCH_DISTFUNC batch_dist_func;
|
|
746
|
+
const void* dist_param;
|
|
747
|
+
bool use_batch;
|
|
748
|
+
int32_t po;
|
|
749
|
+
size_t prefetch_bytes;
|
|
750
|
+
|
|
751
|
+
template <typename GraphType>
|
|
752
|
+
NeighborEvaluator(const GraphType& self, const void* q) noexcept
|
|
753
|
+
: query(q),
|
|
754
|
+
dist_func(self.feature_space_.get_dist_func()),
|
|
755
|
+
batch_dist_func(self.feature_space_.get_batch_dist_func()),
|
|
756
|
+
dist_param(self.feature_space_.get_dist_func_param()),
|
|
757
|
+
use_batch(self.feature_space_.has_batch4()),
|
|
758
|
+
po(self.getPo()),
|
|
759
|
+
prefetch_bytes(static_cast<size_t>(self.getPl()) * deglib::memory::L1_CACHE_LINE_SIZE) {}
|
|
760
|
+
|
|
761
|
+
inline void operator()(
|
|
762
|
+
std::span<const uint32_t> neighbors,
|
|
763
|
+
std::span<const void* const> features,
|
|
764
|
+
std::invocable<uint32_t, float> auto&& on_neighbor
|
|
765
|
+
) const {
|
|
766
|
+
const size_t count = neighbors.size();
|
|
767
|
+
if (use_batch) {
|
|
768
|
+
alignas(64) float distances[256];
|
|
769
|
+
batch_dist_func(query, features.data(), count, dist_param, distances, po, prefetch_bytes);
|
|
770
|
+
for (size_t i = 0; i < count; ++i) {
|
|
771
|
+
on_neighbor(neighbors[i], distances[i]);
|
|
772
|
+
}
|
|
773
|
+
} else {
|
|
774
|
+
const bool do_prefetch = po > 0 && prefetch_bytes > 0;
|
|
775
|
+
const size_t po_u = do_prefetch ? static_cast<size_t>(po) : 0;
|
|
776
|
+
const size_t warmup = do_prefetch ? (std::min)(po_u, count) : 0;
|
|
777
|
+
for (size_t i = 0; i < warmup; ++i) {
|
|
778
|
+
deglib::memory::prefetch(reinterpret_cast<const char*>(features[i]), prefetch_bytes);
|
|
779
|
+
}
|
|
780
|
+
for (size_t i = 0; i < count; ++i) {
|
|
781
|
+
if (do_prefetch && i + po_u < count) {
|
|
782
|
+
deglib::memory::prefetch(reinterpret_cast<const char*>(features[i + po_u]), prefetch_bytes);
|
|
783
|
+
}
|
|
784
|
+
on_neighbor(neighbors[i], dist_func(query, features[i], dist_param));
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
|
|
736
790
|
/**
|
|
737
791
|
* Statically dispatched exploration and k-NN search implementation.
|
|
738
792
|
* Inlines graph member accesses (features, neighbors, labels) via GraphType to avoid vtable calls.
|
|
@@ -829,8 +883,7 @@ class InternalGraph {
|
|
|
829
883
|
auto radius = (results.size() < k) ? std::numeric_limits<float>::max() : results.top().getDistance();
|
|
830
884
|
auto exploration_radius = (radius == std::numeric_limits<float>::max()) ? radius : radius * ((radius < 0) ? (1 - eps) : (1 + eps));
|
|
831
885
|
|
|
832
|
-
const
|
|
833
|
-
const size_t prefetch_bytes = static_cast<size_t>(self.getPl()) * deglib::memory::L1_CACHE_LINE_SIZE;
|
|
886
|
+
const NeighborEvaluator evaluate(self, query);
|
|
834
887
|
const int32_t nl = self.getNl();
|
|
835
888
|
const size_t edges_per_vertex = self.edges_per_vertex_;
|
|
836
889
|
alignas(64) uint32_t good_neighbors[256];
|
|
@@ -868,46 +921,40 @@ class InternalGraph {
|
|
|
868
921
|
if (good_neighbor_count <= 0) break;
|
|
869
922
|
}
|
|
870
923
|
|
|
871
|
-
const
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
// check the neighborhood of this vertex later, if its good enough
|
|
884
|
-
if (neighbor_distance <= exploration_radius) {
|
|
885
|
-
next_vertices.emplace(neighbor_index, neighbor_distance);
|
|
886
|
-
deglib::memory::prefetch(
|
|
887
|
-
reinterpret_cast<const char*>(self.neighbors_by_index(neighbor_index)), static_cast<size_t>(nl) * deglib::memory::L1_CACHE_LINE_SIZE
|
|
888
|
-
);
|
|
924
|
+
const size_t n = static_cast<size_t>(good_neighbor_count);
|
|
925
|
+
evaluate(
|
|
926
|
+
{good_neighbors, n},
|
|
927
|
+
{good_features, n},
|
|
928
|
+
[&](const uint32_t neighbor_index, const float neighbor_distance) {
|
|
929
|
+
// check the neighborhood of this vertex later, if its good enough
|
|
930
|
+
if (neighbor_distance <= exploration_radius) {
|
|
931
|
+
next_vertices.emplace(neighbor_index, neighbor_distance);
|
|
932
|
+
deglib::memory::prefetch(
|
|
933
|
+
reinterpret_cast<const char*>(self.neighbors_by_index(neighbor_index)), static_cast<size_t>(nl) * deglib::memory::L1_CACHE_LINE_SIZE
|
|
934
|
+
);
|
|
889
935
|
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
936
|
+
// remember the vertex, if its better than the worst in the result list
|
|
937
|
+
if (neighbor_distance < radius) {
|
|
938
|
+
bool insert = true;
|
|
939
|
+
if constexpr (use_filter) {
|
|
940
|
+
insert = filter->is_valid(self.label_by_index(neighbor_index));
|
|
941
|
+
}
|
|
942
|
+
if (insert) {
|
|
943
|
+
if (results.size() < k) {
|
|
944
|
+
results.emplace(neighbor_index, neighbor_distance);
|
|
945
|
+
if (results.size() == k) {
|
|
946
|
+
radius = results.top().getDistance();
|
|
947
|
+
exploration_radius = radius * ((radius < 0) ? (1 - eps) : (1 + eps));
|
|
948
|
+
}
|
|
949
|
+
} else {
|
|
950
|
+
radius = results.replace_top(neighbor_index, neighbor_distance).getDistance();
|
|
901
951
|
exploration_radius = radius * ((radius < 0) ? (1 - eps) : (1 + eps));
|
|
902
952
|
}
|
|
903
|
-
} else {
|
|
904
|
-
radius = results.replace_top(neighbor_index, neighbor_distance).getDistance();
|
|
905
|
-
exploration_radius = radius * ((radius < 0) ? (1 - eps) : (1 + eps));
|
|
906
953
|
}
|
|
907
954
|
}
|
|
908
955
|
}
|
|
909
956
|
}
|
|
910
|
-
|
|
957
|
+
);
|
|
911
958
|
|
|
912
959
|
dist_count += static_cast<uint32_t>(good_neighbor_count);
|
|
913
960
|
if constexpr (use_max_distance_count) {
|
|
@@ -1019,8 +1066,7 @@ class InternalGraph {
|
|
|
1019
1066
|
}
|
|
1020
1067
|
}
|
|
1021
1068
|
|
|
1022
|
-
const
|
|
1023
|
-
const size_t prefetch_bytes = static_cast<size_t>(self.getPl()) * deglib::memory::L1_CACHE_LINE_SIZE;
|
|
1069
|
+
const NeighborEvaluator evaluate(self, query);
|
|
1024
1070
|
const int32_t nl = self.getNl();
|
|
1025
1071
|
const size_t edges_per_vertex = self.edges_per_vertex_;
|
|
1026
1072
|
alignas(64) uint32_t good_neighbors[256];
|
|
@@ -1061,32 +1107,26 @@ class InternalGraph {
|
|
|
1061
1107
|
if (good_neighbor_count <= 0) break;
|
|
1062
1108
|
}
|
|
1063
1109
|
|
|
1064
|
-
const
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
// check the neighborhood of this vertex later, if its good enough
|
|
1077
|
-
if (dist <= radius) {
|
|
1078
|
-
next_vertices.emplace(neighbor_index, dist);
|
|
1079
|
-
deglib::memory::prefetch(
|
|
1080
|
-
reinterpret_cast<const char*>(self.neighbors_by_index(neighbor_index)), static_cast<size_t>(nl) * deglib::memory::L1_CACHE_LINE_SIZE
|
|
1081
|
-
);
|
|
1082
|
-
}
|
|
1110
|
+
const size_t n = static_cast<size_t>(good_neighbor_count);
|
|
1111
|
+
evaluate(
|
|
1112
|
+
{good_neighbors, n},
|
|
1113
|
+
{good_features, n},
|
|
1114
|
+
[&](const uint32_t neighbor_index, const float dist) {
|
|
1115
|
+
// check the neighborhood of this vertex later, if its good enough
|
|
1116
|
+
if (dist <= radius) {
|
|
1117
|
+
next_vertices.emplace(neighbor_index, dist);
|
|
1118
|
+
deglib::memory::prefetch(
|
|
1119
|
+
reinterpret_cast<const char*>(self.neighbors_by_index(neighbor_index)), static_cast<size_t>(nl) * deglib::memory::L1_CACHE_LINE_SIZE
|
|
1120
|
+
);
|
|
1121
|
+
}
|
|
1083
1122
|
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1123
|
+
if constexpr (use_filter) {
|
|
1124
|
+
if (filter->is_valid(self.label_by_index(neighbor_index))) valid_results.insert(neighbor_index, dist);
|
|
1125
|
+
} else {
|
|
1126
|
+
valid_results.insert(neighbor_index, dist);
|
|
1127
|
+
}
|
|
1088
1128
|
}
|
|
1089
|
-
|
|
1129
|
+
);
|
|
1090
1130
|
|
|
1091
1131
|
dist_count += static_cast<uint32_t>(good_neighbor_count);
|
|
1092
1132
|
if constexpr (use_max_distance_count) {
|
|
@@ -1169,8 +1209,7 @@ class InternalGraph {
|
|
|
1169
1209
|
}
|
|
1170
1210
|
}
|
|
1171
1211
|
|
|
1172
|
-
const
|
|
1173
|
-
const size_t prefetch_bytes = static_cast<size_t>(self.getPl()) * deglib::memory::L1_CACHE_LINE_SIZE;
|
|
1212
|
+
const NeighborEvaluator evaluate(self, query);
|
|
1174
1213
|
const int32_t nl = self.getNl();
|
|
1175
1214
|
const size_t edges_per_vertex = self.edges_per_vertex_;
|
|
1176
1215
|
alignas(64) uint32_t good_neighbors[256];
|
|
@@ -1204,23 +1243,18 @@ class InternalGraph {
|
|
|
1204
1243
|
if (good_neighbor_count <= 0) break;
|
|
1205
1244
|
}
|
|
1206
1245
|
|
|
1207
|
-
const
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
const float neighbor_distance = dist_func(query, good_features[i], dist_func_param);
|
|
1218
|
-
if (pool.insert(neighbor_index, neighbor_distance)) {
|
|
1219
|
-
deglib::memory::prefetch(
|
|
1220
|
-
reinterpret_cast<const char*>(self.neighbors_by_index(neighbor_index)), static_cast<size_t>(nl) * deglib::memory::L1_CACHE_LINE_SIZE
|
|
1221
|
-
);
|
|
1246
|
+
const size_t n = static_cast<size_t>(good_neighbor_count);
|
|
1247
|
+
evaluate(
|
|
1248
|
+
{good_neighbors, n},
|
|
1249
|
+
{good_features, n},
|
|
1250
|
+
[&](const uint32_t neighbor_index, const float neighbor_distance) {
|
|
1251
|
+
if (pool.insert(neighbor_index, neighbor_distance)) {
|
|
1252
|
+
deglib::memory::prefetch(
|
|
1253
|
+
reinterpret_cast<const char*>(self.neighbors_by_index(neighbor_index)), static_cast<size_t>(nl) * deglib::memory::L1_CACHE_LINE_SIZE
|
|
1254
|
+
);
|
|
1255
|
+
}
|
|
1222
1256
|
}
|
|
1223
|
-
|
|
1257
|
+
);
|
|
1224
1258
|
|
|
1225
1259
|
dist_count += static_cast<uint32_t>(good_neighbor_count);
|
|
1226
1260
|
if constexpr (use_max_distance_count) {
|
|
@@ -69,8 +69,7 @@ class Searcher {
|
|
|
69
69
|
bool normalize_query_ = false;
|
|
70
70
|
|
|
71
71
|
static inline bool is_spatial_prefix_transform(const deglib::transformation::FeatureTransformation& t) noexcept {
|
|
72
|
-
|
|
73
|
-
return n == "L2NormalizeTransform" || n == "MipsTransform";
|
|
72
|
+
return t.type() == deglib::transformation::TransformationType::Spatial;
|
|
74
73
|
}
|
|
75
74
|
|
|
76
75
|
void split_shared_prefix_transforms() {
|
|
@@ -693,6 +693,7 @@ class EvpQuantizer : public FeatureTransformation {
|
|
|
693
693
|
explicit EvpQuantizer(uint32_t dim, uint32_t non_zeros = 0) : dim_(dim), non_zeros_(non_zeros) {}
|
|
694
694
|
|
|
695
695
|
uint32_t tag() const noexcept override { return 0x51505645; } // 'EVPQ'
|
|
696
|
+
TransformationType type() const noexcept override { return TransformationType::Quantizer; }
|
|
696
697
|
std::string_view name() const noexcept override { return "EvpQuantizer"; }
|
|
697
698
|
uint32_t input_dim() const noexcept override { return dim_; }
|
|
698
699
|
uint32_t output_dim() const noexcept override { return dim_; }
|
|
@@ -130,6 +130,7 @@ class MipsTransform : public FeatureTransformation {
|
|
|
130
130
|
MipsTransform(uint32_t dim, float max_norm = 0.0f) : dim_(dim), max_norm_(max_norm) {}
|
|
131
131
|
|
|
132
132
|
uint32_t tag() const noexcept override { return 0x5350494D; } // 'MIPS'
|
|
133
|
+
TransformationType type() const noexcept override { return TransformationType::Spatial; }
|
|
133
134
|
std::string_view name() const noexcept override { return "MipsTransform"; }
|
|
134
135
|
uint32_t input_dim() const noexcept override { return dim_; }
|
|
135
136
|
uint32_t output_dim() const noexcept override { return dim_ + 1; }
|
|
@@ -57,6 +57,7 @@ class L2NormalizeTransform : public FeatureTransformation {
|
|
|
57
57
|
void set_dim(uint32_t d) noexcept { dim_ = d; }
|
|
58
58
|
|
|
59
59
|
uint32_t tag() const noexcept override { return TAG_NORM; }
|
|
60
|
+
TransformationType type() const noexcept override { return TransformationType::Spatial; }
|
|
60
61
|
std::string_view name() const noexcept override { return "L2NormalizeTransform"; }
|
|
61
62
|
uint32_t input_dim() const noexcept override { return dim_; }
|
|
62
63
|
uint32_t output_dim() const noexcept override { return dim_; }
|
|
@@ -212,6 +212,7 @@ class FastHadamardRotation : public FeatureTransformation {
|
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
uint32_t tag() const noexcept override { return TAG_FWHT; }
|
|
215
|
+
TransformationType type() const noexcept override { return TransformationType::Rotation; }
|
|
215
216
|
std::string_view name() const noexcept override { return "FastHadamardRotation"; }
|
|
216
217
|
uint32_t input_dim() const noexcept override { return dim_; }
|
|
217
218
|
uint32_t output_dim() const noexcept override { return dim_; }
|
|
@@ -29,6 +29,7 @@ class ScalarQuantizerFP16 : public FeatureTransformation {
|
|
|
29
29
|
ScalarQuantizerFP16(uint32_t dim, float abs_max) : dim_(dim) { set_abs_max(abs_max); }
|
|
30
30
|
|
|
31
31
|
uint32_t tag() const noexcept override { return TAG_SQ16; }
|
|
32
|
+
TransformationType type() const noexcept override { return TransformationType::Quantizer; }
|
|
32
33
|
std::string_view name() const noexcept override { return "ScalarQuantizerFP16"; }
|
|
33
34
|
uint32_t input_dim() const noexcept override { return dim_; }
|
|
34
35
|
uint32_t output_dim() const noexcept override { return dim_; }
|
|
@@ -29,6 +29,7 @@ class ScalarQuantizerInt4 : public FeatureTransformation {
|
|
|
29
29
|
explicit ScalarQuantizerInt4(uint32_t dim) : dim_(dim) {}
|
|
30
30
|
|
|
31
31
|
uint32_t tag() const noexcept override { return TAG_SQI4; }
|
|
32
|
+
TransformationType type() const noexcept override { return TransformationType::Quantizer; }
|
|
32
33
|
std::string_view name() const noexcept override { return "ScalarQuantizerInt4"; }
|
|
33
34
|
uint32_t input_dim() const noexcept override { return dim_; }
|
|
34
35
|
uint32_t output_dim() const noexcept override { return dim_; }
|
|
@@ -26,6 +26,7 @@ class ScalarQuantizerInt8 : public FeatureTransformation {
|
|
|
26
26
|
explicit ScalarQuantizerInt8(uint32_t dim) : dim_(dim) {}
|
|
27
27
|
|
|
28
28
|
uint32_t tag() const noexcept override { return TAG_SQI8; }
|
|
29
|
+
TransformationType type() const noexcept override { return TransformationType::Quantizer; }
|
|
29
30
|
std::string_view name() const noexcept override { return "ScalarQuantizerInt8"; }
|
|
30
31
|
uint32_t input_dim() const noexcept override { return dim_; }
|
|
31
32
|
uint32_t output_dim() const noexcept override { return dim_; }
|
|
@@ -190,6 +190,7 @@ class ScalarQuantizerUint4 : public FeatureTransformation {
|
|
|
190
190
|
explicit ScalarQuantizerUint4(uint32_t dim) : dim_(dim) {}
|
|
191
191
|
|
|
192
192
|
uint32_t tag() const noexcept override { return TAG_SQU4; }
|
|
193
|
+
TransformationType type() const noexcept override { return TransformationType::Quantizer; }
|
|
193
194
|
std::string_view name() const noexcept override { return "ScalarQuantizerUint4"; }
|
|
194
195
|
uint32_t input_dim() const noexcept override { return dim_; }
|
|
195
196
|
uint32_t output_dim() const noexcept override { return dim_; }
|
|
@@ -25,6 +25,7 @@ class ScalarQuantizerUint7 : public FeatureTransformation {
|
|
|
25
25
|
explicit ScalarQuantizerUint7(uint32_t dim) : dim_(dim) {}
|
|
26
26
|
|
|
27
27
|
uint32_t tag() const noexcept override { return TAG_SQU7; }
|
|
28
|
+
TransformationType type() const noexcept override { return TransformationType::Quantizer; }
|
|
28
29
|
std::string_view name() const noexcept override { return "ScalarQuantizerUint7"; }
|
|
29
30
|
uint32_t input_dim() const noexcept override { return dim_; }
|
|
30
31
|
uint32_t output_dim() const noexcept override { return dim_; }
|
|
@@ -26,6 +26,7 @@ class ScalarQuantizerUint8 : public FeatureTransformation {
|
|
|
26
26
|
explicit ScalarQuantizerUint8(uint32_t dim) : dim_(dim) {}
|
|
27
27
|
|
|
28
28
|
uint32_t tag() const noexcept override { return TAG_SQU8; }
|
|
29
|
+
TransformationType type() const noexcept override { return TransformationType::Quantizer; }
|
|
29
30
|
std::string_view name() const noexcept override { return "ScalarQuantizerUint8"; }
|
|
30
31
|
uint32_t input_dim() const noexcept override { return dim_; }
|
|
31
32
|
uint32_t output_dim() const noexcept override { return dim_; }
|
|
@@ -31,6 +31,15 @@ inline constexpr uint32_t TAG_EVPQ = uint32_t('E') | (uint32_t('V') << 8) | (uin
|
|
|
31
31
|
inline constexpr uint32_t TAG_NORM = uint32_t('N') | (uint32_t('O') << 8) | (uint32_t('R') << 16) | (uint32_t('M') << 24);
|
|
32
32
|
inline constexpr uint32_t TAG_FWHT = uint32_t('F') | (uint32_t('W') << 8) | (uint32_t('H') << 16) | (uint32_t('T') << 24);
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* @brief Semantic category of a FeatureTransformation stage.
|
|
36
|
+
*/
|
|
37
|
+
enum class TransformationType : uint8_t {
|
|
38
|
+
Spatial, ///< Space-preserving or space-lifting prefix transforms (e.g. L2NormalizeTransform, MipsTransform)
|
|
39
|
+
Rotation, ///< Orthogonal pre-quantization transforms (e.g. FastHadamardRotation)
|
|
40
|
+
Quantizer, ///< Precision-reducing quantizers (e.g. ScalarQuantizer*, EvpQuantizer)
|
|
41
|
+
};
|
|
42
|
+
|
|
34
43
|
/**
|
|
35
44
|
* @brief Abstract base class for all feature and vector transformations.
|
|
36
45
|
*/
|
|
@@ -39,6 +48,7 @@ class FeatureTransformation {
|
|
|
39
48
|
virtual ~FeatureTransformation() = default;
|
|
40
49
|
|
|
41
50
|
virtual uint32_t tag() const noexcept = 0;
|
|
51
|
+
virtual TransformationType type() const noexcept = 0;
|
|
42
52
|
virtual std::string_view name() const noexcept = 0;
|
|
43
53
|
virtual uint32_t input_dim() const noexcept = 0;
|
|
44
54
|
virtual uint32_t output_dim() const noexcept = 0;
|