Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug with "get_nns_by_item"? #114

Closed
Horace89 opened this issue Nov 12, 2015 · 14 comments
Closed

bug with "get_nns_by_item"? #114

Horace89 opened this issue Nov 12, 2015 · 14 comments

Comments

@Horace89
Copy link

Hi. I think I have uncovered a bug in "get_nns_by_item". Here is my code to reproduce it.
The bug does not seem to appear in "get_nns_by_vector".

import random


import annoy
DIM = 50
t = annoy.AnnoyIndex(DIM, metric='angular')  # Length of item vector that will be indexed

for i in range(100):
    v = [random.gauss(0, 1) for _ in range(DIM)]
    t.add_item(i, v)

t.build(10)

print('nb_items:', t.get_n_items())

#BUG Annoy : TypeError: get_nns_by_item() takes no keyword arguments

#works...
#res1 = t.get_nns_by_item(50, 3, -1, True)
#does not work:
res1 = t.get_nns_by_item(50, 3, search_k=-1, include_distances=True)
print('res1:', res1)

#both calls work with get_nns_by_vector:
vq = [random.gauss(0, 1) for _ in range(DIM)]
res2a = t.get_nns_by_vector(vq, 2, -1, True)
res2b = t.get_nns_by_vector(vq, 2, search_k=-1, include_distances=True)
print('res2a:', res2a)
print('res2b:', res2b)
@erikbern
Copy link
Collaborator

Did you try the latest code? I think I actually fixed this yesterday

ae74624

@erikbern
Copy link
Collaborator

The underlying python C extension doesn't handle kw arguments so well but I solved it by a dumb wrapper on the Python side

@Horace89
Copy link
Author

ok, I'll test it again tomorrow. Thank you.

@Horace89
Copy link
Author

Yes, I confirm that I use the latest version of Annoy (1.5.2), and the described bug still occurs. I'm on Python 3.4.3.

@erikbern
Copy link
Collaborator

When I meant latest version I meant bleeding edge github master.

I updated master but didn't push it to pypi. I can bump the version and
push. I keep forgetting to do that so in glad you reminded me :)

On Friday, November 13, 2015, Horace89 notifications@github.com wrote:

Yes, I confirm that I use the latest version of Annoy (1.5.2), and the
described bug still occurs. I'm on Python 3.4.3.


Reply to this email directly or view it on GitHub
#114 (comment).

@erikbern
Copy link
Collaborator

I bumped the version to 1.6.0 and pushed it to PyPI

@dudevil
Copy link

dudevil commented Nov 13, 2015

@erikbern
I'm having trouble installing annoy through pip after this update:

Installing collected packages: annoy
  Found existing installation: annoy 1.5.2
    Uninstalling annoy:
      Successfully uninstalled annoy
  Running setup.py install for annoy
    building 'annoy.annoylib' extension
    x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/annoymodule.cc -o build/temp.linux-x86_64-2.7/src/annoymodule.o -O3 -march=native -ffast-math
    cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
    src/annoymodule.cc:16:24: fatal error: kissrandom.h: No such file or directory
     #include "kissrandom.h"
                            ^
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Clonning and running python setup.py install works fine.

@erikbern
Copy link
Collaborator

let me take a look at it

@erikbern
Copy link
Collaborator

I had forgotten to include src/kissrandom.h in setup.py.

I added it and pushed 1.6.1.

Sorry about the inconvenience

@erikbern
Copy link
Collaborator

hm still not working – not sure what's going on. let me try again

@erikbern
Copy link
Collaborator

try again – had to bump to 1.6.2 :(

@dudevil
Copy link

dudevil commented Nov 13, 2015

Works great now. Thanks for the quick fix!

@piskvorky
Copy link
Contributor

That's what I call rapid development! :)

Btw PyPI treats rc1, rc2 tags as proper releases, which pip will ignore when users ask to install (a good option for release checking).

@Horace89
Copy link
Author

It's working great now! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants