code: def _compute_percentile_hausdorff_distance(
      surface_distance: torch.Tensor, percentile: float | None = None
  ) -> torch.Tensor:
      """
      This function is used to compute the Hausdorff distance.
      """
  
      # for both pred and gt do not have foreground
      if surface_distance.shape == (0,):
          return torch.tensor(
              np.nan, dtype=torch.float, device=surface_distance.device
          )
  
      if not percentile:
          return surface_distance.max()
  
      if 0 <= percentile <= 100:
          return torch.quantile(surface_distance, percentile / 100)
      raise ValueError(
          f"percentile should be a value between 0 and 100, get {percentile}."
      )
  
file_path: MONAI/monai/metrics/hausdorff_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, get_surface_distance, ignore_background, prepare_spacing
  from monai.utils import MetricReduction, convert_data_type, deprecated
  from .metric import CumulativeIterationMetric
label_desc: Use image node_id 2 for calling a global function with example usage: _compute_percentile_hausdorff_distance(surface_distance, percentile) and returns: torch, surface_distance, torch