code: def dist(x1, x2=None, metric='sqeuclidean', to_numpy=True):
      
      if x2 is None:
          x2 = x1
      if metric == "sqeuclidean":
          return euclidean_distances(x1, x2, squared=True, to_numpy=to_numpy)
      elif metric == "euclidean":
          return euclidean_distances(x1, x2, squared=False, to_numpy=to_numpy)
      else:
          raise NotImplementedError
docs: Compute distance between samples in x1 and x2 on gpu
  
      Parameters
      ----------
  
      x1 : np.array (n1,d)
          matrix with n1 samples of size d
      x2 : np.array (n2,d), optional
          matrix with n2 samples of size d (if None then x2=x1)
      metric : str
          Metric from 'sqeuclidean', 'euclidean',
  
  
      Returns
      -------
  
      M : np.array (n1,n2)
          distance matrix computed with given metric