From 3c19c52ca0380bbbd032ba15cd9ff8143e4b7b8e Mon Sep 17 00:00:00 2001 From: Junjie Qi Date: Mon, 13 Apr 2026 13:02:00 -0700 Subject: [PATCH] Use std:: qualified math functions to avoid float-to-double promotion (#5088) Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/5088 Fix 4 `performance-type-promotion-in-math-fn` lint warnings by using `std::floor`, `std::fabs`, and `std::pow` instead of the unqualified C versions. The unqualified versions promote `float` arguments to `double`, causing unnecessary precision loss and performance overhead. Also added missing `#include ` in `IndexIVFSpectralHash.cpp`. Reviewed By: mnorris11 Differential Revision: D100576274 fbshipit-source-id: f491b1e9432a42f56a5660002f5b10ed0f594f4c --- faiss/IndexIVFSpectralHash.cpp | 3 ++- faiss/VectorTransform.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/faiss/IndexIVFSpectralHash.cpp b/faiss/IndexIVFSpectralHash.cpp index f0e53d36e..523ef8afb 100644 --- a/faiss/IndexIVFSpectralHash.cpp +++ b/faiss/IndexIVFSpectralHash.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -159,7 +160,7 @@ void binarize_with_freq( memset(codes, 0, (nbit + 7) / 8); for (size_t i = 0; i < nbit; i++) { float xf = (x[i] - c[i]); - int64_t xi = int64_t(floor(xf * freq)); + int64_t xi = int64_t(std::floor(xf * freq)); int64_t bit = xi & 1; codes[i >> 3] |= bit << (i & 7); } diff --git a/faiss/VectorTransform.cpp b/faiss/VectorTransform.cpp index 0f5265f43..219920e88 100644 --- a/faiss/VectorTransform.cpp +++ b/faiss/VectorTransform.cpp @@ -279,7 +279,7 @@ void LinearTransform::set_is_orthonormal() { float v = ATA[i + j * d_out]; if (i == j) v -= 1; - if (fabs(v) > eps) { + if (std::fabs(v) > eps) { is_orthonormal = false; } } @@ -773,7 +773,7 @@ void PCAMatrix::prepare_Ab() { if (eigen_power != 0) { float* ai = A.data(); for (int i = 0; i < d_out; i++) { - float factor = pow(eigenvalues[i] + epsilon, eigen_power); + float factor = std::pow(eigenvalues[i] + epsilon, eigen_power); for (int j = 0; j < d_in; j++) *ai++ *= factor; }