code: def compute_importance_map(
      patch_size: tuple[int, ...],
      mode: BlendMode | str = BlendMode.CONSTANT,
      sigma_scale: Sequence[float] | float = 0.125,
      device: torch.device | int | str = "cpu",
      dtype: torch.dtype | str | None = torch.float32,
  ) -> torch.Tensor:
      """Get importance map for different weight modes.
  
      Args:
          patch_size: Size of the required importance map. This should be either H, W [,D].
          mode: {``"constant"``, ``"gaussian"``}
              How to blend output of overlapping windows. Defaults to ``"constant"``.
  
              - ``"constant``": gives equal weight to all predictions.
              - ``"gaussian``": gives less weight to predictions on edges of windows.
  
          sigma_scale: Sigma_scale to calculate sigma for each dimension
              (sigma = sigma_scale * dim_size). Used for gaussian mode only.
          device: Device to put importance map on.
          dtype: Data type of the output importance map.
  
      Raises:
          ValueError: When ``mode`` is not one of ["constant", "gaussian"].
  
      Returns:
          Tensor of size patch_size.
  
      """
      mode = look_up_option(mode, BlendMode)
      device = torch.device(device)
      if mode == BlendMode.CONSTANT:
          importance_map = torch.ones(
              patch_size, device=device, dtype=torch.float
          )
      elif mode == BlendMode.GAUSSIAN:
          sigma_scale = ensure_tuple_rep(sigma_scale, len(patch_size))
          sigmas = [
              i * sigma_s for i, sigma_s in zip(patch_size, sigma_scale)
          ]
  
          for i in range(len(patch_size)):
              x = torch.arange(
                  start=-(patch_size[i] - 1) / 2.0,
                  end=(patch_size[i] - 1) / 2.0 + 1,
                  dtype=torch.float,
                  device=device,
              )
              x = torch.exp(
                  x**2 / (-2 * sigmas[i] ** 2)
              )  # 1D gaussian
              importance_map = (
                  importance_map.unsqueeze(-1) * x[(None,) * i]
                  if i > 0
                  else x
              )
      else:
          raise ValueError(
              f"Unsupported mode: {mode}, available options are [{BlendMode.CONSTANT}, {BlendMode.CONSTANT}]."
          )
      # handle non-positive weights
      min_non_zero = max(torch.min(importance_map).item(), 1e-3)
      importance_map = torch.clamp_(
          importance_map.to(torch.float), min=min_non_zero
      ).to(dtype)
      return importance_map
  
imports: from __future__ import annotations
  import hashlib
  import json
  import logging
  import math
  import os
  import pickle
  import sys
  from collections import abc, defaultdict
  from collections.abc import Generator, Iterable, Mapping, Sequence, Sized
  from copy import deepcopy
  from functools import reduce
  from itertools import product, starmap, zip_longest
  from pathlib import PurePath
  from typing import Any
  import numpy
  import torch
  from torch.utils.data._utils.collate import default_collate
  from monai import config
  from monai.config.type_definitions import NdarrayOrTensor, NdarrayTensor, PathLike
  from monai.data.meta_obj import MetaObj
  from monai.utils import MAX_SEED, BlendMode, Method, NumpyPadMode, TraceKeys, convert_data_type, convert_to_dst_type, ensure_tuple, ensure_tuple_rep, ensure_tuple_size, fall_back_tuple, first, get_equivalent_dtype, issequenceiterable, look_up_option, optional_import, pytorch_after
label_desc: Use image node_id 26 for calling a global function with example usage: compute_importance_map(patch_size, mode, sigma_scale, device, dtype) and returns: importance_map