Skip to content

Commit

Permalink
Try to fix order in sparse loop
Browse files Browse the repository at this point in the history
Definitely wrong! Was confused by brace levels
  • Loading branch information
johnlees committed Mar 19, 2024
1 parent 1af9b63 commit aca1829
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,13 @@ sparse_coo query_db_sparse(std::vector<Reference> &ref_sketches,
}
}
}
if (min_dists.size() < kNN || row_dist < min_dists.top().dist) {
SparseDist new_min = {row_dist, j};
min_dists.push(new_min);
if (min_dists.size() > kNN) {
min_dists.pop();
}
}
if ((i * ref_sketches.size() + j) % update_every == 0) {
#pragma omp critical
{
Expand All @@ -390,24 +397,15 @@ sparse_coo query_db_sparse(std::vector<Reference> &ref_sketches,
}
}
}
}

if (min_dists.size() < kNN || row_dist < min_dists.top().dist) {
SparseDist new_min = {row_dist, j};
min_dists.push(new_min);
if (min_dists.size() > kNN) {
min_dists.pop();
}
}

long offset = i * kNN;
std::fill_n(i_vec.begin() + offset, kNN, i);
for (int k = 0; k < kNN; ++k) {
SparseDist entry = min_dists.top();
j_vec[offset + k] = entry.j;
dists[offset + k] = entry.dist;
min_dists.pop();
}

long offset = i * kNN;
std::fill_n(i_vec.begin() + offset, kNN, i);
for (int k = 0; k < kNN; ++k) {
SparseDist entry = min_dists.top();
j_vec[offset + k] = entry.j;
dists[offset + k] = entry.dist;
min_dists.pop();
}
}
}
Expand Down

0 comments on commit aca1829

Please sign in to comment.