code: def check_index(axis, ind, dimension):
      """Check validity of index for a given dimension
  
      Examples
      --------
      >>> check_index(0, 3, 5)
      >>> check_index(0, 5, 5)
      Traceback (most recent call last):
      ...
      IndexError: Index 5 is out of bounds for axis 0 with size 5
  
      >>> check_index(1, 6, 5)
      Traceback (most recent call last):
      ...
      IndexError: Index 6 is out of bounds for axis 1 with size 5
  
      >>> check_index(1, -1, 5)
      >>> check_index(1, -6, 5)
      Traceback (most recent call last):
      ...
      IndexError: Index -6 is out of bounds for axis 1 with size 5
  
      >>> check_index(0, [1, 2], 5)
      >>> check_index(0, [6, 3], 5)
      Traceback (most recent call last):
      ...
      IndexError: Index is out of bounds for axis 0 with size 5
  
      >>> check_index(1, slice(0, 3), 5)
  
      >>> check_index(0, [True], 1)
      >>> check_index(0, [True, True], 3)
      Traceback (most recent call last):
      ...
      IndexError: Boolean array with size 2 is not long enough for axis 0 with size 3
      >>> check_index(0, [True, True, True], 1)
      Traceback (most recent call last):
      ...
      IndexError: Boolean array with size 3 is not long enough for axis 0 with size 1
      """
      if isinstance(ind, list):
          ind = np.asanyarray(ind)
  
      # unknown dimension, assumed to be in bounds
      if np.isnan(dimension):
          return
      elif is_dask_collection(ind):
          return
      elif is_arraylike(ind):
          if ind.dtype == bool:
              if ind.size != dimension:
                  raise IndexError(
                      f"Boolean array with size {ind.size} is not long enough "
                      f"for axis {axis} with size {dimension}"
                  )
          elif (ind >= dimension).any() or (ind < -dimension).any():
              raise IndexError(
                  f"Index is out of bounds for axis {axis} with size {dimension}"
              )
      elif isinstance(ind, slice):
          return
      elif ind is None:
          return
  
      elif ind >= dimension or ind < -dimension:
          raise IndexError(
              f"Index {ind} is out of bounds for axis {axis} with size {dimension}"
          )
  
imports: from __future__ import annotations
  import bisect
  import functools
  import math
  import warnings
  from itertools import product
  from numbers import Integral, Number
  from operator import itemgetter
  import numpy
  from tlz import concat, memoize, merge, pluck
  from dask import config, core, utils
  from dask.array.chunk import getitem
  from dask.base import is_dask_collection, tokenize
  from dask.highlevelgraph import HighLevelGraph
  from dask.utils import cached_cumsum, is_arraylike
label_desc: Use image node_id 19 for calling a global function with example usage: check_index(axis, ind, dimension) without return types