Skip to content

Commit 5e452ed

Browse files
Xiao Fufacebook-github-bot
Xiao Fu
authored andcommitted
Cleaning up more unnecessary print (facebookresearch#3455)
Summary: Pull Request resolved: facebookresearch#3455 Code quality control by reducing the number of prints Reviewed By: junjieqi Differential Revision: D57502194 fbshipit-source-id: a6cd65ed4cc49590ce73d2978d41b640b5259c17
1 parent e822a8c commit 5e452ed

14 files changed

+0
-105
lines changed

tests/test_binary_hashindex.py

-10
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ def test_hash(self):
5858

5959
Lref, Dref, Iref = index_ref.range_search(xq, radius)
6060

61-
print("nb res: ", Lref[-1])
62-
6361
index = faiss.IndexBinaryHash(d, 10)
6462
index.add(xb)
6563
# index.display()
@@ -80,8 +78,6 @@ def test_hash(self):
8078
self.assertTrue(snew <= set(ref))
8179
nfound.append(Lnew[-1])
8280
ndis.append(stats.ndis)
83-
print('nfound=', nfound)
84-
print('ndis=', ndis)
8581
nfound = np.array(nfound)
8682
self.assertTrue(nfound[-1] == Lref[-1])
8783
self.assertTrue(np.all(nfound[1:] >= nfound[:-1]))
@@ -100,8 +96,6 @@ def test_multihash(self):
10096

10197
Lref, Dref, Iref = index_ref.range_search(xq, radius)
10298

103-
print("nb res: ", Lref[-1])
104-
10599
nfound = []
106100
ndis = []
107101

@@ -123,8 +117,6 @@ def test_multihash(self):
123117
self.assertTrue(snew <= set(ref))
124118
nfound.append(Lnew[-1])
125119
ndis.append(stats.ndis)
126-
print('nfound=', nfound)
127-
print('ndis=', ndis)
128120
nfound = np.array(nfound)
129121
# self.assertTrue(nfound[-1] == Lref[-1])
130122
self.assertTrue(np.all(nfound[1:] >= nfound[:-1]))
@@ -163,7 +155,6 @@ def test_hash_and_multihash(self):
163155
# no duplicates
164156
self.assertTrue(len(new) == len(snew))
165157
nf += len(set(ref) & snew)
166-
print('nfound', nh, nbit, nf)
167158
nfound[(nh, nbit)] = nf
168159
self.assertGreater(nfound[(nh, 4)], nfound[(nh, 7)])
169160

@@ -175,7 +166,6 @@ def test_hash_and_multihash(self):
175166
np.testing.assert_array_equal(Inew, I2)
176167
np.testing.assert_array_equal(Dnew, D2)
177168

178-
print('nfound=', nfound)
179169
self.assertGreater(3, abs(nfound[(0, 7)] - nfound[(1, 7)]))
180170
self.assertGreater(nfound[(3, 7)], nfound[(1, 7)])
181171
self.assertGreater(nfound[(5, 7)], nfound[(3, 7)])

tests/test_build_blocks.py

-15
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ def test_l2(self):
189189
for d in 1, 2, 4, 8, 12, 16:
190190
x = rs.rand(d).astype('float32')
191191
for ny in 128, 129, 130:
192-
print("d=%d ny=%d" % (d, ny))
193192
y = rs.rand(ny, d).astype('float32')
194193
ref = ((x - y) ** 2).sum(1)
195194
new = np.zeros(ny, dtype='float32')
@@ -204,7 +203,6 @@ def test_IP(self):
204203
for d in 1, 2, 4, 8, 12, 16:
205204
x = rs.rand(d).astype('float32')
206205
for ny in 128, 129, 130:
207-
print("d=%d ny=%d" % (d, ny))
208206
y = rs.rand(ny, d).astype('float32')
209207
ref = (x * y).sum(1)
210208
new = np.zeros(ny, dtype='float32')
@@ -220,7 +218,6 @@ def test_0s(self):
220218
m = rs.rand(40, 20).astype('float32')
221219
m[5:10] = 0
222220
comments = faiss.MatrixStats(m).comments
223-
print(comments)
224221
assert 'has 5 copies' in comments
225222
assert '5 null vectors' in comments
226223

@@ -229,31 +226,27 @@ def test_copies(self):
229226
m = rs.rand(40, 20).astype('float32')
230227
m[::2] = m[1::2]
231228
comments = faiss.MatrixStats(m).comments
232-
print(comments)
233229
assert '20 vectors are distinct' in comments
234230

235231
def test_dead_dims(self):
236232
rs = np.random.RandomState(123)
237233
m = rs.rand(40, 20).astype('float32')
238234
m[:, 5:10] = 0
239235
comments = faiss.MatrixStats(m).comments
240-
print(comments)
241236
assert '5 dimensions are constant' in comments
242237

243238
def test_rogue_means(self):
244239
rs = np.random.RandomState(123)
245240
m = rs.rand(40, 20).astype('float32')
246241
m[:, 5:10] += 12345
247242
comments = faiss.MatrixStats(m).comments
248-
print(comments)
249243
assert '5 dimensions are too large wrt. their variance' in comments
250244

251245
def test_normalized(self):
252246
rs = np.random.RandomState(123)
253247
m = rs.rand(40, 20).astype('float32')
254248
faiss.normalize_L2(m)
255249
comments = faiss.MatrixStats(m).comments
256-
print(comments)
257250
assert 'vectors are normalized' in comments
258251

259252
def test_hash(self):
@@ -300,7 +293,6 @@ def test_8bit_equiv(self):
300293
D, I = index.search(x[3:], 1)
301294

302295
# assert D[0, 0] == Dref[0, 0]
303-
# print(D[0, 0], ((x[3] - x[2]) ** 2).sum())
304296
assert D[0, 0] == ((x[3] - x[2]) ** 2).sum()
305297

306298
def test_6bit_equiv(self):
@@ -314,8 +306,6 @@ def test_6bit_equiv(self):
314306
d, faiss.ScalarQuantizer.QT_6bit)
315307
index.train(trainset)
316308

