faiss/tests/test_contrib.py
Lucas Hosseini e5d2defaae Disable contrib tests for python2. (#1364)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/1364

Test Plan: Imported from OSS

Reviewed By: mdouze

Differential Revision: D23314732

Pulled By: beauby

fbshipit-source-id: 788465c353bbc65947a6c766e8509f35f35e4134
2020-08-25 16:58:24 -07:00

34 lines
940 B
Python

import faiss
import unittest
import numpy as np
import platform
from common import get_dataset_2
try:
from faiss.contrib.exhaustive_search import knn_ground_truth
except:
pass # Submodule import broken in python 2.
@unittest.skipIf(platform.python_version_tuple()[0] < '3', \
'Submodule import broken in python 2.')
class TestComputeGT(unittest.TestCase):
def test_compute_GT(self):
d = 64
xt, xb, xq = get_dataset_2(d, 0, 10000, 100)
index = faiss.IndexFlatL2(d)
index.add(xb)
Dref, Iref = index.search(xq, 10)
# iterator function on the matrix
def matrix_iterator(xb, bs):
for i0 in range(0, xb.shape[0], bs):
yield xb[i0:i0 + bs]
Dnew, Inew = knn_ground_truth(xq, matrix_iterator(xb, 1000), 10)
np.testing.assert_array_equal(Iref, Inew)
np.testing.assert_almost_equal(Dref, Dnew, decimal=5)