Closed rsokl closed 3 years ago
Computing pairwise_dists(x, x) can lead to nans because floating point may produce negative square-distance values.
pairwise_dists(x, x)
def pairwise_dists(x, y): """ Computing pairwise distances using memory-efficient vectorization. Parameters ---------- x : numpy.ndarray, shape=(M, D) y : numpy.ndarray, shape=(N, D) Returns ------- numpy.ndarray, shape=(M, N) The Euclidean distance between each pair of rows between `x` and `y`.""" dists = -2 * np.matmul(x, y.T) dists += np.sum(x**2, axis=1)[:, np.newaxis] dists += np.sum(y**2, axis=1) return np.sqrt(np.clip(dists, 0, None))
Closed by #165
Computing
pairwise_dists(x, x)
can lead to nans because floating point may produce negative square-distance values.