pairwise_distances#
- torchdr.pairwise_distances(X: Tensor, Y: Tensor | None = None, metric: str = 'sqeuclidean', backend: str | None = None, exclude_self: bool = False, k: int | None = None)[source]#
Compute pairwise distances matrix between points in two datasets.
Returns the pairwise distance matrix as torch tensor or KeOps lazy tensor (if keops is True).
- Parameters:
X (torch.Tensor of shape (n_samples, n_features)) – First dataset.
Y (torch.Tensor of shape (m_samples, n_features), optional) – Second dataset. If None, Y = X.
metric (str, optional) – Metric to use for computing distances. The default is “sqeuclidean”.
backend ({"keops", None}, optional) – Which backend to use for handling sparsity and memory efficiency. Default is None.
exclude_self (bool, optional) – If True, adds weight on the diagonal of the distance matrix. Default is False.
k (int, optional) – Number of nearest neighbors to consider for the distances. Default is None.
- Returns:
C (torch.Tensor or pykeops.torch.LazyTensor (if keops is True))
of shape (n_samples, m_samples) – Pairwise distances matrix.