code: def _execute_map(cls, ctx, op):
      from scipy.spatial.distance import pdist, cdist
  
      inputs, device_id, xp = as_same_device(
          [ctx[inp.key] for inp in op.inputs],
          device=op.device,
          ret_extra=True,
      )
  
      if xp is cp:  # pragma: no cover
          raise NotImplementedError(
              "`pdist` does not support running on GPU yet"
          )
  
      with device(device_id):
          inputs_iter = iter(inputs)
          a = next(inputs_iter)
          if op.b is not None:
              b = next(inputs_iter)
          else:
              b = None
          kw = dict()
          if op.p is not None:
              kw["p"] = op.p
          if op.w is not None:
              kw["w"] = next(inputs_iter)
          if op.v is not None:
              kw["V"] = next(inputs_iter)
          if op.vi is not None:
              kw["VI"] = next(inputs_iter)
          metric = op.metric
  
          if b is None:
              # one input, pdist on same chunk
              dists = pdist(ensure_own_data(a), metric=metric, **kw)
              i_indices, j_indices = xp.triu_indices(a.shape[0], k=1)
              i_indices += op.a_offset
              j_indices += op.a_offset
          else:
              # two inputs, pdist on different chunks
              dists = cdist(
                  ensure_own_data(a),
                  ensure_own_data(b),
                  metric=metric,
                  **kw,
              ).ravel()
              mgrid = xp.mgrid[
                  op.a_offset : op.a_offset + a.shape[0],
                  op.b_offset : op.b_offset + b.shape[0],
              ]
              i_indices, j_indices = mgrid[0].ravel(), mgrid[1].ravel()
  
          out_row_sizes = xp.arange(op.n - 1, -1, -1)
          out_row_cum_sizes = xp.empty((op.n + 1,), dtype=int)
          out_row_cum_sizes[0] = 0
          xp.cumsum(out_row_sizes, out=out_row_cum_sizes[1:])
          indices = (
              out_row_cum_sizes[i_indices]
              + j_indices
              - (op.n - out_row_sizes[i_indices])
          )
  
          # save as much memory as possible
          del i_indices, j_indices, out_row_sizes, out_row_cum_sizes
  
          out_cum_size = xp.cumsum(op.out_sizes)
          out = op.outputs[0]
          for i in range(len(op.out_sizes)):
              start_index = out_cum_size[i - 1] if i > 0 else 0
              end_index = out_cum_size[i]
              to_filter = (indices >= start_index) & (
                  indices < end_index
              )
              downside_indices = indices[to_filter] - start_index
              downside_dists = dists[to_filter]
              ctx[out.key, (i,)] = (downside_indices, downside_dists)
  
imports: from typing import List, Tuple
  import numpy
  from ....None import opcodes
  from ....core import recursive_tile
  from ....core.operand import OperandStage
  from ....serialization.serializables import FieldTypes, KeyField, AnyField, Float16Field, Int32Field, TupleField
  from ....utils import has_unknown_shape, require_module, ensure_own_data
  from ....config import options
  from ...operands import TensorMapReduceOperand, TensorOperandMixin, TensorShuffleProxy
  from ...array_utils import as_same_device, device, cp
  from ...core import TensorOrder
  from ...datasource.array import tensor
label_desc: Use image node_id 20 for calling the TensorPdist obj's underlying member method code with example usage: obj._execute_map(cls, ctx, op) without return types