code: def _pairwise_callable(X, Y, metric, force_all_finite=True, **kwds):
      """Handle the callable case for pairwise_{distances,kernels}."""
      X, Y = check_pairwise_arrays(
          X, Y, force_all_finite=force_all_finite
      )
  
      if X is Y:
          # Only calculate metric for upper triangle
          out = np.zeros((X.shape[0], Y.shape[0]), dtype="float")
          iterator = itertools.combinations(range(X.shape[0]), 2)
          for i, j in iterator:
              out[i, j] = metric(X[i], Y[j], **kwds)
  
          # Make symmetric
          # NB: out += out.T will produce incorrect results
          out = out + out.T
  
          # Calculate diagonal
          # NB: nonzero diagonals are allowed for both metrics and kernels
          for i in range(X.shape[0]):
              x = X[i]
              out[i, i] = metric(x, x, **kwds)
  
      else:
          # Calculate all cells
          out = np.empty((X.shape[0], Y.shape[0]), dtype="float")
          iterator = itertools.product(
              range(X.shape[0]), range(Y.shape[0])
          )
          for i, j in iterator:
              out[i, j] = metric(X[i], Y[j], **kwds)
  
      return out
  
imports: import itertools
  import warnings
  from functools import partial
  import numpy
  from joblib import effective_n_jobs
  from scipy.sparse import csr_matrix, issparse
  from scipy.spatial import distance
  from ..None import config_context
  from ..exceptions import DataConversionWarning
  from ..preprocessing import normalize
  from ..utils import check_array, gen_batches, gen_even_slices, get_chunk_n_rows, is_scalar_nan
  from ..utils._mask import _get_mask
  from ..utils._param_validation import Hidden, Integral, Interval, MissingValues, Options, Real, StrOptions, validate_params
  from ..utils.extmath import row_norms, safe_sparse_dot
  from ..utils.fixes import parse_version, sp_base_version
  from ..utils.parallel import Parallel, delayed
  from ..utils.validation import _num_samples, check_non_negative
  from ._pairwise_distances_reduction import ArgKmin
  from ._pairwise_fast import _chi2_kernel_fast, _sparse_manhattan
label_desc: Use image node_id 30 for calling a global function with example usage: _pairwise_callable(X, Y, metric, force_all_finite) and returns: out