Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tests/common_faiss_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def evalres(self, DI):
for rank in 1, 10, 100:
e[rank] = ((I[:, :rank] == self.gt.reshape(-1, 1)).sum() /
float(self.nq))
# print("1-recalls: %s" % e)
return e


Expand Down
2 changes: 0 additions & 2 deletions tests/test_RCQ_cropping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ TEST(RCQCropping, test_cropping) {
faiss::ResidualCoarseQuantizer rcq(d, nbits);

rcq.train(nt, xt);
// fprintf(stderr, "nb centroids: %zd\n", rcq.ntotal);

// the test below works only for beam size == nprobe
rcq.set_beam_factor(1.0);
Expand All @@ -44,7 +43,6 @@ TEST(RCQCropping, test_cropping) {
nbits.pop_back();
faiss::ResidualCoarseQuantizer rcq_cropped(d, nbits);
rcq_cropped.initialize_from(rcq);
// fprintf(stderr, "cropped nb centroids: %zd\n", rcq_cropped.ntotal);

EXPECT_EQ(rcq_cropped.ntotal, rcq.ntotal >> last_nbits);

Expand Down
3 changes: 0 additions & 3 deletions tests/test_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ def test_weighted(self):
cdis2_first = cdis2[:5].sum()
cdis2_last = cdis2[5:].sum()

print(cdis1_first, cdis1_last)
print(cdis2_first, cdis2_last)

# with the new clustering, the last should be much (*2) closer
# to their centroids
self.assertGreater(cdis1_last, cdis1_first * 2)
Expand Down
2 changes: 0 additions & 2 deletions tests/test_contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ def test_query_iterator(self, metric=faiss.METRIC_L2):
xb = ds.get_database()
D, I = faiss.knn(xq, xb, 10, metric=metric)
threshold = float(D[:, -1].mean())
print(threshold)

index = faiss.IndexFlat(32, metric)
index.add(xb)
Expand Down Expand Up @@ -251,7 +250,6 @@ def test_precision_recall(self):
Inew = np.hstack(Inew)

precision, recall = evaluation.range_PR(lims_ref, Iref, lims_new, Inew)
print(precision, recall)

self.assertEqual(precision, 0.6)
self.assertEqual(recall, 0.6)
Expand Down
2 changes: 0 additions & 2 deletions tests/test_contrib_with_scipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def test_sparse_routines(self):
faiss.normalize_L2(xt)

mask = np.abs(xt) > 0.045
# print("fraction:", mask.sum() / mask.size) # around 10% non-zeros
xt[np.logical_not(mask)] = 0

centroids = ds.get_queries()
Expand Down Expand Up @@ -72,7 +71,6 @@ def test_sparse_kmeans(self):
faiss.normalize_L2(xt)

mask = np.abs(xt) > 0.045
# print("fraction:", mask.sum() / mask.size) # around 10% non-zeros
xt[np.logical_not(mask)] = 0

km = faiss.Kmeans(ds.d, 50)
Expand Down
3 changes: 0 additions & 3 deletions tests/test_fast_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def test_PQ4_accuracy(self):
nq = Iref.shape[0]
recall_at_1 = (Iref[:, 0] == Ia[:, 0]).sum() / nq
assert recall_at_1 > 0.6
# print(f'recall@1 = {recall_at_1:.3f}')


# This is an experiment to see if we can catch performance
Expand Down Expand Up @@ -498,7 +497,6 @@ def subtest_accuracy(self, aq, st, implem, metric_type='L2'):
recall_ref = (Iref == gt).sum() / nq
recall = (Ia == gt).sum() / nq

print(aq, st, implem, metric_type, recall_ref, recall)
assert abs(recall_ref - recall) < 0.05

def xx_test_accuracy(self):
Expand Down Expand Up @@ -531,7 +529,6 @@ def subtest_from_idxaq(self, implem, metric):
nq = Iref.shape[0]
recall_ref = (Iref == gt).sum() / nq
recall1 = (I1 == gt).sum() / nq
print(recall_ref, recall1)
assert abs(recall_ref - recall1) < 0.05

def xx_test_from_idxaq(self):
Expand Down
3 changes: 0 additions & 3 deletions tests/test_index_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ def test_remove_id_map_2(self):
index.remove_ids(remove_set)
index.add_with_ids(X[5:, :], idx[5:])

print (index.search(X, 1))

for i in range(10):
_, searchres = index.search(X[i:i + 1, :], 1)
if idx[i] in remove_set:
Expand Down Expand Up @@ -954,7 +952,6 @@ def do_test(self, factory_string):
index.nprobe = 10
Dref, Iref = index.search(ds.get_queries(), 10)

#print(index.search_and_return_codes)
D, I, codes = index.search_and_return_codes(
ds.get_queries(), 10, include_listnos=True)

Expand Down
6 changes: 0 additions & 6 deletions tests/test_local_search_quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ def test_update_codebooks_with_double(self):
err_float = eval_codec(lsq, xb)

# 6533.377 vs 25457.99
print(err_double, err_float)
self.assertLess(err_double, err_float)

def test_compute_binary_terms(self):
Expand Down Expand Up @@ -348,7 +347,6 @@ def test_training(self):
pq.train(xt)
err_pq = eval_codec(pq, xb)

print(err_lsq, err_pq)
self.assertLess(err_lsq, err_pq)


Expand Down Expand Up @@ -463,7 +461,6 @@ def eval_index_accuracy(self, factory_key):
index.nprobe = nprobe
D, I = index.search(ds.get_queries(), 10)
inter = faiss.eval_intersection(I, ds.get_groundtruth(10))
# print("nprobe=", nprobe, "inter=", inter)
inters.append(inter)

inters = np.array(inters)
Expand Down Expand Up @@ -528,7 +525,6 @@ def test_codec(self):
pq.train(xt)
err_pq = eval_codec(pq, xb)

print(err_plsq, err_pq)
self.assertLess(err_plsq, err_pq)

def test_with_lsq(self):
Expand All @@ -549,7 +545,6 @@ def test_with_lsq(self):
lsq.train(xt)
err_lsq = eval_codec(lsq, xb)

print(err_plsq, err_lsq)
self.assertEqual(err_plsq, err_lsq)

def test_lut(self):
Expand Down Expand Up @@ -664,7 +659,6 @@ def test_index_accuracy2(self):
"""check that the error is in the same ballpark as LSQ."""
inter1 = self.eval_index_accuracy("IVF32,PLSQ2x2x5_Nqint8")
inter2 = self.eval_index_accuracy("IVF32,LSQ4x5_Nqint8")
# print(inter1, inter2) # 381 vs 374
self.assertGreaterEqual(inter1 * 1.1, inter2)

def test_factory(self):
Expand Down
6 changes: 0 additions & 6 deletions tests/test_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def do_partition(self, n, q, maxval=None, seed=None):
if seed is None:
for i in range(50):
self.do_partition(n, q, maxval, i + 1234)
# print("seed=", seed)
rs = np.random.RandomState(seed)
if maxval is None:
vals = rs.rand(n).astype('float32')
Expand Down Expand Up @@ -95,7 +94,6 @@ def do_partition(self, n, q, maxval=None, seed=None):
if seed is None:
for i in range(50):
self.do_partition(n, q, maxval, i + 1234)
# print("seed=", seed)
rs = np.random.RandomState(seed)
if maxval is None:
vals = rs.rand(n).astype('float32')
Expand Down Expand Up @@ -148,7 +146,6 @@ def do_partition(self, n, q, maxval=65536, seed=None):
for i in range(50):
self.do_partition(n, q, maxval, i + 1234)

# print("seed=", seed)
rs = np.random.RandomState(seed)
vals = rs.randint(maxval, size=n).astype('uint16')
ids = (rs.permutation(n) + 12345).astype('int64')
Expand All @@ -160,7 +157,6 @@ def do_partition(self, n, q, maxval=65536, seed=None):
tab_a = faiss.AlignedTableUint16()
faiss.copy_array_to_AlignedTable(vals, tab_a)

# print("tab a type", tab_a.get())
if type(q) == int:
faiss.CMax_uint16_partition_fuzzy(
tab_a.get(), sp(ids), n, q, q, None)
Expand Down Expand Up @@ -196,7 +192,6 @@ def do_partition(self, n, q, maxval=65536, seed=None):
if seed is None:
for i in range(50):
self.do_partition(n, q, maxval, i + 1234)
# print("seed=", seed)
rs = np.random.RandomState(seed)
vals = rs.randint(maxval, size=n).astype('uint16')
ids = (rs.permutation(n) + 12345).astype('int64')
Expand All @@ -209,7 +204,6 @@ def do_partition(self, n, q, maxval=65536, seed=None):
vals_inv = (65535 - vals).astype('uint16')
faiss.copy_array_to_AlignedTable(vals_inv, tab_a)

# print("tab a type", tab_a.get())
if type(q) == int:
faiss.CMin_uint16_partition_fuzzy(
tab_a.get(), sp(ids), n, q, q, None)
Expand Down
1 change: 0 additions & 1 deletion tests/test_product_quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def test_pq(self):
x2 = pq.decode(codes)
diff = ((x - x2)**2).sum()

# print("diff=", diff)
# diff= 4418.0562
self.assertGreater(5000, diff)

Expand Down
14 changes: 0 additions & 14 deletions tests/test_residual_quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ def test_training(self):

# in practice RQ is often better than PQ but it does not the case here, so just check
# that we are within some factor.
# print(err_pq, err_rq)
self.assertLess(err_rq, err_pq * 1.2)

def test_beam_size(self):
Expand Down Expand Up @@ -321,10 +320,8 @@ def retrain_AQ_codebook(index, xt):

x_decoded = index.sa_decode(codes_packed)
MSE = ((xt - x_decoded) ** 2).sum() / n
# print(f"Initial MSE on training set: {MSE:g}")

codes = unpack_codes(index.rq, codes_packed)
# print("ref codes", codes[0])
codebook_offsets = faiss.vector_to_array(rq.codebook_offsets)

# build sparse code matrix (represented as a dense matrix)
Expand All @@ -343,7 +340,6 @@ def retrain_AQ_codebook(index, xt):
B, residuals, rank, singvals = scipy.linalg.lstsq(C, xt, )

MSE = ((C @ B - xt) ** 2).sum() / n
# print(f"MSE after retrainining: {MSE:g}")

# replace codebook
# faiss.copy_array_to_vector(B.astype('float32').ravel(), index.rq.codebooks)
Expand Down Expand Up @@ -503,7 +499,6 @@ def test_reestimate_codebook_2(self):
xt_decoded = ir.sa_decode(ir.sa_encode(xt))
err_after_refined = ((xt - xt_decoded) ** 2).sum()

# print(err_before, err_after_refined)
# ref run 7474.98 / 7006.1777
self.assertGreater(err_before, err_after_refined * 1.06)

Expand Down Expand Up @@ -781,7 +776,6 @@ def test_search_L2(self):
else:
inter_2 = faiss.eval_intersection(I2, gt)
self.assertGreaterEqual(inter_ref, inter_2)
# print(st, inter_ref, inter_2)


###########################################################
Expand Down Expand Up @@ -814,7 +808,6 @@ def do_test_accuracy(self, by_residual, st):
index.nprobe = nprobe
D, I = index.search(ds.get_queries(), 10)
inter = faiss.eval_intersection(I, ds.get_groundtruth(10))
# print(st, "nprobe=", nprobe, "inter=", inter)
inters.append(inter)

# do a little I/O test
Expand Down Expand Up @@ -909,18 +902,13 @@ def do_test_accuracy_IP(self, by_residual):
D, I = index.search(ds.get_queries(), 10)
index.rq.search_type = faiss.AdditiveQuantizer.ST_LUT_nonorm
D2, I2 = index.search(ds.get_queries(), 10)
# print(D[:5] - D2[:5])
# print(I[:5])
np.testing.assert_array_almost_equal(D, D2, decimal=5)
# there are many ties because the codes are so short
self.assertLess((I != I2).sum(), I.size * 0.1)

# D2, I2 = index2.search(ds.get_queries(), 10)
# print(D[:5])
# print(D2[:5])

inter = faiss.eval_intersection(I, ds.get_groundtruth(10))
# print("nprobe=", nprobe, "inter=", inter)
inters.append(inter)
self.assertTrue(np.all(inters[1:4] >= inters[:3]))

Expand Down Expand Up @@ -1166,7 +1154,6 @@ def test_codec(self):
pq.train(xt)
err_pq = eval_codec(pq, xb)

# print(err_prq, err_pq)
self.assertLess(err_prq, err_pq)

def test_with_rq(self):
Expand Down Expand Up @@ -1271,7 +1258,6 @@ def test_index_accuracy2(self):
"""check that the error is in the same ballpark as RQ."""
inter1 = self.eval_index_accuracy("IVF100,PRQ2x2x5_Nqint8")
inter2 = self.eval_index_accuracy("IVF100,RQ4x5_Nqint8")
# print(inter1, inter2) # 392 vs 374
self.assertGreaterEqual(inter1 * 1.1, inter2)

def test_factory(self):
Expand Down
1 change: 0 additions & 1 deletion tests/test_rowwise_minmax.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def compare_train_vs_train_inplace(self, factory_key):

# make sure that the reconstruction error is not crazy
reconstruction_err = ((x - decoded) ** 2).sum()
print(reconstruction_err)

self.assertLess(reconstruction_err, 0.6)

Expand Down
9 changes: 0 additions & 9 deletions tests/test_standalone_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def compare_accuracy(self, lowac, highac, max_errs=(1e10, 1e10)):
err = ((x - x2) ** 2).sum()
errs.append(err)

print(errs)
self.assertGreater(errs[0], errs[1])

self.assertGreater(max_errs[0], errs[0])
Expand Down Expand Up @@ -214,15 +213,13 @@ def test_repeats(self):
code = repeats.encode(swig_ptr(vec))
vec2 = np.zeros(dim, dtype='float32')
repeats.decode(code, swig_ptr(vec2))
# print(vec2)
assert np.all(vec == vec2)

def test_ZnSphereCodec_encode_centroid(self):
dim = 8
r2 = 5
ref_codec = faiss.ZnSphereCodec(dim, r2)
codec = faiss.ZnSphereCodecRec(dim, r2)
# print(ref_codec.nv, codec.nv)
assert ref_codec.nv == codec.nv
s = set()
for i in range(ref_codec.nv):
Expand All @@ -237,7 +234,6 @@ def test_ZnSphereCodecRec(self):
dim = 16
r2 = 6
codec = faiss.ZnSphereCodecRec(dim, r2)
# print("nv=", codec.nv)
for i in range(codec.nv):
c = np.zeros(dim, dtype='float32')
codec.decode(i, swig_ptr(c))
Expand Down Expand Up @@ -300,15 +296,10 @@ def test_rw(self):
for i in range(nbyte):
self.assertTrue(((bignum >> (i * 8)) & 255) == bs[i])

#for i in range(nbyte):
# print(bin(bs[i] + 256)[3:], end=' ')
# print()

br = faiss.BitstringReader(swig_ptr(bs), nbyte)

for nbit, xref in ctrl:
xnew = br.read(nbit)
# print('nbit %d xref %x xnew %x' % (nbit, xref, xnew))
self.assertTrue(xnew == xref)

def test_arrays(self):
Expand Down