Skip to content

Commit fb201aa

Browse files
committed
Improve: Start with import usearch
1 parent 77d20c6 commit fb201aa

10 files changed

+17
-34
lines changed

python/scripts/bench.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66
import pandas as pd
77

8+
import usearch
89
from usearch.index import Index, Key, MetricKind, ScalarKind
910
from usearch.numba import jit as njit
1011
from usearch.eval import Evaluation, AddTask

python/scripts/bench_exact.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from faiss import knn, METRIC_L2, METRIC_INNER_PRODUCT
55
import fire
66

7+
import usearch
78
from usearch.compiled import hardware_acceleration
89
from usearch.eval import random_vectors
910

python/scripts/index_faiss.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy as np
55
from faiss import IndexHNSWFlat, IndexIVFPQ, read_index
66

7+
import usearch
78
from usearch.index import BatchMatches
89
from usearch.index import (
910
DEFAULT_CONNECTIVITY,

python/scripts/join.py

+8-26
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
rm -rf datasets/cc_3M/*.usearch datasets/arxiv_2M/*.usearch
1313
python python/scripts/join.py
1414
"""
15+
1516
from numpy import dot
1617
from numpy.linalg import norm
1718
from tqdm import tqdm
1819
from simsimd import cos_f32x4_neon, to_int
1920

21+
import usearch
2022
from usearch.index import Index, MetricKind, CompiledMetric, MetricSignature
2123
from usearch.io import load_matrix
2224
from usearch.eval import measure_seconds
@@ -70,9 +72,7 @@
7072
b.save()
7173

7274

73-
print(
74-
f"Loaded two indexes of size: {len(a):,} for {a_name} and {len(b):,} for {b_name}"
75-
)
75+
print(f"Loaded two indexes of size: {len(a):,} for {a_name} and {len(b):,} for {b_name}")
7676
min_elements = min(len(a), len(b))
7777

7878
run_diagnostics = input("Would you like to run diagnostics? [Y/n]: ")
@@ -111,32 +111,16 @@
111111
)
112112

113113
secs, a_self_recall = dt(lambda: a.search(a.vectors, **args).recall(a.keys))
114-
print(
115-
"Self-recall @{} of {} index: {:.2f}%, took {:.2f}s".format(
116-
count, a_name, a_self_recall * 100, secs
117-
)
118-
)
114+
print("Self-recall @{} of {} index: {:.2f}%, took {:.2f}s".format(count, a_name, a_self_recall * 100, secs))
119115

120116
secs, b_self_recall = dt(lambda: b.search(b.vectors, **args).recall(b.keys))
121-
print(
122-
"Self-recall @{} of {} index: {:.2f}%, took {:.2f}s".format(
123-
count, b_name, b_self_recall * 100, secs
124-
)
125-
)
117+
print("Self-recall @{} of {} index: {:.2f}%, took {:.2f}s".format(count, b_name, b_self_recall * 100, secs))
126118

127119
secs, ab_recall = dt(lambda: b.search(a.vectors, **args).recall(b.keys))
128-
print(
129-
"Cross-recall @{} of {} in {}: {:.2f}%, took {:.2f}s".format(
130-
count, a_name, b_name, ab_recall * 100, secs
131-
)
132-
)
120+
print("Cross-recall @{} of {} in {}: {:.2f}%, took {:.2f}s".format(count, a_name, b_name, ab_recall * 100, secs))
133121

134122
secs, ba_recall = dt(lambda: a.search(b.vectors, **args).recall(a.keys))
135-
print(
136-
"Cross-recall @{} of {} in {}: {:.2f}%, took {:.2f}s".format(
137-
count, b_name, a_name, ba_recall * 100, secs
138-
)
139-
)
123+
print("Cross-recall @{} of {} in {}: {:.2f}%, took {:.2f}s".format(count, b_name, a_name, ba_recall * 100, secs))
140124

141125

142126
print("--------------------------------------")
@@ -150,6 +134,4 @@
150134
recall += i == j
151135

152136
recall *= 100.0 / min_elements
153-
print(
154-
f"Took {secs:.2f}s to find {mapping_size:,} pairings with {recall:.2f}% being exact"
155-
)
137+
print(f"Took {secs:.2f}s to find {mapping_size:,} pairings with {recall:.2f}% being exact")

python/scripts/test_distances.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
import numpy as np
33

4+
import usearch
45
from usearch.eval import random_vectors
56
from usearch.index import search
67

python/scripts/test_index.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
import pytest
55
import numpy as np
66

7+
import usearch
78
from usearch.eval import random_vectors, self_recall, SearchStats
8-
from usearch.index import search
9-
109
from usearch.index import (
1110
Index,
1211
MetricKind,

python/scripts/test_jit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import pytest
22
import numpy as np
33

4+
import usearch
45
from usearch.eval import random_vectors
5-
66
from usearch.index import (
77
Index,
88
MetricKind,

python/scripts/test_sparse.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
import numpy as np
33

4+
import usearch
45
from usearch.index import (
56
Index,
67
MetricKind,

python/scripts/test_sqlite.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import sqlite3
22
import json
33
import math
4-
import sys
54

65
import numpy as np
76
import pytest

python/scripts/test_tooling.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import pytest
44
import numpy as np
55

6+
import usearch
67
from usearch.io import load_matrix, save_matrix
78
from usearch.index import search
89
from usearch.eval import random_vectors
9-
1010
from usearch.index import Match, Matches, BatchMatches, Index, Indexes
1111

1212

@@ -70,9 +70,7 @@ def test_exact_search(rows: int, cols: int, k: int, reordered: bool):
7070
reordered_keys = keys
7171

7272
matches: BatchMatches = search(original, original[reordered_keys], k, exact=True)
73-
top_matches = (
74-
[int(m.keys[0]) for m in matches] if rows > 1 else [int(matches.keys[0])]
75-
)
73+
top_matches = [int(m.keys[0]) for m in matches] if rows > 1 else [int(matches.keys[0])]
7674
assert top_matches == list(reordered_keys)
7775

7876
matches: Matches = search(original, original[-1], k, exact=True)

0 commit comments

Comments
 (0)