Python module: cuvs.distance
| 1 | DISTANCE_NAMES = {v: k for k, v in DISTANCE_TYPES.items()} |
| 1 | DISTANCE_TYPES = { |
| 2 | "l2": cuvsDistanceType.L2SqrtExpanded, |
| 3 | "sqeuclidean": cuvsDistanceType.L2Expanded, |
| 4 | "euclidean": cuvsDistanceType.L2SqrtExpanded, |
| 5 | "l1": cuvsDistanceType.L1, |
| 6 | "cityblock": cuvsDistanceType.L1, |
| 7 | "inner_product": cuvsDistanceType.InnerProduct, |
| 8 | "chebyshev": cuvsDistanceType.Linf, |
| 9 | "canberra": cuvsDistanceType.Canberra, |
| 10 | "cosine": cuvsDistanceType.CosineExpanded, |
| 11 | "lp": cuvsDistanceType.LpUnexpanded, |
| 12 | "correlation": cuvsDistanceType.CorrelationExpanded, |
| 13 | "jaccard": cuvsDistanceType.JaccardExpanded, |
| 14 | "hellinger": cuvsDistanceType.HellingerExpanded, |
| 15 | "braycurtis": cuvsDistanceType.BrayCurtis, |
| 16 | "jensenshannon": cuvsDistanceType.JensenShannon, |
| 17 | "hamming": cuvsDistanceType.HammingUnexpanded, |
| 18 | "kl_divergence": cuvsDistanceType.KLDivergence, |
| 19 | "minkowski": cuvsDistanceType.LpUnexpanded, |
| 20 | "russellrao": cuvsDistanceType.RusselRaoExpanded, |
| 21 | "dice": cuvsDistanceType.DiceExpanded, |
| 22 | "bitwise_hamming": cuvsDistanceType.BitwiseHamming |
| 23 | } |
@auto_sync_resources @auto_convert_output
| 1 | def pairwise_distance(X, Y, out=None, metric="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”]
Parameters
| 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 | cuvs.common.Resources, optional |
Examples
| 1 | >>> import cupy as cp |
| 2 | >>> from cuvs.distance import pairwise_distance |
| 3 | >>> n_samples = 5000 |
| 4 | >>> n_features = 50 |
| 5 | >>> in1 = cp.random.random_sample((n_samples, n_features), |
| 6 | ... dtype=cp.float32) |
| 7 | >>> in2 = cp.random.random_sample((n_samples, n_features), |
| 8 | ... dtype=cp.float32) |
| 9 | >>> output = pairwise_distance(in1, in2, metric="euclidean") |
Copyright © 2026, NVIDIA Corporation.