Skip to content

Commit 21dfdba

Browse files
Fix an incorrectly counted the number of computed distances for HNSW (#3840)
Summary: #3819 A definite bug in my code from the past. The number of reported distances is higher that the number of distances actually computed. Pull Request resolved: #3840 Reviewed By: junjieqi Differential Revision: D62392577 Pulled By: mengdilin fbshipit-source-id: c4d595849cc95e77eb6cd8d499b3128bbe9a6e13
1 parent 3f41161 commit 21dfdba

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

faiss/impl/HNSW.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,6 @@ int search_from_candidates(
775775
int counter = 0;
776776
size_t saved_j[4];
777777

778-
ndis += jmax - begin;
779778
threshold = res.threshold;
780779

781780
auto add_to_heap = [&](const size_t idx, const float dis) {
@@ -814,13 +813,17 @@ int search_from_candidates(
814813
add_to_heap(saved_j[id4], dis[id4]);
815814
}
816815

816+
ndis += 4;
817+
817818
counter = 0;
818819
}
819820
}
820821

821822
for (size_t icnt = 0; icnt < counter; icnt++) {
822823
float dis = qdis(saved_j[icnt]);
823824
add_to_heap(saved_j[icnt], dis);
825+
826+
ndis += 1;
824827
}
825828
}
826829

@@ -919,8 +922,6 @@ std::priority_queue<HNSW::Node> search_from_candidate_unbounded(
919922
int counter = 0;
920923
size_t saved_j[4];
921924

922-
ndis += jmax - begin;
923-
924925
auto add_to_heap = [&](const size_t idx, const float dis) {
925926
if (top_candidates.top().first > dis ||
926927
top_candidates.size() < ef) {
@@ -957,13 +958,17 @@ std::priority_queue<HNSW::Node> search_from_candidate_unbounded(
957958
add_to_heap(saved_j[id4], dis[id4]);
958959
}
959960

961+
ndis += 4;
962+
960963
counter = 0;
961964
}
962965
}
963966

964967
for (size_t icnt = 0; icnt < counter; icnt++) {
965968
float dis = qdis(saved_j[icnt]);
966969
add_to_heap(saved_j[icnt], dis);
970+
971+
ndis += 1;
967972
}
968973
}
969974

0 commit comments

Comments
 (0)