code: def get_nearest_neighbor_distances(samples):
      try:
          # This version scales as O(N log(N)).
          from scipy.spatial import cKDTree
  
          samples = samples.cpu().numpy()
          distances, indices = cKDTree(samples).query(samples, k=2)
          return torch.from_numpy(distances[:, 1])
      except ImportError:
          # This version scales as O(N^2).
          distances, indices = torch.cdist(samples, samples).kthvalue(
              k=2
          )
          return distances
  
file_path: pyro/pyro/distributions/testing/gof.py
imports: import math
  import warnings
  import torch
  from .special import chi2sf
label_desc: Use image node_id 7 for calling a global function with example usage: get_nearest_neighbor_distances(samples) and returns: torch, distances