code: def compute_average_surface_distance(
      y_pred: np.ndarray | torch.Tensor,
      y: np.ndarray | torch.Tensor,
      include_background: bool = False,
      symmetric: bool = False,
      distance_metric: str = "euclidean",
      spacing: int
      | float
      | np.ndarray
      | Sequence[int | float | np.ndarray | Sequence[int | float]]
      | None = None,
  ) -> torch.Tensor:
      """
      This function is used to compute the Average Surface Distance from `y_pred` to `y`
      under the default setting.
      In addition, if sets ``symmetric = True``, the average symmetric surface distance between
      these two inputs will be returned.
      The implementation refers to `DeepMind's implementation <https://github.com/deepmind/surface-distance>`_.
  
      Args:
          y_pred: input data to compute, typical segmentation model output.
              It must be one-hot format and first dim is batch, example shape: [16, 3, 32, 32]. The values
              should be binarized.
          y: ground truth to compute mean the distance. It must be one-hot format and first dim is batch.
              The values should be binarized.
          include_background: whether to include distance computation on the first channel of
              the predicted output. Defaults to ``False``.
          symmetric: whether to calculate the symmetric average surface distance between
              `seg_pred` and `seg_gt`. Defaults to ``False``.
          distance_metric: : [``"euclidean"``, ``"chessboard"``, ``"taxicab"``]
              the metric used to compute surface distance. Defaults to ``"euclidean"``.
          spacing: spacing of pixel (or voxel). This parameter is relevant only if ``distance_metric`` is set to ``"euclidean"``.
              If a single number, isotropic spacing with that value is used for all images in the batch. If a sequence of numbers,
              the length of the sequence must be equal to the image dimensions. This spacing will be used for all images in the batch.
              If a sequence of sequences, the length of the outer sequence must be equal to the batch size.
              If inner sequence has length 1, isotropic spacing with that value is used for all images in the batch,
              else the inner sequence length must be equal to the image dimensions. If ``None``, spacing of unity is used
              for all images in batch. Defaults to ``None``.
      """
  
      if not include_background:
          y_pred, y = ignore_background(y_pred=y_pred, y=y)
  
      y_pred = convert_data_type(
          y_pred, output_type=torch.Tensor, dtype=torch.float
      )[0]
      y = convert_data_type(
          y, output_type=torch.Tensor, dtype=torch.float
      )[0]
  
      if y.shape != y_pred.shape:
          raise ValueError(
              f"y_pred and y should have same shapes, got {y_pred.shape} and {y.shape}."
          )
  
      batch_size, n_class = y_pred.shape[:2]
      asd = torch.empty(
          (batch_size, n_class),
          dtype=torch.float32,
          device=y_pred.device,
      )
  
      img_dim = y_pred.ndim - 2
      spacing_list = prepare_spacing(
          spacing=spacing, batch_size=batch_size, img_dim=img_dim
      )
  
      for b, c in np.ndindex(batch_size, n_class):
          _, distances, _ = get_edge_surface_distance(
              y_pred[b, c],
              y[b, c],
              distance_metric=distance_metric,
              spacing=spacing_list[b],
              symmetric=symmetric,
              class_index=c,
          )
          surface_distance = torch.cat(distances)
          asd[b, c] = (
              torch.tensor(np.nan)
              if surface_distance.shape == (0,)
              else surface_distance.mean()
          )
  
      return convert_data_type(
          asd,
          output_type=torch.Tensor,
          device=y_pred.device,
          dtype=torch.float,
      )[0]
  
file_path: MONAI/monai/metrics/surface_distance.py
imports: from __future__ import annotations
  from collections.abc import Sequence
  from typing import Any
  import numpy
  import torch
  from monai.metrics.utils import do_metric_reduction, get_edge_surface_distance, ignore_background, prepare_spacing
  from monai.utils import MetricReduction, convert_data_type
  from .metric import CumulativeIterationMetric
label_desc: Use image node_id 1 for calling a global function with example usage: compute_average_surface_distance(y_pred, y, include_background, symmetric, distance_metric, spacing) and returns: convert_data_type