Skip to content

Commit a7d91d4

Browse files
limqiyingmeta-codesync[bot]
authored andcommitted
black -l 80: tests/ formatting (2/3) (#5427)
Summary: Pull Request resolved: #5427 # this is a no-op change Part 2 of a 3-diff split of the faiss `black -l 80` reformat into small, reviewable diffs (each 3-4 files, <100 changed lines). Follow-up to D109736099 (landed), which formatted the faiss Python tree; these files drifted or are new. Ran `black -l 80` (line length 80, matching faiss's `CONTRIBUTING.md`: "80 character line length (both for C++ and Python)") over the test files: `tests/test_build_blocks.py`, `tests/test_contrib.py`, `tests/test_eden.py`, `tests/test_ivf_flat_panorama.py`. Pure-formatting only. `black`'s AST-equivalence safety check guarantees no identifier, string/numeric value, operator, or control-flow change — only whitespace, wrapping, trailing commas, and quote normalization. Independently verified: `ast.dump` equality (docstrings normalized) and comment-content preservation. `fbcode/faiss/` is excluded from Meta's standard Python autoformatter (it mirrors to public GitHub), so `black -l 80` is the correct tool. ___ Reviewed By: trang-nm-nguyen Differential Revision: D112191719 fbshipit-source-id: 20fc89768077a16fb6abd6c2fe58981c3febf0ea
1 parent 259fa85 commit a7d91d4

4 files changed

Lines changed: 23 additions & 15 deletions

File tree

tests/test_build_blocks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,14 +669,14 @@ def test_small(self):
669669

670670
def xx_test_large(self):
671671
# don't run by default because it's slow
672-
self.do_test(2 ** 21, 10 ** 6)
672+
self.do_test(2**21, 10**6)
673673

674674

675675
class TestRanklistIntersectionSize(unittest.TestCase):
676676

677677
def _intersect(self, v1, v2):
678-
a = np.array(v1, dtype='int64')
679-
b = np.array(v2, dtype='int64')
678+
a = np.array(v1, dtype="int64")
679+
b = np.array(v2, dtype="int64")
680680
return faiss.ranklist_intersection_size(
681681
len(a), faiss.swig_ptr(a), len(b), faiss.swig_ptr(b)
682682
)
@@ -706,5 +706,5 @@ def test_negative_values_not_counted(self):
706706

707707
def test_ids_above_2_pow_60(self):
708708
# the old bit-flag trick corrupted IDs with bit 60 set
709-
v1, v2 = [2 ** 60, 2 ** 61, 2 ** 62], [2 ** 61, 2 ** 62, 2 ** 63 - 1]
709+
v1, v2 = [2**60, 2**61, 2**62], [2**61, 2**62, 2**63 - 1]
710710
self.assertEqual(self._intersect(v1, v2), self._expected(v1, v2))

tests/test_contrib.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,7 @@ def test_equal_time_better_perf_shadows(self):
319319
pts = op.operating_points
320320
for _, pi, ti in pts:
321321
for _, pj, tj in pts:
322-
self.assertFalse(
323-
pj >= pi and tj <= ti and (pj > pi or tj < ti))
322+
self.assertFalse(pj >= pi and tj <= ti and (pj > pi or tj < ti))
324323

325324

326325
class TestPreassigned(unittest.TestCase):
@@ -933,13 +932,19 @@ def test_scalar_quantizer_types(self):
933932
def test_get_code_size_hnsw_non_default_m(self):
934933
d = 128
935934
# Non-default M values previously raised RuntimeError("cannot parse HNSW16")
936-
self.assertEqual(factory_tools.get_code_size(d, "HNSW16"), d * 4 + 16 * 2 * 4)
937-
self.assertEqual(factory_tools.get_code_size(d, "HNSW64"), d * 4 + 64 * 2 * 4)
935+
self.assertEqual(
936+
factory_tools.get_code_size(d, "HNSW16"), d * 4 + 16 * 2 * 4
937+
)
938+
self.assertEqual(
939+
factory_tools.get_code_size(d, "HNSW64"), d * 4 + 64 * 2 * 4
940+
)
938941
self.assertEqual(
939942
factory_tools.get_code_size(d, "HNSW16,Flat"), d * 4 + 16 * 2 * 4
940943
)
941944
# HNSW32 backward compat: formula generalizes correctly
942-
self.assertEqual(factory_tools.get_code_size(d, "HNSW32"), d * 4 + 32 * 2 * 4)
945+
self.assertEqual(
946+
factory_tools.get_code_size(d, "HNSW32"), d * 4 + 32 * 2 * 4
947+
)
943948

944949
def test_get_code_size_ivf_hnsw_non_default_m(self):
945950
d = 128
@@ -948,7 +953,8 @@ def test_get_code_size_ivf_hnsw_non_default_m(self):
948953
factory_tools.get_code_size(d, "IVF64_HNSW16,Flat"), d * 4
949954
)
950955
self.assertEqual(
951-
factory_tools.get_code_size(d, "IVF64_HNSW64,PQ8x8"), (8 * 8 + 7) // 8
956+
factory_tools.get_code_size(d, "IVF64_HNSW64,PQ8x8"),
957+
(8 * 8 + 7) // 8,
952958
)
953959

954960
def test_get_code_size_hnsw_roundtrip(self):

tests/test_eden.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ def eden_reference_reconstruct(x, bits, center=None, scale_type="unbiased"):
6363
return out
6464

6565

66-
def eden_reference_l2_distances(x, query, bits, center=None, scale_type="unbiased"):
66+
def eden_reference_l2_distances(
67+
x, query, bits, center=None, scale_type="unbiased"
68+
):
6769
x = np.asarray(x, dtype="float32")
6870
query = np.asarray(query, dtype="float32")
6971
if center is None:
@@ -205,9 +207,7 @@ def test_factory_flat_and_ivf(self):
205207
self.assertTrue(np.any(I >= 0))
206208

207209
def test_search_matches_none_simd_level(self):
208-
if not faiss.SIMDConfig.is_simd_level_available(
209-
faiss.SIMDLevel_NONE
210-
):
210+
if not faiss.SIMDConfig.is_simd_level_available(faiss.SIMDLevel_NONE):
211211
self.skipTest("SIMDLevel.NONE not available")
212212

213213
levels = [

tests/test_ivf_flat_panorama.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ def assert_search_results_equal(
104104
atol=atol,
105105
err_msg="Distances mismatch",
106106
)
107-
check_ref_knn_with_draws(D_regular, I_regular, D_regular, I_panorama, rtol=rtol)
107+
check_ref_knn_with_draws(
108+
D_regular, I_regular, D_regular, I_panorama, rtol=rtol
109+
)
108110

109111
def assert_range_results_equal(
110112
self,

0 commit comments

Comments
 (0)