-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #276 from ashvardanian/main-dev
- Loading branch information
Showing
6 changed files
with
93 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,7 @@ | |
"SLOC", | ||
"sorensen", | ||
"tanimoto", | ||
"tqdm", | ||
"uninitialize", | ||
"unumusearch", | ||
"usearch", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from time import time | ||
|
||
from usearch.index import search, MetricKind, ScalarKind | ||
from usearch.compiled import hardware_acceleration | ||
from faiss import IndexFlatL2, knn | ||
import numpy as np | ||
import fire | ||
|
||
|
||
def run( | ||
n: int = 10**5, | ||
q: int = 10, | ||
k: int = 100, | ||
ndim: int = 256, | ||
half: bool = False, | ||
): | ||
usearch_dtype = ScalarKind.F16 if half else ScalarKind.F32 | ||
acceleration = hardware_acceleration( | ||
dtype=usearch_dtype, | ||
ndim=ndim, | ||
metric_kind=MetricKind.L2sq, | ||
) | ||
print("Hardware acceleration in USearch: ", acceleration) | ||
|
||
x = np.random.random((n, ndim)) | ||
x = x.astype(np.float16) if half else x.astype(np.float32) | ||
|
||
start = time() | ||
_ = search( | ||
x, | ||
x[:q], | ||
k, | ||
MetricKind.L2sq, | ||
exact=True, | ||
).keys | ||
print("USearch: ", time() - start) | ||
|
||
start = time() | ||
_ = knn(x, x[:q], k)[1] | ||
print("FAISS: ", time() - start) | ||
|
||
|
||
if __name__ == "__main__": | ||
fire.Fire(run) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters