From 420a3d70ddb168b21359a6ef25bf4e6d762542cd Mon Sep 17 00:00:00 2001 From: Erik Bernhardsson Date: Mon, 5 Feb 2018 09:05:35 -0500 Subject: [PATCH] fix issue with holes in the index and angular distance --- src/annoylib.h | 3 +++ test/accuracy_test.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/annoylib.h b/src/annoylib.h index f13d9229..454c842a 100644 --- a/src/annoylib.h +++ b/src/annoylib.h @@ -218,6 +218,9 @@ inline void two_means(const vector& nodes, int f, Random& random, bool co T di = ic * Distance::distance(p, nodes[k], f), dj = jc * Distance::distance(q, nodes[k], f); T norm = cosine ? get_norm(nodes[k]->v, f) : 1.0; + if (!(norm > T(0))) { + continue; + } if (di < dj) { for (int z = 0; z < f; z++) p->v[z] = (p->v[z] * ic + nodes[k]->v[z] / norm) / (ic + 1); diff --git a/test/accuracy_test.py b/test/accuracy_test.py index 6581a3d9..92dfe050 100644 --- a/test/accuracy_test.py +++ b/test/accuracy_test.py @@ -75,5 +75,8 @@ def _test_index(self, dataset, exp_accuracy): def test_glove_25(self): self._test_index('glove-25-angular', 69.00) + def test_nytimes_16(self): + self._test_index('nytimes-16-angular', 80.00) + def test_fashion_mnist(self): self._test_index('fashion-mnist-784-euclidean', 90.00)