code: def pairwise_distances(X, Y=None, metric="euclidean", **kwds):
      if (
          metric not in _VALID_METRICS
          and not callable(metric)
          and metric != "precomputed"
      ):
          raise ValueError(
              f"Unknown metric {metric}. Valid metrics are {_VALID_METRICS}, "
              "or 'precomputed', or a callable"
          )
  
      if metric == "precomputed":
          X, _ = PairwiseDistances.check_pairwise_arrays(
              X, Y, precomputed=True
          )
  
          whom = (
              "`pairwise_distances`. Precomputed distance "
              " need to have non-negative values."
          )
          X = check_non_negative(X, whom=whom)
          return X
      elif metric in PAIRWISE_DISTANCE_FUNCTIONS:
          func = PAIRWISE_DISTANCE_FUNCTIONS[metric]
      else:
          # including when metric is callable
          dtype = bool if metric in PAIRWISE_BOOLEAN_FUNCTIONS else None
  
          if (
              dtype == bool
              and (
                  X.dtype != bool or (Y is not None and Y.dtype != bool)
              )
              and DataConversionWarning is not None
          ):
              msg = f"Data was converted to boolean for metric {metric}"
              warnings.warn(msg, DataConversionWarning)
  
          X, Y = PairwiseDistances.check_pairwise_arrays(
              X, Y, dtype=dtype
          )
          if X is Y:
              return distance.squareform(
                  distance.pdist(X, metric=metric, **kwds)
              )
          func = partial(distance.cdist, metric=metric, **kwds)
  
      return func(X, Y, **kwds)
  
file_path: mars/mars/learn/metrics/pairwise/pairwise.py
imports: import warnings
  from functools import partial
  from ....tensor.spatial import distance
  from ...utils.validation import check_non_negative
  from .core import PairwiseDistances
  from .manhattan import manhattan_distances
  from .cosine import cosine_distances
  from .euclidean import euclidean_distances
  from .haversine import haversine_distances
label_desc: Use image node_id 1 for calling a global function with example usage: pairwise_distances(X, Y, metric) and returns: func, X, distance