1 Commits
Author SHA1 Message Date
Alibek Zhakubayev 55990eb91f Port test_rabitq_utils from C++ to Python (#5442)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/5442

The RaBitQ utility tests landed as C++ (`test_rabitq_utils.cpp`) in D112153740, but faiss tests are primarily written in Python because they exercise the full SWIG binding stack. This diff ports them to Python with identical cases and no behavior change.

The tested helpers (`round_nonnegative_to_uint8`, `round_nonnegative_to_uint16`, `round_clamped_to_uint8` in `faiss::rabitq_utils`, and `LinearTransform::apply_noalloc`) are all reachable from Python via the existing SWIG bindings, so no bindings changes are needed. The C++ test was registered only in `tests/CMakeLists.txt` and was never built by Buck; the Python port is added to `py_tests` in `tests/BUCK`, so it now runs under Buck as well.

Changes:
- Delete `tests/test_rabitq_utils.cpp` and remove it from `tests/CMakeLists.txt`.
- Add `tests/test_rabitq_utils.py` with the same cases: the fixed-value assertions for all three round helpers, the 10000-sample +/-1 property tests, and the `LinearTransform` single-vector vs batch check for both bias settings.
- Register `test_rabitq_utils` in `py_tests` in `tests/BUCK`.

The random property tests use numpy RNG rather than std::mt19937 (the two RNG engines cannot be made bit-identical across languages), but the ranges, sample counts, and +/-1 tolerance are unchanged.

Reviewed By: mnorris11

Differential Revision: D112559549

fbshipit-source-id: 9be93dc33e94477c6c5919582d3a8b4774e476c1
2026-07-17 11:14:42 -07:00