Skip to content

Commit

Permalink
Assert that indexes are unique. (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
maumueller committed Jun 17, 2024
1 parent da31331 commit 840c4b0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ann_benchmarks/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def single_query(v: numpy.array) -> Tuple[float, List[Tuple[int, float]]]:
start = time.time()
candidates = algo.query(v, count)
total = time.time() - start

# make sure all returned indices are unique
assert len(candidates) == len(set(candidates)), "Implementation returned duplicated candidates"

candidates = [
(int(idx), float(metrics[distance].distance(v, X_train[idx]))) for idx in candidates # noqa
]
Expand Down Expand Up @@ -105,6 +109,11 @@ def batch_query(X: numpy.array) -> List[Tuple[float, List[Tuple[int, float]]]]:
batch_latencies = algo.get_batch_latencies()
else:
batch_latencies = [total / float(len(X))] * len(X)

# make sure all returned indices are unique
for res in results:
assert len(res) == len(set(res)), "Implementation returned duplicated candidates"

candidates = [
[(int(idx), float(metrics[distance].distance(v, X_train[idx]))) for idx in single_results] # noqa
for v, single_results in zip(X, results)
Expand Down

0 comments on commit 840c4b0

Please sign in to comment.