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

Adjust Hellinger pairwise distance to vaoid NaNs #189

Merged
merged 2 commits into from
Apr 1, 2021
Merged
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion cpp/include/raft/sparse/distance/l2_distance.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,11 @@ class hellinger_expanded_distances_t : public distances_t<value_t> {

raft::linalg::unaryOp<value_t>(
out_dists, out_dists, config_->a_nrows * config_->b_nrows,
[=] __device__(value_t input) { return sqrt(1 - input); },
[=] __device__(value_t input) {
// Adjust to replace NaN in sqrt with 0 if input to sqrt is negative
value_t rectifier = (1 - input) > 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be bool. Just combine this with next line?

return rectifier * sqrt(1 - input);
},
config_->stream);
}

Expand Down