Skip to content

Commit

Permalink
Merge pull request #283 from spotify/n-items-issue
Browse files Browse the repository at this point in the history
Fix issue with _n_items for index with missing vectors
  • Loading branch information
erikbern authored Mar 31, 2018
2 parents 00c20dc + e085a0b commit 536f342
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/annoylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ template<typename S, typename T, typename Distance, typename Random>
_allocate_size(_n_nodes + 1);
S item = _n_nodes++;
Node* m = _get(item);
m->n_descendants = (S)indices.size();
m->n_descendants = is_root ? _n_items : (S)indices.size();

// Using std::copy instead of a loop seems to resolve issues #3 and #13,
// probably because gcc 4.8 goes overboard with optimizations.
Expand Down Expand Up @@ -814,7 +814,7 @@ template<typename S, typename T, typename Distance, typename Random>

int flip = (children_indices[0].size() > children_indices[1].size());

m->n_descendants = (S)indices.size();
m->n_descendants = is_root ? _n_items : (S)indices.size();
for (int side = 0; side < 2; side++)
// run _make_tree for the smallest child first (for cache locality)
m->children[side^flip] = _make_tree(children_indices[side^flip], false);
Expand Down
2 changes: 0 additions & 2 deletions test/index_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import random
from common import TestCase
from annoy import AnnoyIndex
from nose.plugins.skip import SkipTest


class IndexTest(TestCase):
Expand Down Expand Up @@ -99,7 +98,6 @@ def test_metric_kwarg(self):
def test_metric_f_kwargs(self):
i = AnnoyIndex(f=3, metric='euclidean')

@SkipTest
def test_item_vector_after_save(self):
# Issue #279
a = AnnoyIndex(3)
Expand Down

0 comments on commit 536f342

Please sign in to comment.