Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addn_query_subset_with_ids float index bug #2834

Closed
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
2 changes: 1 addition & 1 deletion faiss/utils/Heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void HeapArray<C>::addn_query_subset_with_ids(
}
#pragma omp parallel for if (nsubset * nj > 100000)
for (int64_t si = 0; si < nsubset; si++) {
T i = subset[si];
TI i = subset[si];
T* __restrict simi = get_val(i);
TI* __restrict idxi = get_ids(i);
const T* ip_line = vin + si * nj;
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(FAISS_TEST_SRC
test_approx_topk.cpp
test_RCQ_cropping.cpp
test_distances_simd.cpp
test_heap.cpp
)

add_executable(faiss_test ${FAISS_TEST_SRC})
Expand Down
53 changes: 53 additions & 0 deletions tests/test_heap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <faiss/utils/Heap.h>
#include <gtest/gtest.h>
#include <algorithm>
#include <numeric>

using namespace faiss;

TEST(Heap, addn_with_ids) {
size_t n = 1000;
size_t k = 1;
std::vector<int64_t> heap_labels(n, -1);
std::vector<float> heap_distances(n, 0);
float_minheap_array_t heaps = {
n, k, heap_labels.data(), heap_distances.data()};
heaps.heapify();
std::vector<int64_t> labels(n, 1);
std::vector<float> distances(n, 0.0f);
std::vector<int64_t> subset(n);
std::iota(subset.begin(), subset.end(), 0);
heaps.addn_with_ids(1, distances.data(), labels.data(), 1);
heaps.reorder();
EXPECT_TRUE(
std::all_of(heap_labels.begin(), heap_labels.end(), [](int64_t i) {
return i == 1;
}));
}

TEST(Heap, addn_query_subset_with_ids) {
size_t n = 20000000; // more than 2^24
size_t k = 1;
std::vector<int64_t> heap_labels(n, -1);
std::vector<float> heap_distances(n, 0);
float_minheap_array_t heaps = {
n, k, heap_labels.data(), heap_distances.data()};
heaps.heapify();
std::vector<int64_t> labels(n, 1);
std::vector<float> distances(n, 0.0f);
std::vector<int64_t> subset(n);
std::iota(subset.begin(), subset.end(), 0);
heaps.addn_query_subset_with_ids(
n, subset.data(), 1, distances.data(), labels.data(), 1);
heaps.reorder();
EXPECT_TRUE(
std::all_of(heap_labels.begin(), heap_labels.end(), [](int64_t i) {
return i == 1;
}));
}