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

Using expanded distance computations in pylibraft #1759

Merged
merged 8 commits into from
Aug 23, 2023
Prev Previous commit
Next Next commit
Adding abs to clamping
  • Loading branch information
cjnolet committed Aug 23, 2023
commit 0b9ce69ecea2cc8ae907ecd25d3471b69adb6516
5 changes: 3 additions & 2 deletions cpp/include/raft/distance/detail/distance_ops/l2_exp.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#pragma once

#include <raft/core/math.hpp>
#include <raft/util/cuda_dev_essentials.cuh> // DI

namespace raft::distance::detail::ops {
Expand All @@ -33,7 +34,7 @@ struct l2_exp_cutlass_op {
// outVal could be negative due to numerical instability, especially when
// calculating self distance.
// clamp to 0 to avoid potential NaN in sqrt
outVal = outVal * (outVal <= DataT(0.0001));
outVal = outVal * (raft::abs(outVal) >= DataT(0.0001));
return sqrt ? raft::sqrt(outVal) : outVal;
}

Expand Down Expand Up @@ -88,7 +89,7 @@ struct l2_exp_distance_op {
DataT val = regxn[i] + regyn[j] - (DataT)2.0 * acc[i][j];
// val could be negative due to numerical instability, especially when
// calculating self distance. Clamp to 0 to avoid potential NaN in sqrt
acc[i][j] = val * (val <= DataT(0.0001));
acc[i][j] = val * (raft::abs(val) >= DataT(0.0001));
}
}
if (sqrt) {
Expand Down