code: def pad(array, pad_width, mode="constant", **kwargs):
      array = asarray(array)
  
      pad_width = expand_pad_value(array, pad_width)
  
      if callable(mode):
          return pad_udf(array, pad_width, mode, **kwargs)
  
      # Make sure that no unsupported keywords were passed for the current mode
      allowed_kwargs = {
          "empty": [],
          "edge": [],
          "wrap": [],
          "constant": ["constant_values"],
          "linear_ramp": ["end_values"],
          "maximum": ["stat_length"],
          "mean": ["stat_length"],
          "median": ["stat_length"],
          "minimum": ["stat_length"],
          "reflect": ["reflect_type"],
          "symmetric": ["reflect_type"],
      }
      try:
          unsupported_kwargs = set(kwargs) - set(allowed_kwargs[mode])
      except KeyError as e:
          raise ValueError(f"mode '{mode}' is not supported") from e
      if unsupported_kwargs:
          raise ValueError(
              "unsupported keyword arguments for mode '{}': {}".format(
                  mode, unsupported_kwargs
              )
          )
  
      if mode in {"maximum", "mean", "median", "minimum"}:
          stat_length = kwargs.get(
              "stat_length", tuple((n, n) for n in array.shape)
          )
          return pad_stats(array, pad_width, mode, stat_length)
      elif mode == "constant":
          kwargs.setdefault("constant_values", 0)
          return pad_edge(array, pad_width, mode, **kwargs)
      elif mode == "linear_ramp":
          kwargs.setdefault("end_values", 0)
          return pad_edge(array, pad_width, mode, **kwargs)
      elif mode in {"edge", "empty"}:
          return pad_edge(array, pad_width, mode)
      elif mode in ["reflect", "symmetric", "wrap"]:
          return pad_reuse(array, pad_width, mode, **kwargs)
  
      raise RuntimeError("unreachable")
  
imports: from __future__ import annotations
  import itertools
  from collections.abc import Sequence
  from functools import partial
  from itertools import product
  from numbers import Integral, Number
  import numpy
  from tlz import sliding_window
  from dask.array import chunk
  from dask.array.backends import array_creation_dispatch
  from dask.array.core import Array, asarray, block, blockwise, broadcast_arrays, broadcast_to, concatenate, normalize_chunks, stack
  from dask.array.numpy_compat import AxisError
  from dask.array.ufunc import greater_equal, rint
  from dask.array.utils import meta_from_array
  from dask.array.wrap import empty, full, ones, zeros
  from dask.base import tokenize
  from dask.highlevelgraph import HighLevelGraph
  from dask.utils import cached_cumsum, derived_from, is_cupy_type
label_desc: Use image node_id 26 for calling a global function with example usage: pad(array, pad_width, mode) and returns: pad_udf, pad_stats, pad_edge, pad_edge, pad_edge, pad_reuse