matsui528 / nanopq

Pure python implementation of product quantization for nearest neighbor search
MIT License
327 stars 43 forks source link

Fix a bug to use faiss #32

Closed matsui528 closed 1 year ago

matsui528 commented 1 year ago

Even when faiss is not installed, faiss.METRIC_L2 is always called, causing the error. This PR fixes it.

Before this PR:

$ make test 

...

tests/test_pq.py:7: in <module>
    import nanopq
nanopq/__init__.py:4: in <module>
    from .convert_faiss import faiss_to_nanopq, nanopq_to_faiss
nanopq/convert_faiss.py:16: in <module>
    "l2": faiss.METRIC_L2,
E   NameError: name 'faiss' is not defined
============================================================ short test summary info =============================================================
ERROR tests/test_convert_faiss.py - NameError: name 'faiss' is not defined
ERROR tests/test_opq.py - NameError: name 'faiss' is not defined
ERROR tests/test_pq.py - NameError: name 'faiss' is not defined
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 3 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=============================================================== 3 errors in 0.51s ================================================================
make: *** [Makefile:4: test] Error 2

With this PR:

$ make test

...

tests/test_opq.py .....                                                                                                                                                                                               [ 41%]
tests/test_pq.py .......                                                                                                                                                                                              [100%]

=============================================================================================== 12 passed, 1 skipped in 0.28s ===============================================================================================