Skip to content

Commit 5b6da88

Browse files
authored
Clear descriptor-index results for empty queries (colmap#4960)
`FeatureDescriptorIndex::Search` returns early for an empty descriptor matrix without updating its output matrices. A C++ caller that reuses those matrices after a nonempty query receives the previous query's indices and distances for an empty input. Clear both matrices in the existing empty-query branch, matching the existing empty-index result convention. Type and descriptor-width validation and nonempty FAISS searches stay unchanged. The current SIFT pipeline already filters empty images before this call; this fix covers direct use of the public index utility. I extended the existing parameterized native test to search an empty matrix after filling both outputs. All four combinations fail the new assertions on pristine production and pass with the fix, covering SIFT/ALIKED and flat/IVF indexes. All five module tests pass. A separate native check covers 72 empty queries and 312 ordinary, repeated and rebuild controls; ordinary results match pristine output exactly. Clang-format, scoped Clang-Tidy and whitespace checks pass. I validated the actual C++ owner with MSVC Release and generic CPU FAISS 1.15.1. I did not run a full application build, reconstruction datasets, GPU builds, dynamic-dispatch builds or other operating systems. AI assistance disclosure: AI-assisted development tools were used during investigation and implementation. The reported tests were run against the final diff.
1 parent e6644e7 commit 5b6da88

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

‎src/colmap/feature/index.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ class FaissFeatureDescriptorIndex : public FeatureDescriptorIndex {
9393
THROW_CHECK_EQ(query_descriptors.data.cols(), index_->d);
9494
const int64_t num_query_descriptors = query_descriptors.data.rows();
9595
if (num_query_descriptors == 0) {
96+
indices.resize(0, 0);
97+
l2_dists.resize(0, 0);
9698
return;
9799
}
98100

‎src/colmap/feature/index_test.cc‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ TEST_P(ParameterizedFeatureDescriptorIndexTests, Nominal) {
9898
ASSERT_EQ(indices.cols(), index_descriptors.data.rows());
9999
ASSERT_EQ(distances.rows(), query_descriptors.data.rows());
100100
ASSERT_EQ(distances.cols(), index_descriptors.data.rows());
101+
102+
FeatureDescriptorsFloat empty_queries;
103+
empty_queries.type = params.extractor_type;
104+
empty_queries.data.resize(0, query_descriptors.data.cols());
105+
index->Search(/*num_neighbors=*/2, empty_queries, indices, distances);
106+
EXPECT_EQ(indices.size(), 0);
107+
EXPECT_EQ(distances.size(), 0);
101108
}
102109

103110
TEST(FeatureDescriptorIndexTests, TypeMismatch) {

0 commit comments

Comments
 (0)