Skip to content

Commit

Permalink
Fix kmeans init dead loop when dist is inf (zilliztech#574)
Browse files Browse the repository at this point in the history
Signed-off-by: chasingegg <[email protected]>
  • Loading branch information
chasingegg authored May 21, 2024
1 parent 89657b0 commit 39c0a73
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions thirdparty/DiskANN/src/math_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,16 +475,20 @@ namespace kmeans {
size_t init_id = int_dist(generator);
size_t num_picked = 1;

picked.push_back(init_id);
std::memcpy(pivot_data, data + init_id * dim, dim * sizeof(float));

auto dist = std::make_unique<float[]>(num_points);

for (int64_t i = 0; i < (_s64) num_points; i++) {
dist[i] =
math_utils::calc_distance(data + i * dim, data + init_id * dim, dim);
if (std::isinf(dist[i])) {
selecting_pivots(data, num_points, dim, pivot_data, num_centers);
return;
}
}

picked.push_back(init_id);
std::memcpy(pivot_data, data + init_id * dim, dim * sizeof(float));

double dart_val;
size_t tmp_pivot;
bool sum_flag = false;
Expand Down

0 comments on commit 39c0a73

Please sign in to comment.