Distance#
2025-10-17
2 min read time
Pairwise Distance#
- cuvs.distance.pairwise_distance(*args, resources=None, **kwargs)#
pairwise_distance(X, Y, out=None, metric=u’euclidean’, p=2.0, resources=None)
Compute pairwise distances between X and Y
- Valid values for metric:
- [“euclidean”, “l2”, “l1”, “cityblock”, “inner_product”,
“chebyshev”, “canberra”, “lp”, “hellinger”, “jensenshannon”, “kl_divergence”, “russellrao”, “minkowski”, “correlation”, “cosine”]
X : CUDA array interface compliant matrix shape (m, k) Y : CUDA array interface compliant matrix shape (n, k) out : Optional writable CUDA array interface matrix shape (m, n) metric : string denoting the metric type (default=”euclidean”) p : metric parameter (currently used only for “minkowski”) resources : Optional cuVS Resource handle for reusing CUDA resources.
If Resources aren’t supplied, CUDA resources will be allocated inside this function and synchronized before the function exits. If resources are supplied, you will need to explicitly synchronize yourself by calling resources.sync() before accessing the output.
>>> import cupy as cp >>> from cuvs.distance import pairwise_distance >>> n_samples = 5000 >>> n_features = 50 >>> in1 = cp.random.random_sample((n_samples, n_features), ... dtype=cp.float32) >>> in2 = cp.random.random_sample((n_samples, n_features), ... dtype=cp.float32) >>> output = pairwise_distance(in1, in2, metric="euclidean")