From a7d91d44d945b58baebe03ce4fdbdfecc55dec73 Mon Sep 17 00:00:00 2001 From: Tia Lim Date: Wed, 15 Jul 2026 17:47:15 -0700 Subject: [PATCH] black -l 80: tests/ formatting (2/3) (#5427) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/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 --- tests/test_build_blocks.py | 8 ++++---- tests/test_contrib.py | 18 ++++++++++++------ tests/test_eden.py | 8 ++++---- tests/test_ivf_flat_panorama.py | 4 +++- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/tests/test_build_blocks.py b/tests/test_build_blocks.py index 6c28da49c..2c5fddd12 100644 --- a/tests/test_build_blocks.py +++ b/tests/test_build_blocks.py @@ -669,14 +669,14 @@ class TestMapInt64ToInt64(unittest.TestCase): def xx_test_large(self): # don't run by default because it's slow - self.do_test(2 ** 21, 10 ** 6) + self.do_test(2**21, 10**6) class TestRanklistIntersectionSize(unittest.TestCase): def _intersect(self, v1, v2): - a = np.array(v1, dtype='int64') - b = np.array(v2, dtype='int64') + a = np.array(v1, dtype="int64") + b = np.array(v2, dtype="int64") return faiss.ranklist_intersection_size( len(a), faiss.swig_ptr(a), len(b), faiss.swig_ptr(b) ) @@ -706,5 +706,5 @@ class TestRanklistIntersectionSize(unittest.TestCase): def test_ids_above_2_pow_60(self): # the old bit-flag trick corrupted IDs with bit 60 set - v1, v2 = [2 ** 60, 2 ** 61, 2 ** 62], [2 ** 61, 2 ** 62, 2 ** 63 - 1] + v1, v2 = [2**60, 2**61, 2**62], [2**61, 2**62, 2**63 - 1] self.assertEqual(self._intersect(v1, v2), self._expected(v1, v2)) diff --git a/tests/test_contrib.py b/tests/test_contrib.py index a4a612b1c..8a89af0c0 100644 --- a/tests/test_contrib.py +++ b/tests/test_contrib.py @@ -319,8 +319,7 @@ class TestOperatingPoints(unittest.TestCase): pts = op.operating_points for _, pi, ti in pts: for _, pj, tj in pts: - self.assertFalse( - pj >= pi and tj <= ti and (pj > pi or tj < ti)) + self.assertFalse(pj >= pi and tj <= ti and (pj > pi or tj < ti)) class TestPreassigned(unittest.TestCase): @@ -933,13 +932,19 @@ class TestFactoryTools(unittest.TestCase): def test_get_code_size_hnsw_non_default_m(self): d = 128 # Non-default M values previously raised RuntimeError("cannot parse HNSW16") - self.assertEqual(factory_tools.get_code_size(d, "HNSW16"), d * 4 + 16 * 2 * 4) - self.assertEqual(factory_tools.get_code_size(d, "HNSW64"), d * 4 + 64 * 2 * 4) + self.assertEqual( + factory_tools.get_code_size(d, "HNSW16"), d * 4 + 16 * 2 * 4 + ) + self.assertEqual( + factory_tools.get_code_size(d, "HNSW64"), d * 4 + 64 * 2 * 4 + ) self.assertEqual( factory_tools.get_code_size(d, "HNSW16,Flat"), d * 4 + 16 * 2 * 4 ) # HNSW32 backward compat: formula generalizes correctly - self.assertEqual(factory_tools.get_code_size(d, "HNSW32"), d * 4 + 32 * 2 * 4) + self.assertEqual( + factory_tools.get_code_size(d, "HNSW32"), d * 4 + 32 * 2 * 4 + ) def test_get_code_size_ivf_hnsw_non_default_m(self): d = 128 @@ -948,7 +953,8 @@ class TestFactoryTools(unittest.TestCase): factory_tools.get_code_size(d, "IVF64_HNSW16,Flat"), d * 4 ) self.assertEqual( - factory_tools.get_code_size(d, "IVF64_HNSW64,PQ8x8"), (8 * 8 + 7) // 8 + factory_tools.get_code_size(d, "IVF64_HNSW64,PQ8x8"), + (8 * 8 + 7) // 8, ) def test_get_code_size_hnsw_roundtrip(self): diff --git a/tests/test_eden.py b/tests/test_eden.py index 0dce2e4cf..729d5316f 100644 --- a/tests/test_eden.py +++ b/tests/test_eden.py @@ -63,7 +63,9 @@ def eden_reference_reconstruct(x, bits, center=None, scale_type="unbiased"): return out -def eden_reference_l2_distances(x, query, bits, center=None, scale_type="unbiased"): +def eden_reference_l2_distances( + x, query, bits, center=None, scale_type="unbiased" +): x = np.asarray(x, dtype="float32") query = np.asarray(query, dtype="float32") if center is None: @@ -205,9 +207,7 @@ class TestEDENScalarQuantizer(unittest.TestCase): self.assertTrue(np.any(I >= 0)) def test_search_matches_none_simd_level(self): - if not faiss.SIMDConfig.is_simd_level_available( - faiss.SIMDLevel_NONE - ): + if not faiss.SIMDConfig.is_simd_level_available(faiss.SIMDLevel_NONE): self.skipTest("SIMDLevel.NONE not available") levels = [ diff --git a/tests/test_ivf_flat_panorama.py b/tests/test_ivf_flat_panorama.py index d9529de41..638f69f82 100644 --- a/tests/test_ivf_flat_panorama.py +++ b/tests/test_ivf_flat_panorama.py @@ -104,7 +104,9 @@ class TestIndexIVFFlatPanorama(unittest.TestCase): atol=atol, err_msg="Distances mismatch", ) - check_ref_knn_with_draws(D_regular, I_regular, D_regular, I_panorama, rtol=rtol) + check_ref_knn_with_draws( + D_regular, I_regular, D_regular, I_panorama, rtol=rtol + ) def assert_range_results_equal( self,