Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions faiss/impl/HNSW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <faiss/impl/HNSW.h>

#include <cmath>
#include <string>

#include <faiss/impl/AuxIndexStructures.h>
Expand Down Expand Up @@ -543,11 +542,12 @@ int search_from_candidates(
for (int i = 0; i < candidates.size(); i++) {
idx_t v1 = candidates.ids[i];
float d = candidates.dis[i];
assert(v1 >= 0);
FAISS_ASSERT(v1 >= 0);
if (!sel || sel->is_member(v1)) {
if (d < D[0]) {
faiss::maxheap_replace_top(k, D, I, d, v1);
nres++;
if (nres < k) {
faiss::maxheap_push(++nres, D, I, d, v1);
} else if (d < D[0]) {
faiss::maxheap_replace_top(nres, D, I, d, v1);
}
}
vt.set(v1);
Expand Down Expand Up @@ -612,9 +612,10 @@ int search_from_candidates(

auto add_to_heap = [&](const size_t idx, const float dis) {
if (!sel || sel->is_member(idx)) {
if (dis < D[0]) {
faiss::maxheap_replace_top(k, D, I, dis, idx);
nres++;
if (nres < k) {
faiss::maxheap_push(++nres, D, I, dis, idx);
} else if (dis < D[0]) {
faiss::maxheap_replace_top(nres, D, I, dis, idx);
}
}
candidates.push(idx, dis);
Expand Down Expand Up @@ -667,7 +668,7 @@ int search_from_candidates(
stats.n3 += ndis;
}

return std::min(nres, k);
return nres;
}

std::priority_queue<HNSW::Node> search_from_candidate_unbounded(
Expand Down Expand Up @@ -815,11 +816,6 @@ HNSWStats HNSW::search(
// greedy search on upper levels
storage_idx_t nearest = entry_point;
float d_nearest = qdis(nearest);
if (!std::isfinite(d_nearest)) {
// means either the query or the entry point are NaN: in
// both cases we can only return -1 as a result
return stats;
}

for (int level = max_level; level >= 1; level--) {
greedy_update_nearest(*this, qdis, level, nearest, d_nearest);
Expand All @@ -830,6 +826,7 @@ HNSWStats HNSW::search(
MinimaxHeap candidates(ef);

candidates.push(nearest, d_nearest);

search_from_candidates(
*this, qdis, k, I, D, candidates, vt, stats, 0, 0, params);
} else {
Expand Down
7 changes: 3 additions & 4 deletions faiss/impl/ResultHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,8 @@ struct SingleBestResultHandler {
/// begin results for query # i
void begin(const size_t current_idx) {
this->current_idx = current_idx;
min_dis = C::neutral();
min_idx = -1;
min_dis = HUGE_VALF;
min_idx = 0;
}

/// add one result for query i
Expand All @@ -472,8 +472,7 @@ struct SingleBestResultHandler {
this->i1 = i1;

for (size_t i = i0; i < i1; i++) {
this->dis_tab[i] = C::neutral();
this->ids_tab[i] = -1;
this->dis_tab[i] = HUGE_VALF;
}
}

Expand Down
5 changes: 0 additions & 5 deletions faiss/impl/ScalarQuantizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,11 +1075,6 @@ void ScalarQuantizer::set_derived_sizes() {
}

void ScalarQuantizer::train(size_t n, const float* x) {
for (size_t i = 0; i < n * d; i++) {
FAISS_THROW_IF_NOT_MSG(
std::isfinite(x[i]), "training data contains NaN or Inf");
}

int bit_per_dim = qtype == QT_4bit_uniform ? 4
: qtype == QT_4bit ? 4
: qtype == QT_6bit ? 6
Expand Down
182 changes: 0 additions & 182 deletions tests/test_error_reporting.py

This file was deleted.

Loading