cdist implementation #1833
-
Does candle have an implementation of the cdist ? |
Beta Was this translation helpful? Give feedback.
Answered by
LaurentMazare
Mar 11, 2024
Replies: 1 comment
-
It doesn't but you could implement it manually via the following, though it wouldn't be very efficient. let x1 = x1.unsqueeze(1)?;
let x2 = x2.unsqueeze(2)?;
let cdist = x1.broadcast_sub(&x2)?.sqr()?.sum(D::Minus1)?.sqrt()?; If this ends up being an issue performance wise, you could also write a custom op for it, e.g. in encodec we have such a custom kernel here though it applies both a cdist and an argmin in the same kernel. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
vishpat
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It doesn't but you could implement it manually via the following, though it wouldn't be very efficient.
If this ends up being an issue performance wise, you could also write a custom op for it, e.g. in encodec we have such a custom kernel here though it applies both a cdist and an argmin in the same kernel.