code: def pad_edge(array, pad_width, mode, **kwargs):
      """
      Helper function for padding edges.
  
      Handles the cases where the only the values on the edge are needed.
      """
  
      kwargs = {
          k: expand_pad_value(array, v) for k, v in kwargs.items()
      }
  
      result = array
      for d in range(array.ndim):
          pad_shapes, pad_chunks = get_pad_shapes_chunks(
              result, pad_width, (d,)
          )
          pad_arrays = [result, result]
  
          if mode == "constant":
              from dask.array.utils import asarray_safe
  
              constant_values = kwargs["constant_values"][d]
              constant_values = [
                  asarray_safe(
                      c, like=meta_from_array(array), dtype=result.dtype
                  )
                  for c in constant_values
              ]
  
              pad_arrays = [
                  broadcast_to(v, s, c)
                  for v, s, c in zip(
                      constant_values, pad_shapes, pad_chunks
                  )
              ]
          elif mode in ["edge", "linear_ramp"]:
              pad_slices = [
                  result.ndim * [slice(None)],
                  result.ndim * [slice(None)],
              ]
              pad_slices[0][d] = slice(None, 1, None)
              pad_slices[1][d] = slice(-1, None, None)
              pad_slices = [tuple(sl) for sl in pad_slices]
  
              pad_arrays = [result[sl] for sl in pad_slices]
  
              if mode == "edge":
                  pad_arrays = [
                      broadcast_to(a, s, c)
                      for a, s, c in zip(
                          pad_arrays, pad_shapes, pad_chunks
                      )
                  ]
              elif mode == "linear_ramp":
                  end_values = kwargs["end_values"][d]
  
                  pad_arrays = [
                      a.map_blocks(
                          linear_ramp_chunk,
                          ev,
                          pw,
                          chunks=c,
                          dtype=result.dtype,
                          dim=d,
                          step=(2 * i - 1),
                      )
                      for i, (a, ev, pw, c) in enumerate(
                          zip(
                              pad_arrays,
                              end_values,
                              pad_width[d],
                              pad_chunks,
                          )
                      )
                  ]
          elif mode == "empty":
              pad_arrays = [
                  empty_like(
                      array, shape=s, dtype=array.dtype, chunks=c
                  )
                  for s, c in zip(pad_shapes, pad_chunks)
              ]
  
          result = concatenate(
              [pad_arrays[0], result, pad_arrays[1]], axis=d
          )
  
      return result
  
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 21 for calling a global function with example usage: pad_edge(array, pad_width, mode) and returns: result