Skip to content

Commit

Permalink
Change order to match with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlees committed Mar 19, 2024
1 parent aca1829 commit f507518
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ sparse_coo query_db_sparse(std::vector<Reference> &ref_sketches,
Eigen::MatrixXf kmer_mat = kmer2mat(kmer_lengths);
#pragma omp parallel for schedule(static) num_threads(num_threads) shared(progress)
for (size_t i = 0; i < ref_sketches.size(); i++) {
// Use a priority queue to efficiently track the smallest N dists
std::priority_queue<SparseDist> min_dists;
if (!interrupt) {
for (size_t j = 0; j < ref_sketches.size(); j++) {
Expand All @@ -380,6 +381,7 @@ sparse_coo query_db_sparse(std::vector<Reference> &ref_sketches,
}
}
}
// Add dist if it is in the smallest k
if (min_dists.size() < kNN || row_dist < min_dists.top().dist) {
SparseDist new_min = {row_dist, j};
min_dists.push(new_min);
Expand All @@ -399,9 +401,11 @@ sparse_coo query_db_sparse(std::vector<Reference> &ref_sketches,
}
}

// For each sample/row/i, fill the ijk vectors
// This goes 'backwards' for compatibility with numpy (so dists are ascending)
long offset = i * kNN;
std::fill_n(i_vec.begin() + offset, kNN, i);
for (int k = 0; k < kNN; ++k) {
for (int k = kNN - 1; k >= 0; --k) {
SparseDist entry = min_dists.top();
j_vec[offset + k] = entry.j;
dists[offset + k] = entry.dist;
Expand Down

0 comments on commit f507518

Please sign in to comment.