Skip to content

Commit c9cff00

Browse files
Adding test for IndexBinaryFlat.reconstruct_n() (#3310)
Summary: Pull Request resolved: facebookresearch/faiss#3310 **Context** [Issue 2751](facebookresearch/faiss#2751) is already fixed as class wrappers has replacement definition of reconstruct_n in handle_IndexBinary. **In this diff**, Writing test test_reconstruct for binary index to validate fix for above issue. Reviewed By: junjieqi Differential Revision: D55168600 fbshipit-source-id: b62dc5fa89d65b843c52faa7456f046142e34421
1 parent 54eb9c2 commit c9cff00

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

tests/test_index_binary.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ def test_range_search(self):
143143
# nb tests is actually low...
144144
self.assertTrue(nt1 > 19 and nt2 > 19)
145145

146+
def test_reconstruct(self):
147+
index = faiss.IndexBinaryFlat(64)
148+
input_vector = np.random.randint(0, 255, size=(10, index.code_size)).astype("uint8")
149+
index.add(input_vector)
150+
151+
reconstructed_vector = index.reconstruct_n(0, 4)
152+
assert reconstructed_vector.shape == (4, index.code_size)
153+
assert np.all(input_vector[:4] == reconstructed_vector)
154+
146155

147156
class TestBinaryIVF(unittest.TestCase):
148157

0 commit comments

Comments
 (0)