317-
print('cs=', index.code_size)
318-
319309
x = rs.randint(64, size=(100, d)).astype('float32')
320310

321311
# verify encoder / decoder
@@ -330,7 +320,6 @@ def test_6bit_equiv(self):
330320
for i in range(20):
331321
for j in range(10):
332322
dis = ((y[i] - x2[I[i, j]]) ** 2).sum()
333-
# print(dis, D[i, j])
334323
assert abs(D[i, j] - dis) / dis < 1e-5
335324

336325
def test_reconstruct(self):
@@ -371,7 +360,6 @@ def test_randint(self):
371360
x = faiss.randint(20000, vmax=100)
372361
assert np.all(x >= 0) and np.all(x < 100)
373362
c = np.bincount(x, minlength=100)
374-
print(c)
375363
assert c.max() - c.min() < 50 * 2
376364

377365
def test_rand_vector(self):
@@ -473,7 +461,6 @@ def do_test_array_type(self, dtype):
473461
""" tests swig_ptr and rev_swig_ptr for this type of array """
474462
a = np.arange(12).astype(dtype)
475463
ptr = faiss.swig_ptr(a)
476-
print(ptr)
477464
a2 = faiss.rev_swig_ptr(ptr, 12)
478465
np.testing.assert_array_equal(a, a2)
479466

@@ -547,7 +534,6 @@ def subtest(self, d, K, metric):
547534
recalls += 1
548535
break
549536
recall = 1.0 * recalls / (nb * K)
550-
print('Metric: {}, knng accuracy: {}'.format(metric_names[metric], recall))
551537
assert recall > 0.99
552538

