code: def optimize(
      dsk,
      keys,
      fuse_keys=None,
      fast_functions=None,
      inline_functions_fast_functions=(getter_inline,),
      rename_fused_keys=True,
      **kwargs,
  ):
      """Optimize dask for array computation
  
      1.  Cull tasks not necessary to evaluate keys
      2.  Remove full slicing, e.g. x[:]
      3.  Inline fast functions like getitem and np.transpose
      """
      if not isinstance(keys, (list, set)):
          keys = [keys]
      keys = list(flatten(keys))
  
      if not isinstance(dsk, HighLevelGraph):
          dsk = HighLevelGraph.from_collections(
              id(dsk), dsk, dependencies=()
          )
  
      dsk = optimize_blockwise(dsk, keys=keys)
      dsk = fuse_roots(dsk, keys=keys)
      dsk = dsk.cull(set(keys))
  
      # Perform low-level fusion unless the user has
      # specified False explicitly.
      if config.get("optimization.fuse.active") is False:
          return dsk
  
      dependencies = dsk.get_all_dependencies()
      dsk = ensure_dict(dsk)
  
      # Low level task optimizations
      if fast_functions is not None:
          inline_functions_fast_functions = fast_functions
  
      hold = hold_keys(dsk, dependencies)
  
      dsk, dependencies = fuse(
          dsk,
          hold + keys + (fuse_keys or []),
          dependencies,
          rename_keys=rename_fused_keys,
      )
      if inline_functions_fast_functions:
          dsk = inline_functions(
              dsk,
              keys,
              dependencies=dependencies,
              fast_functions=inline_functions_fast_functions,
          )
  
      return optimize_slices(dsk)
  
imports: from __future__ import annotations
  from collections.abc import Callable
  from itertools import zip_longest
  from numbers import Integral
  from typing import Any
  import numpy
  from dask import config
  from dask.array.chunk import getitem
  from dask.array.core import getter, getter_inline, getter_nofancy
  from dask.blockwise import fuse_roots, optimize_blockwise
  from dask.core import flatten, reverse_dict
  from dask.highlevelgraph import HighLevelGraph
  from dask.optimization import SubgraphCallable, fuse, inline_functions
  from dask.utils import ensure_dict
label_desc: Use image node_id 1 for calling a global function with example usage: optimize(dsk, keys, fuse_keys, fast_functions, inline_functions_fast_functions, rename_fused_keys) and returns: optimize_slices, dsk