Skip to content

Commit

Permalink
Add an extra check for angular consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
erikbern committed Apr 11, 2023
1 parent 42a18ea commit e642be3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/distance_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import numpy

from ann_benchmarks.datasets import get_dataset
from ann_benchmarks.distance import metrics


Expand Down Expand Up @@ -40,3 +41,18 @@ def test_angular():
p = numpy.array([7, 0])
q = numpy.array([-8, 0])
assert dist(p, q) == pytest.approx(2)


def test_angular_dataset():
# Make sure distances in the datasets are calculated consistent with the definitions
# This is to avoid issues like #367

dist_f = metrics["angular"]["distance"]

hdf5_f, n_dims = get_dataset("glove-25-angular")

n = 1000
for u, nns, dists in zip(hdf5_f["test"][:n], hdf5_f["neighbors"][:n], hdf5_f["distances"][:n]):
for j, dist in zip(nns, dists):
v = hdf5_f["train"][j]
assert dist_f(u, v) == pytest.approx(dist, rel=1e-4, abs=1e-4)

0 comments on commit e642be3

Please sign in to comment.