mirror of
https://github.com/facebookresearch/faiss.git
synced 2026-10-11 22:50:00 +00:00
black -l 80: tests/ formatting (2/3) (#5427)
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
This commit is contained in:
committed by
meta-codesync[bot]
parent
259fa853af
commit
a7d91d44d9
@@ -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))
|
||||
|
||||
+12
-6
@@ -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):
|
||||
|
||||
+4
-4
@@ -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 = [
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user