553539
def test_small_nndescent(self):
@@ -656,7 +642,6 @@ def do_test_bucket_sort_inplace(
656642
rows, _ = np.where(tab == b)
657643
rows.sort()
658644
tab2[lims[b]:lims[b + 1]].sort()
659-
# print(rows, tab2[lims[b] : lims[b + 1]])
660645
rows = set(rows)
661646
self.assertEqual(rows, set(tab2[lims[b]:lims[b + 1]]))
662647

tests/test_graph_based.py

-7
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ def subtest_add(self, build_type, thresh, metric=faiss.METRIC_L2):
209209
Dnsg, Insg = index.search(self.xq, 1)
210210

211211
recalls = (Iref == Insg).sum()
212-
print('metric: {}, nb equal: {}'.format(metrics[metric], recalls))
213212
self.assertGreaterEqual(recalls, thresh)
214213
self.subtest_connectivity(index, self.xb.shape[0])
215214
self.subtest_io_and_clone(index, Dnsg, Insg)
@@ -230,7 +229,6 @@ def subtest_build(self, knn_graph, thresh, metric=faiss.METRIC_L2):
230229
Dnsg, Insg = index.search(self.xq, 1)
231230

232231
recalls = (Iref == Insg).sum()
233-
print('metric: {}, nb equal: {}'.format(metrics[metric], recalls))
234232
self.assertGreaterEqual(recalls, thresh)
235233
self.subtest_connectivity(index, self.xb.shape[0])
236234

@@ -286,15 +284,13 @@ def test_reset(self):
286284
index.add(self.xb)
287285
Dnsg, Insg = index.search(self.xq, 1)
288286
recalls = (Iref == Insg).sum()
289-
print('metric: {}, nb equal: {}'.format(metrics[metric], recalls))
290287
self.assertGreaterEqual(recalls, 475)
291288
self.subtest_connectivity(index, self.xb.shape[0])
292289

293290
index.reset()
294291
index.add(self.xb)
295292
Dnsg, Insg = index.search(self.xq, 1)
296293
recalls = (Iref == Insg).sum()
297-
print('metric: {}, nb equal: {}'.format(metrics[metric], recalls))
298294
self.assertGreaterEqual(recalls, 475)
299295
self.subtest_connectivity(index, self.xb.shape[0])
300296

@@ -335,7 +331,6 @@ def test_nsg_pq(self):
335331

336332
# test accuracy
337333
recalls = (Iref == I).sum()
338-
print("IndexNSGPQ", recalls)
339334
self.assertGreaterEqual(recalls, 190) # 193
340335

341336
# test I/O
@@ -361,7 +356,6 @@ def test_nsg_sq(self):
361356

362357
# test accuracy
363358
recalls = (Iref == I).sum()
364-
print("IndexNSGSQ", recalls)
365359
self.assertGreaterEqual(recalls, 405) # 411
366360

367361
# test I/O
@@ -395,7 +389,6 @@ def test_nndescentflat(self):
395389

396390
# test accuracy
397391
recalls = (Iref == I).sum()
398-
print("IndexNNDescentFlat", recalls)
399392
self.assertGreaterEqual(recalls, 450) # 462
400393

401394
# do some IO tests

tests/test_index.py

-5
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ def test_4variants_ivf(self):
338338
D, I = index.search(xq, 10)
339339

340340
nok[qname] = (I[:, 0] == I_ref[:, 0]).sum()
341-
print(nok, nq)
342341

343342
self.assertGreaterEqual(nok['flat'], nq * 0.6)
344343
# The tests below are a bit fragile, it happens that the
@@ -373,8 +372,6 @@ def test_4variants(self):
373372
D, I = index.search(xq, 10)
374373
nok[qname] = (I[:, 0] == I_ref[:, 0]).sum()
375374

376-
print(nok, nq)
377-
378375
self.assertGreaterEqual(nok['QT_8bit'], nq * 0.9)
379376
self.assertGreaterEqual(nok['QT_8bit'], nok['QT_4bit'])
380377
self.assertGreaterEqual(nok['QT_8bit'], nok['QT_8bit_uniform'])
@@ -442,7 +439,6 @@ def norm1(x):
442439

443440
recons_err = np.mean(norm1(R_flat - xb[I_flat]))
444441

445-
print('Reconstruction error = %.3f' % recons_err)
446442
if eps is not None:
447443
self.assertLessEqual(recons_err, eps)
448444

@@ -638,7 +634,6 @@ def test_reconstuct_after_add(self):
638634

639635
# should not raise an exception
640636
index.reconstruct(5)
641-
print(index.ntotal)
642637
index.reconstruct(150)
643638

644639

tests/test_index_accuracy.py

-24
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def test_ivf_kmeans(self):
5656
Dref, Iref = ivfk.search(ev.xq, 100)
5757
ivfk.parallel_mode = 1
5858
Dnew, Inew = ivfk.search(ev.xq, 100)
59-
print((Iref != Inew).sum(), Iref.size)
6059
assert (Iref != Inew).sum() < Iref.size / 5000.0
6160
assert np.all(Dref == Dnew)
6261

@@ -136,8 +135,6 @@ def test_polysemous(self):
136135

137136
res = ev.launch("Polysemous ht=%d" % index.polysemous_ht, index)
138137
e_polysemous = ev.evalres(res)
139-
print(e_baseline, e_polysemous, index.polysemous_ht)
140-
print(stats.n_hamming_pass, stats.ncode)
141138
# The randu dataset is difficult, so we are not too picky on
142139
# the results. Here we assert that we have < 10 % loss when
143140
# computing full PQ on fewer than 20% of the data.
@@ -248,7 +245,6 @@ def subtest(self, mt):
248245
index.nprobe = 4 # hopefully more robust than 1
249246
D, I = index.search(xq, 10)
250247
ninter = faiss.eval_intersection(I, gt_I)
251-
print("(%d, %s): %d, " % (mt, repr(qname), ninter))
252248
assert abs(ninter - self.ref_results[(mt, qname)]) <= 10
253249

254250
if qname == "6bit":
@@ -264,7 +260,6 @@ def subtest(self, mt):
264260
radius = float(D[:, -1].max())
265261
else:
266262
radius = float(D[:, -1].min())
267-
# print("radius", radius)
268263

269264
lims, D3, I3 = index.range_search(xq, radius)
270265
ntot = ndiff = 0
@@ -278,14 +273,11 @@ def subtest(self, mt):
278273
Iref = set(I2[i, mask])
279274
ndiff += len(Inew ^ Iref)
280275
ntot += len(Iref)
281-
# print("ndiff %d / %d" % (ndiff, ntot))
282276
assert ndiff < ntot * 0.01
283277

284278
for pm in 1, 2:
285-
# print("parallel_mode=%d" % pm)
286279
index.parallel_mode = pm
287280
lims4, D4, I4 = index.range_search(xq, radius)
288-
# print("sizes", lims4[1:] - lims4[:-1])
289281
for qno in range(len(lims) - 1):
290282
Iref = I3[lims[qno]: lims[qno + 1]]
291283
Inew = I4[lims4[qno]: lims4[qno + 1]]
@@ -485,7 +477,6 @@ def subtest(self, mt):
485477
D, I = index.search(xq, 10)
486478

487479
ninter = faiss.eval_intersection(I, gt_I)
488-
print("(%d, %s): %d, " % (mt, by_residual, ninter))
489480

490481
assert abs(ninter - self.ref_results[mt, by_residual]) <= 3
491482

@@ -499,10 +490,6 @@ def subtest(self, mt):
499490
index.polysemous_ht = 20
500491
D, I = index.search(xq, 10)
501492
ninter = faiss.eval_intersection(I, gt_I)
502-
print(
503-
"(%d, %s, %d): %d, "
504-
% (mt, by_residual, index.polysemous_ht, ninter)
505-
)
506493

507494
# polysemous behaves bizarrely on ARM
508495
assert (
@@ -516,7 +503,6 @@ def subtest(self, mt):
516503
radius = float(D[:, -1].max())
517504
else:
518505
radius = float(D[:, -1].min())
519-
print("radius", radius)
520506

521507
lims, D3, I3 = index.range_search(xq, radius)
522508
ntot = ndiff = 0
@@ -530,7 +516,6 @@ def subtest(self, mt):
530516
Iref = set(I2[i, mask])
531517
ndiff += len(Inew ^ Iref)
532518
ntot += len(Iref)
533-
print("ndiff %d / %d" % (ndiff, ntot))
534519
assert ndiff < ntot * 0.02
535520

536521
def test_IVFPQ_non8bit(self):
@@ -555,7 +540,6 @@ def test_IVFPQ_non8bit(self):
555540

556541
D, I = index.search(xq, 10)
557542
ninter[v] = faiss.eval_intersection(I, gt_I)
558-
print("ninter=", ninter)
559543
# this should be the case but we don't observe
560544
# that... Probavly too few test points
561545
# assert ninter['2x8'] > ninter['8x2']
@@ -623,9 +607,6 @@ def test_OPQ(self):
623607
res = ev.launch("OPQ", index)
624608
e_opq = ev.evalres(res)
625609

626-
print("e_pq=%s" % e_pq)
627-
print("e_opq=%s" % e_opq)
628-
629610
# verify that OPQ better than PQ
630611
for r in 1, 10, 100:
631612
assert e_opq[r] > e_pq[r]
@@ -656,7 +637,6 @@ def test_OIVFPQ(self):
656637

657638
# verify same on OIVFPQ
658639
for r in 1, 10, 100:
659-
print(e_oivfpq[r], e_ivfpq[r])
660640
assert e_oivfpq[r] >= e_ivfpq[r]
661641

662642

@@ -758,9 +738,6 @@ def test_sh(self):
758738
ninter = faiss.eval_intersection(I, gt_I)
759739
key = (nbit, tt, period)
760740

761-
print("(%d, %s, %g): %d, " % (nbit, repr(tt), period,
762-
ninter))
763-
print(abs(ninter - self.ref_results[key]))
764741
assert abs(ninter - self.ref_results[key]) <= 14
765742

766743

@@ -799,7 +776,6 @@ def do_test(self, metric):
799776
# check that with refinement, the recall@10 is the same as
800777
# the original recall@100
801778
recall2 = (I2 == Iref[:, :1]).sum()
802-
# print("recalls", recall1, recall2)
803779
self.assertEqual(recall1, recall2)
804780

805781
def test_IP(self):

tests/test_io.py

-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ def test_buf_read(self):
102102
reader = faiss.BufferedIOReader(reader, bsz)
103103

104104
y = np.zeros_like(x)
105-
print('nbytes=', y.nbytes)
106105
reader(faiss.swig_ptr(y), y.nbytes, 1)
107106

108107
np.testing.assert_array_equal(x, y)

tests/test_ivflib.py

-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ def test_range_search_with_parameters(self):
125125

126126
Dpre, _ = index.search(xq, 15)
127127
radius = float(np.median(Dpre[:, -1]))
128-
print("Radius=", radius)
129128
stats = faiss.cvar.indexIVF_stats
130129
stats.reset()
131130
Lref, Dref, Iref = index.range_search(xq, radius)

0 commit comments

Comments
 (0)