code: def _pariwise_distance_chunked(
      X,
      Y,
      reduce_func=None,
      metric="euclidean",
      working_memory=None,
      xp=None,
      **kwds,
  ):
      if xp is np:
          from sklearn.metrics import pairwise_distances
      else:  # pragma: no cover
          from cuml.metrics import pairwise_distances
  
      n_samples_X = _num_samples(X)
      if metric == "precomputed":  # pragma: no cover
          slices = (slice(0, n_samples_X),)
      else:
          # We get as many rows as possible within our working_memory budget to
          # store len(Y) distances in each row of output.
          #
          # Note:
          #  - this will get at least 1 row, even if 1 row of distances will
          #    exceed working_memory.
          #  - this does not account for any temporary memory usage while
          #    calculating distances (e.g. difference of vectors in manhattan
          #    distance.
          chunk_n_rows = get_chunk_n_rows(
              row_bytes=8 * _num_samples(Y),
              max_n_rows=n_samples_X,
              working_memory=working_memory,
          )
          slices = gen_batches(n_samples_X, chunk_n_rows)
  
      # precompute data-derived metric params
      params = _precompute_metric_params(
          X, Y, xp, metric=metric, **kwds
      )
      kwds.update(**params)
  
      for sl in slices:
          if sl.start == 0 and sl.stop == n_samples_X:
              X_chunk = X  # enable optimised paths for X is Y
          else:
              X_chunk = X[sl]
          # call pairwise op's execute method to get the result
          D_chunk = pairwise_distances(
              ensure_own_data(X_chunk),
              ensure_own_data(Y),
              metric=metric,
              **kwds,
          )
          if (X is Y or Y is None) and metric == "euclidean":
              # zeroing diagonal, taking care of aliases of "euclidean",
              # i.e. "l2"
              D_chunk.flat[
                  sl.start :: _num_samples(X) + 1
              ] = 0  # pylint: disable=invalid-slice-index
          if reduce_func is not None:
              chunk_size = D_chunk.shape[0]
              D_chunk = reduce_func(D_chunk, sl.start)
              _check_chunk_size(D_chunk, chunk_size)
          yield D_chunk
  
imports: from functools import partial
  import numpy
  from ....None import opcodes
  from ....None import options
  from ....core import recursive_tile
  from ....core.operand import OperandStage
  from ....serialization.serializables import KeyField, BoolField, DictField, Int64Field, AnyField
  from ....tensor.core import TensorOrder
  from ....tensor.merge import TensorConcatenate
  from ....tensor.array_utils import as_same_device, device, get_array_module
  from ....utils import has_unknown_shape, ensure_own_data
  from ...utils import gen_batches, get_chunk_n_rows
  from ...utils.validation import _num_samples
  from .core import PairwiseDistances
label_desc: Use image node_id 3 for calling a global function with example usage: _pariwise_distance_chunked(X, Y, reduce_func, metric, working_memory, xp) without return types