code: def iter_patch_slices(
      image_size: Sequence[int],
      patch_size: Sequence[int] | int,
      start_pos: Sequence[int] = (),
      overlap: Sequence[float] | float = 0.0,
      padded: bool = True,
  ) -> Generator[tuple[slice, ...], None, None]:
      """
      Yield successive tuples of slices defining patches of size `patch_size` from an array of dimensions `image_size`.
      The iteration starts from position `start_pos` in the array, or starting at the origin if this isn't provided. Each
      patch is chosen in a contiguous grid using a rwo-major ordering.
  
      Args:
          image_size: dimensions of array to iterate over
          patch_size: size of patches to generate slices for, 0 or None selects whole dimension
          start_pos: starting position in the array, default is 0 for each dimension
          overlap: the amount of overlap of neighboring patches in each dimension (a value between 0.0 and 1.0).
              If only one float number is given, it will be applied to all dimensions. Defaults to 0.0.
          padded: if the image is padded so the patches can go beyond the borders. Defaults to False.
  
      Yields:
          Tuples of slice objects defining each patch
      """
  
      # ensure patch_size has the right length
      patch_size_ = get_valid_patch_size(image_size, patch_size)
  
      # create slices based on start position of each patch
      for position in iter_patch_position(
          image_size=image_size,
          patch_size=patch_size_,
          start_pos=start_pos,
          overlap=overlap,
          padded=padded,
      ):
          yield tuple(
              slice(s, s + p) for s, p in zip(position, patch_size_)
          )
  
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 2 for calling a global function with example usage: iter_patch_slices(image_size, patch_size, start_pos, overlap, padded) without return types