mirror of
https://github.com/facebookresearch/faiss.git
synced 2026-10-12 02:13:36 +00:00
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/5349 # this is a no-op change Ran `black -l 80` over all tracked Python files under `fbcode/faiss/`, using line length 80 to match faiss's documented coding style (`CONTRIBUTING.md`: "80 character line length (both for C++ and Python)"). 172 files were reformatted; 28 were already compliant. This is a pure-formatting change. `black` runs its AST-equivalence safety check on every file, so no identifiers, string/numeric values, operators, or control flow were altered — only whitespace, indentation, line wrapping, blank lines, trailing commas, and string-quote normalization (single to double quotes). `fbcode/faiss/` is intentionally excluded from Meta's standard Python autoformatter (`arc f` / `arc lint -a` report no formatter for these paths) because it mirrors to public GitHub, so the Python had drifted out of any consistent style. The C++ is already clang-format-clean (0 of 807 files change), so this effort is Python-only. This diff brings the Python to canonical `black` formatting. Excluded `demos/index_pq_flat_separate_codes_from_codebook.py`: it contains a Jupyter `!rm` shell-magic line and is not valid Python, so `black` cannot parse it. This is the base of a 3-diff stack: (1) this black reformat; (2) `.flake8` alignment (max-line-length 80 + black-compatible ignores E203/W503); (3) genuine lint fixes (F401/F403/F841/B011). Reviewed By: mnorris11 Differential Revision: D109736099 fbshipit-source-id: 9a054635766ed11aa3760a788395babd3d198abf
81 lines
2.2 KiB
Python
81 lines
2.2 KiB
Python
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
#
|
|
# This source code is licensed under the MIT license found in the
|
|
# LICENSE file in the root directory of this source tree.
|
|
|
|
import time
|
|
import faiss
|
|
import numpy as np
|
|
|
|
|
|
def do_partition(n, qin, maxval=65536, seed=123, id_type="int64"):
|
|
print(
|
|
f"n={n} qin={qin} maxval={maxval} id_type={id_type} ",
|
|
end="\t",
|
|
flush=True,
|
|
)
|
|
|
|
# print("seed=", seed)
|
|
rs = np.random.RandomState(seed)
|
|
vals = rs.randint(maxval, size=n).astype("uint16")
|
|
ids = (rs.permutation(n) + 12345).astype(id_type)
|
|
|
|
sp = faiss.swig_ptr
|
|
|
|
tab_a = faiss.AlignedTableUint16()
|
|
faiss.copy_array_to_AlignedTable(vals, tab_a)
|
|
|
|
nrun = 2000
|
|
|
|
times = []
|
|
nerr = 0
|
|
stats = faiss.cvar.partition_stats
|
|
stats.reset()
|
|
for _run in range(nrun):
|
|
faiss.copy_array_to_AlignedTable(vals, tab_a)
|
|
t0 = time.time()
|
|
# print("tab a type", tab_a.get())
|
|
if isinstance(qin, int):
|
|
q = qin
|
|
faiss.CMax_uint16_partition_fuzzy(
|
|
tab_a.get(), sp(ids), n, q, q, None
|
|
)
|
|
else:
|
|
q_min, q_max = qin
|
|
q = np.array([-1], dtype="uint64")
|
|
faiss.CMax_uint16_partition_fuzzy(
|
|
tab_a.get(), sp(ids), n, q_min, q_max, sp(q)
|
|
)
|
|
q = q[0]
|
|
|
|
if not (q_min <= q <= q_max):
|
|
nerr += 1
|
|
|
|
t1 = time.time()
|
|
|
|
times.append(t1 - t0)
|
|
|
|
times = np.array(times[100:]) * 1000000
|
|
|
|
print(
|
|
f"times {times.mean():.3f} µs (± {times.std():.4f} µs) nerr={nerr} "
|
|
f"bisect {stats.bissect_cycles / 1e6:.3f} Mcy "
|
|
f"compress {stats.compress_cycles / 1e6:.3f} Mcy"
|
|
)
|
|
|
|
|
|
do_partition(200, (100, 100))
|
|
do_partition(200, (100, 150))
|
|
do_partition(2000, (1000, 1000))
|
|
do_partition(2000, (1000, 1500))
|
|
do_partition(20000, (10000, 10000))
|
|
do_partition(20000, (10000, 15000))
|
|
|
|
|
|
do_partition(200, (100, 100), id_type="int32")
|
|
do_partition(200, (100, 150), id_type="int32")
|
|
do_partition(2000, (1000, 1000), id_type="int32")
|
|
do_partition(2000, (1000, 1500), id_type="int32")
|
|
do_partition(20000, (10000, 10000), id_type="int32")
|
|
do_partition(20000, (10000, 15000), id_type="int32")
|