Skip to content

Commit bf8bd6b

Browse files
Xiao Fufacebook-github-bot
Xiao Fu
authored andcommitted
Delete all remaining print (facebookresearch#3452)
Summary: Pull Request resolved: facebookresearch#3452 Delete all remaining print within the Tests to improve the readability and effectiveness of the codebase. Reviewed By: junjieqi Differential Revision: D57466393 fbshipit-source-id: 6ebd66ae2e769894d810d4ba7a5f69fc865b797d
1 parent 4972abd commit bf8bd6b

13 files changed

+0
-53
lines changed

tests/common_faiss_tests.py

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def evalres(self, DI):
4949
for rank in 1, 10, 100:
5050
e[rank] = ((I[:, :rank] == self.gt.reshape(-1, 1)).sum() /
5151
float(self.nq))
52-
# print("1-recalls: %s" % e)
5352
return e
5453

5554

tests/test_RCQ_cropping.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ TEST(RCQCropping, test_cropping) {
2828
faiss::ResidualCoarseQuantizer rcq(d, nbits);
2929

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

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

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

tests/test_clustering.py

-3
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ def test_weighted(self):
110110
cdis2_first = cdis2[:5].sum()
111111
cdis2_last = cdis2[5:].sum()
112112

113-
print(cdis1_first, cdis1_last)
114-
print(cdis2_first, cdis2_last)
115-
116113
# with the new clustering, the last should be much (*2) closer
117114
# to their centroids
118115
self.assertGreater(cdis1_last, cdis1_first * 2)

tests/test_contrib.py

-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ def test_query_iterator(self, metric=faiss.METRIC_L2):
147147
xb = ds.get_database()
148148
D, I = faiss.knn(xq, xb, 10, metric=metric)
149149
threshold = float(D[:, -1].mean())
150-
print(threshold)
151150

152151
index = faiss.IndexFlat(32, metric)
153152
index.add(xb)
@@ -251,7 +250,6 @@ def test_precision_recall(self):
251250
Inew = np.hstack(Inew)
252251

253252
precision, recall = evaluation.range_PR(lims_ref, Iref, lims_new, Inew)
254-
print(precision, recall)
255253

256254
self.assertEqual(precision, 0.6)
257255
self.assertEqual(recall, 0.6)

tests/test_contrib_with_scipy.py

-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def test_sparse_routines(self):
4444
faiss.normalize_L2(xt)
4545

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

5049
centroids = ds.get_queries()
@@ -72,7 +71,6 @@ def test_sparse_kmeans(self):
7271
faiss.normalize_L2(xt)
7372

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

7876
km = faiss.Kmeans(ds.d, 50)

tests/test_fast_scan.py

-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def test_PQ4_accuracy(self):
3434
nq = Iref.shape[0]
3535
recall_at_1 = (Iref[:, 0] == Ia[:, 0]).sum() / nq
3636
assert recall_at_1 > 0.6
37-
# print(f'recall@1 = {recall_at_1:.3f}')
3837

3938

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

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

504502
def xx_test_accuracy(self):
@@ -531,7 +529,6 @@ def subtest_from_idxaq(self, implem, metric):
531529
nq = Iref.shape[0]
532530
recall_ref = (Iref == gt).sum() / nq
533531
recall1 = (I1 == gt).sum() / nq
534-
print(recall_ref, recall1)
535532
assert abs(recall_ref - recall1) < 0.05
536533

537534
def xx_test_from_idxaq(self):

tests/test_index_composite.py

-3
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ def test_remove_id_map_2(self):
168168
index.remove_ids(remove_set)
169169
index.add_with_ids(X[5:, :], idx[5:])
170170

171-
print (index.search(X, 1))
172-
173171
for i in range(10):
174172
_, searchres = index.search(X[i:i + 1, :], 1)
175173
if idx[i] in remove_set:
@@ -954,7 +952,6 @@ def do_test(self, factory_string):
954952
index.nprobe = 10
955953
Dref, Iref = index.search(ds.get_queries(), 10)
956954

957-
#print(index.search_and_return_codes)
958955
D, I, codes = index.search_and_return_codes(
959956
ds.get_queries(), 10, include_listnos=True)
960957

tests/test_local_search_quantizer.py

-6
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ def test_update_codebooks_with_double(self):
196196
err_float = eval_codec(lsq, xb)
197197

198198
# 6533.377 vs 25457.99
199-
print(err_double, err_float)
200199
self.assertLess(err_double, err_float)
201200

202201
def test_compute_binary_terms(self):
@@ -348,7 +347,6 @@ def test_training(self):
348347
pq.train(xt)
349348
err_pq = eval_codec(pq, xb)
350349

351-
print(err_lsq, err_pq)
352350
self.assertLess(err_lsq, err_pq)
353351

354352

@@ -463,7 +461,6 @@ def eval_index_accuracy(self, factory_key):
463461
index.nprobe = nprobe
464462
D, I = index.search(ds.get_queries(), 10)
465463
inter = faiss.eval_intersection(I, ds.get_groundtruth(10))
466-
# print("nprobe=", nprobe, "inter=", inter)
467464
inters.append(inter)
468465

469466
inters = np.array(inters)
@@ -528,7 +525,6 @@ def test_codec(self):
528525
pq.train(xt)
529526
err_pq = eval_codec(pq, xb)
530527

531-
print(err_plsq, err_pq)
532528
self.assertLess(err_plsq, err_pq)
533529

534530
def test_with_lsq(self):
@@ -549,7 +545,6 @@ def test_with_lsq(self):
549545
lsq.train(xt)
550546
err_lsq = eval_codec(lsq, xb)
551547

552-
print(err_plsq, err_lsq)
553548
self.assertEqual(err_plsq, err_lsq)
554549

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

670664
def test_factory(self):

tests/test_partition.py

-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def do_partition(self, n, q, maxval=None, seed=None):
4949
if seed is None:
5050
for i in range(50):
5151
self.do_partition(n, q, maxval, i + 1234)
52-
# print("seed=", seed)
5352
rs = np.random.RandomState(seed)
5453
if maxval is None:
5554
vals = rs.rand(n).astype('float32')
@@ -95,7 +94,6 @@ def do_partition(self, n, q, maxval=None, seed=None):
9594
if seed is None:
9695
for i in range(50):
9796
self.do_partition(n, q, maxval, i + 1234)
98-
# print("seed=", seed)
9997
rs = np.random.RandomState(seed)
10098
if maxval is None:
10199
vals = rs.rand(n).astype('float32')
@@ -148,7 +146,6 @@ def do_partition(self, n, q, maxval=65536, seed=None):
148146
for i in range(50):
149147
self.do_partition(n, q, maxval, i + 1234)
150148

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

163-
# print("tab a type", tab_a.get())
164160
if type(q) == int:
165161
faiss.CMax_uint16_partition_fuzzy(
166162
tab_a.get(), sp(ids), n, q, q, None)
@@ -196,7 +192,6 @@ def do_partition(self, n, q, maxval=65536, seed=None):
196192
if seed is None:
197193
for i in range(50):
198194
self.do_partition(n, q, maxval, i + 1234)
199-
# print("seed=", seed)
200195
rs = np.random.RandomState(seed)
201196
vals = rs.randint(maxval, size=n).astype('uint16')
202197
ids = (rs.permutation(n) + 12345).astype('int64')
@@ -209,7 +204,6 @@ def do_partition(self, n, q, maxval=65536, seed=None):
209204
vals_inv = (65535 - vals).astype('uint16')
210205
faiss.copy_array_to_AlignedTable(vals_inv, tab_a)
211206

212-
# print("tab a type", tab_a.get())
213207
if type(q) == int:
214208
faiss.CMin_uint16_partition_fuzzy(
215209
tab_a.get(), sp(ids), n, q, q, None)

tests/test_product_quantizer.py

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def test_pq(self):
2626
x2 = pq.decode(codes)
2727
diff = ((x - x2)**2).sum()
2828

29-
# print("diff=", diff)
3029
# diff= 4418.0562
3130
self.assertGreater(5000, diff)
3231

tests/test_residual_quantizer.py

-14
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ def test_training(self):
211211

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

217216
def test_beam_size(self):
@@ -321,10 +320,8 @@ def retrain_AQ_codebook(index, xt):
321320

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

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

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

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

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

506-
# print(err_before, err_after_refined)
507502
# ref run 7474.98 / 7006.1777
508503
self.assertGreater(err_before, err_after_refined * 1.06)
509504

@@ -781,7 +776,6 @@ def test_search_L2(self):
781776
else:
782777
inter_2 = faiss.eval_intersection(I2, gt)
783778
self.assertGreaterEqual(inter_ref, inter_2)
784-
# print(st, inter_ref, inter_2)
785779

786780

787781
###########################################################
@@ -814,7 +808,6 @@ def do_test_accuracy(self, by_residual, st):
814808
index.nprobe = nprobe
815809
D, I = index.search(ds.get_queries(), 10)
816810
inter = faiss.eval_intersection(I, ds.get_groundtruth(10))
817-
# print(st, "nprobe=", nprobe, "inter=", inter)
818811
inters.append(inter)
819812

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

918909
# D2, I2 = index2.search(ds.get_queries(), 10)
919-
# print(D[:5])
920-
# print(D2[:5])
921910

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

@@ -1166,7 +1154,6 @@ def test_codec(self):
11661154
pq.train(xt)
11671155
err_pq = eval_codec(pq, xb)
11681156

1169-
# print(err_prq, err_pq)
11701157
self.assertLess(err_prq, err_pq)
11711158

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

12771263
def test_factory(self):

tests/test_rowwise_minmax.py

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def compare_train_vs_train_inplace(self, factory_key):
4545

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

5049
self.assertLess(reconstruction_err, 0.6)
5150

tests/test_standalone_codec.py

-9
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ def compare_accuracy(self, lowac, highac, max_errs=(1e10, 1e10)):
151151
err = ((x - x2) ** 2).sum()
152152
errs.append(err)
153153

154-
print(errs)
155154
self.assertGreater(errs[0], errs[1])
156155

157156
self.assertGreater(max_errs[0], errs[0])
@@ -214,15 +213,13 @@ def test_repeats(self):
214213
code = repeats.encode(swig_ptr(vec))
215214
vec2 = np.zeros(dim, dtype='float32')
216215
repeats.decode(code, swig_ptr(vec2))
217-
# print(vec2)
218216
assert np.all(vec == vec2)
219217

220218
def test_ZnSphereCodec_encode_centroid(self):
221219
dim = 8
222220
r2 = 5
223221
ref_codec = faiss.ZnSphereCodec(dim, r2)
224222
codec = faiss.ZnSphereCodecRec(dim, r2)
225-
# print(ref_codec.nv, codec.nv)
226223
assert ref_codec.nv == codec.nv
227224
s = set()
228225
for i in range(ref_codec.nv):
@@ -237,7 +234,6 @@ def test_ZnSphereCodecRec(self):
237234
dim = 16
238235
r2 = 6
239236
codec = faiss.ZnSphereCodecRec(dim, r2)
240-
# print("nv=", codec.nv)
241237
for i in range(codec.nv):
242238
c = np.zeros(dim, dtype='float32')
243239
codec.decode(i, swig_ptr(c))
@@ -300,15 +296,10 @@ def test_rw(self):
300296
for i in range(nbyte):
301297
self.assertTrue(((bignum >> (i * 8)) & 255) == bs[i])
302298

303-
#for i in range(nbyte):
304-
# print(bin(bs[i] + 256)[3:], end=' ')
305-
# print()
306-
307299
br = faiss.BitstringReader(swig_ptr(bs), nbyte)
308300

309301
for nbit, xref in ctrl:
310302
xnew = br.read(nbit)
311-
# print('nbit %d xref %x xnew %x' % (nbit, xref, xnew))
312303
self.assertTrue(xnew == xref)
313304

314305
def test_arrays(self):

0 commit comments

Comments
 (0)